diff --git a/modules/notifications/Telegram/Telegram.php b/modules/notifications/Telegram/Telegram.php index a6974ca..b4c3d74 100644 --- a/modules/notifications/Telegram/Telegram.php +++ b/modules/notifications/Telegram/Telegram.php @@ -36,6 +36,12 @@ public function settings() 'Description' => 'ChatID of the user/channel.', 'Placeholder' => ' ', ], + 'TopicGroup' => [ + 'FriendlyName' => 'TopicID', + 'Type' => 'text', + 'Description' => 'Topic of the Group.', + 'Placeholder' => ' ', + ], ]; } @@ -44,12 +50,13 @@ public function testConnection($settings) { $botToken = $settings['botToken']; $botChatID = $settings['botChatID']; - + $TopicGroup = $settings['TopicGroup']; + $message = urlencode("Connected with WHMCS"); - $response = file_get_contents("https://api.telegram.org/bot".$botToken."/sendMessage?chat_id=".$botChatID."&text=".$message); + $response = file_get_contents("https://api.telegram.org/bot".$botToken."/sendMessage?chat_id=".$botChatID."&message_thread_id=".$TopicGroup."&text=".$message.""); if (!$response) { - throw new Exception('No response received from API'); + throw new Exception("We Have Problem Bruh"); } } @@ -66,16 +73,17 @@ public function getDynamicField($fieldName, $settings) public function sendNotification(NotificationInterface $notification, $moduleSettings, $notificationSettings) { - $botToken = $moduleSettings['botToken']; + $botToken = $moduleSettings['botToken']; $botChatID = $moduleSettings['botChatID']; - - $messageContent = "*". $notification->getTitle() ."*\n\n". $notification->getMessage() ."\n\n[Open »](". $notification->getUrl() .")"; + $TopicGroup = $moduleSettings['TopicGroup']; + + $messageContent = "— #*". $notification->getTitle() ."*\n\n". $notification->getMessage() ."\n\n[Open »](". $notification->getUrl() .")"; $message = urlencode($messageContent); - $response = file_get_contents("https://api.telegram.org/bot".$botToken."/sendMessage?parse_mode=Markdown&chat_id=".$botChatID."&text=".$message); - + $response = file_get_contents("https://api.telegram.org/bot".$botToken."/sendMessage?parse_mode=Markdown&chat_id=".$botChatID."&message_thread_id=".$TopicGroup."&text=".$message); + if (!$response) { - throw new Exception('No response received from API'); + throw new Exception("We Have Problem Bruh"); } } } diff --git a/readme.md b/readme.md index 9c21fc8..65571ab 100644 --- a/readme.md +++ b/readme.md @@ -1,13 +1,13 @@ # WHMCS-TelegramNotify -Send WHMCS notifications to telegram +Send WHMCS notifications to telegram user/channel/group ## Installation 1. Place the Telegram folder in your WHMCS installation (modules/notification/Telegram) 2. Create a bot with [BotFather](https://telegram.me/BotFather "BotFather"), and get the token. -3. Send a message to your new bot from the user/channel on which you want to receive notifications. +3. Send a message to your new bot from the user/channel/group on which you want to receive notifications. 4. Go to this URL: https://api.telegram.org/bot[TOKEN]/getUpdates (Replace[TOKEN] with your bot token) -5. Get your chat ID -6. Go to your WHMCS administration panel, Setup > Notifications, click on the Configure button under Telegram, and put your bot token and chat ID, you should receive a message "Connected with WHMCS", otherwise, check your chat ID and token. +5. Get your chat ID And Topic ID ( if you want send notif in topic group ) +6. Go to your WHMCS administration panel, Setup > Notifications, click on the Configure button under Telegram, and put your bot token and chat ID and topic ID, you should receive a message "Connected with WHMCS", otherwise, check your chat ID and token and topic ID.