Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions modules/notifications/Telegram/Telegram.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => ' ',
],
];
}

Expand All @@ -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");
}
}

Expand All @@ -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");
}
}
}
8 changes: 4 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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.