From b66949fc11e82e1198780ace45c0f1725d046137 Mon Sep 17 00:00:00 2001 From: Arvin Date: Tue, 9 Jul 2024 12:53:49 +0330 Subject: [PATCH 1/3] Update Telegram.php Can Send Notif in topic group --- modules/notifications/Telegram/Telegram.php | 24 ++++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/modules/notifications/Telegram/Telegram.php b/modules/notifications/Telegram/Telegram.php index a6974ca..b0f9644 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("Fuck"); } } @@ -68,14 +75,15 @@ public function sendNotification(NotificationInterface $notification, $moduleSet { $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($response); } } } From 105793cc563c685888d92dd92da3068d60240742 Mon Sep 17 00:00:00 2001 From: Arvin Date: Tue, 9 Jul 2024 12:57:03 +0330 Subject: [PATCH 2/3] Update readme.md --- readme.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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. From c39d81acbc0ebe2f36ef5d2f9f903f6ff058f6c4 Mon Sep 17 00:00:00 2001 From: Arvin Date: Tue, 9 Jul 2024 13:06:58 +0330 Subject: [PATCH 3/3] Update Telegram.php --- modules/notifications/Telegram/Telegram.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/notifications/Telegram/Telegram.php b/modules/notifications/Telegram/Telegram.php index b0f9644..b4c3d74 100644 --- a/modules/notifications/Telegram/Telegram.php +++ b/modules/notifications/Telegram/Telegram.php @@ -56,7 +56,7 @@ public function testConnection($settings) $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("Fuck"); + throw new Exception("We Have Problem Bruh"); } } @@ -73,7 +73,7 @@ public function getDynamicField($fieldName, $settings) public function sendNotification(NotificationInterface $notification, $moduleSettings, $notificationSettings) { - $botToken = $moduleSettings['botToken']; + $botToken = $moduleSettings['botToken']; $botChatID = $moduleSettings['botChatID']; $TopicGroup = $moduleSettings['TopicGroup']; @@ -83,7 +83,7 @@ public function sendNotification(NotificationInterface $notification, $moduleSet $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($response); + throw new Exception("We Have Problem Bruh"); } } }