├── modules └── notifications │ └── Telegram │ ├── Telegram.php │ └── logo.png └── readme.md /modules/notifications/Telegram/Telegram.php: -------------------------------------------------------------------------------- 1 | setDisplayName('Telegram') 20 | ->setLogoFileName('logo.png'); 21 | } 22 | 23 | 24 | public function settings() 25 | { 26 | return [ 27 | 'botToken' => [ 28 | 'FriendlyName' => 'Token', 29 | 'Type' => 'text', 30 | 'Description' => 'Token of the Telegram Bot.', 31 | 'Placeholder' => ' ', 32 | ], 33 | 'botChatID' => [ 34 | 'FriendlyName' => 'chatID', 35 | 'Type' => 'text', 36 | 'Description' => 'ChatID of the user/channel.', 37 | 'Placeholder' => ' ', 38 | ], 39 | ]; 40 | } 41 | 42 | 43 | public function testConnection($settings) 44 | { 45 | $botToken = $settings['botToken']; 46 | $botChatID = $settings['botChatID']; 47 | 48 | $message = urlencode("Connected with WHMCS"); 49 | $response = file_get_contents("https://api.telegram.org/bot".$botToken."/sendMessage?chat_id=".$botChatID."&text=".$message); 50 | 51 | if (!$response) { 52 | throw new Exception('No response received from API'); 53 | } 54 | } 55 | 56 | public function notificationSettings() 57 | { 58 | return []; 59 | } 60 | 61 | public function getDynamicField($fieldName, $settings) 62 | { 63 | return []; 64 | } 65 | 66 | 67 | public function sendNotification(NotificationInterface $notification, $moduleSettings, $notificationSettings) 68 | { 69 | $botToken = $moduleSettings['botToken']; 70 | $botChatID = $moduleSettings['botChatID']; 71 | 72 | $messageContent = "*". $notification->getTitle() ."*\n\n". $notification->getMessage() ."\n\n[Open »](". $notification->getUrl() .")"; 73 | 74 | $message = urlencode($messageContent); 75 | $response = file_get_contents("https://api.telegram.org/bot".$botToken."/sendMessage?parse_mode=Markdown&chat_id=".$botChatID."&text=".$message); 76 | 77 | if (!$response) { 78 | throw new Exception('No response received from API'); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /modules/notifications/Telegram/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sapinet/WHMCS-TelegramNotify/6483e81b0d2fc1ad2f64f4043a16b763f664bb55/modules/notifications/Telegram/logo.png -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # WHMCS-TelegramNotify 2 | Send WHMCS notifications to telegram 3 | 4 | ## Installation 5 | 1. Place the Telegram folder in your WHMCS installation (modules/notification/Telegram) 6 | 2. Create a bot with [BotFather](https://telegram.me/BotFather "BotFather"), and get the token. 7 | 3. Send a message to your new bot from the user/channel on which you want to receive notifications. 8 | 4. Go to this URL: https://api.telegram.org/bot[TOKEN]/getUpdates 9 | (Replace[TOKEN] with your bot token) 10 | 5. Get your chat ID 11 | 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. 12 | 13 | 14 | --------------------------------------------------------------------------------