Tạo BOT từ telegram
- Search bot BotFather
- Gõ lệnh /newbot
- Lấy bot group ID nhanh bằng cách add @RawDataBot
class TelegramModel
{
public static function send($content)
{
$content = is_array($content) && !empty($content) ? implode(PHP_EOL, $content) : $content;
$token = "5160686247:AAGUQsYeTtWD9ZNGUHxTjIc";
$chatID = "-574816132";
$url = "https://api.telegram.org/bot" . $token . "/sendMessage?chat_id=" . $chatID;
$url = $url . "&text=" . urlencode($content);
$ch = curl_init();
$optArray = array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true
);
curl_setopt_array($ch, $optArray);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
}
Sau cùng gắn vào chổ cần thông báo. Ví dụ thông báo đăng nhập.
$messageTelegram[] = '<strong>Thông báo đăng nhập</strong>';
$messageTelegram[] = '<strong> - Name</strong>: ' . $myUser->fullname;
$messageTelegram[] = '<strong> - Email</strong>: ' . $myUser->email;
$messageTelegram[] = '<strong> - Username</strong>: ' . $myUser->username;
$messageTelegram[] = '<strong> - Time</strong>: ' . date("Y/m/d H:i A");
$messageTelegram[] = '<strong> - Agent</strong>: ' . $agent;
$messageTelegram[] = '<strong> - IP</strong>: ' . $this->input->ip_address();
$messageTelegram[] = '<strong> - Platform</strong>: ' . $this->agent->platform();
$messageTelegram[] = '<strong> - Version</strong>: ' . $this->agent->version();
TelegramModel::send($messageTelegram);
Tạo BOT từ telegram image widget