43 lines
1.2 KiB
PHP
43 lines
1.2 KiB
PHP
<?php
|
|
// config/TelegramBot.php
|
|
require_once __DIR__ . '/config.php';
|
|
require_once dirname(__DIR__) . '/models/Setting.php';
|
|
|
|
class TelegramBot {
|
|
|
|
public function sendGroupMessage($message, $jobId = null) {
|
|
$settingModel = new Setting();
|
|
$token = $settingModel->get('telegram_bot_token', '');
|
|
$chat_id = $settingModel->get('telegram_chat_id', '');
|
|
|
|
if (empty($token) || empty($chat_id)) {
|
|
return false;
|
|
}
|
|
|
|
$text = $message;
|
|
|
|
if ($jobId) {
|
|
$acceptUrl = BASE_URL . "?page=staff&action=accept&job_id=" . $jobId;
|
|
$text .= "\n\n🔗 กดรับงาน: " . $acceptUrl;
|
|
}
|
|
|
|
// Actual cURL request to Telegram API
|
|
$url = "https://api.telegram.org/bot" . $token . "/sendMessage";
|
|
|
|
$data = [
|
|
'chat_id' => $chat_id,
|
|
'text' => $text,
|
|
'parse_mode' => 'HTML'
|
|
];
|
|
|
|
$ch = curl_init($url);
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
$result = curl_exec($ch);
|
|
curl_close($ch);
|
|
|
|
return $result;
|
|
}
|
|
}
|