├── LICENSE ├── README.md └── telegrambot ├── config.php ├── plugin.php └── telegrambot.php /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Tomas Kirkegaard 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | osTicket-telegram 2 | ============== 3 | An plugin for [osTicket](https://osticket.com) which posts notifications to a [Telegram](https://telegram.org) channel/chat/group. 4 | 5 | ## Note 6 | This project is no longer maintained 7 | 8 | Install 9 | -------- 10 | Clone this repo or download the zip file and place the contents into your `include/plugins` folder. 11 | Insert Telegrams Bot URL for your bot (ex. `https://api.telegram.org/bot/`) and Chat ID. 12 | 13 | For more information about Telegram Bot, see: https://core.telegram.org/bots/api 14 | 15 | Info 16 | ------ 17 | This plugin uses CURL and tested on osTicket-1.10.1 18 | 19 | Based on [thammanna/osticket-slack](https://github.com/thammanna/osticket-slack) 20 | -------------------------------------------------------------------------------- /telegrambot/config.php: -------------------------------------------------------------------------------- 1 | new SectionBreakField(array( 9 | 'label' => 'Telegram Bot', 10 | )), 11 | 'telegram-webhook-url' => new TextboxField(array( 12 | 'label' => 'Telegram Bot URL', 13 | 'configuration' => array('size'=>100, 'length'=>200), 14 | )), 15 | 'telegram-chat-id' => new TextboxField(array( 16 | 'label' => 'Chat ID', 17 | 'configuration' => array('size'=>100, 'length'=>200), 18 | )), 19 | 'telegram-include-body' => new BooleanField(array( 20 | 'label' => 'Include Body', 21 | 'default' => 0, 22 | )), 23 | ); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /telegrambot/plugin.php: -------------------------------------------------------------------------------- 1 | 'osticket:telegrambot', 5 | 'version' => '0.3', 6 | 'name' => 'Telegram Bot', 7 | 'author' => 'Tomas Kirkegaard', 8 | 'description' => 'Notify Telegram on new ticket.', 9 | 'url' => 'https://github.com/drtomasso', 10 | 'plugin' => 'telegrambot.php:TelegramPlugin', 11 | ); 12 | 13 | ?> 14 | -------------------------------------------------------------------------------- /telegrambot/telegrambot.php: -------------------------------------------------------------------------------- 1 | getConfig()->getUrl().'scp/tickets.php?id='.$ticket->getId(); 18 | $ticketId = $ticket->getNumber(); 19 | $title = $ticket->getSubject() ?: 'No subject'; 20 | $createdBy = $ticket->getName()." (".$ticket->getEmail().")"; 21 | $chatid = $this->getConfig()->get('telegram-chat-id'); 22 | if ($this->getConfig()->get('telegram-include-body')) { 23 | $body = $ticket->getLastMessage()->getMessage() ?: 'No content'; 24 | $body = str_replace('

', '', $body); 25 | $body = str_replace('

', '
' , $body); 26 | $breaks = array("
","
","
"); 27 | $body = str_ireplace($breaks, "\n", $body); 28 | $body = preg_replace('/\v(?:[\v\h]+)/', '', $body); 29 | $body = strip_tags($body); 30 | } 31 | 32 | $this->sendToTelegram( 33 | array( 34 | "method" => "sendMessage", 35 | "chat_id" => $chatid, 36 | "text" => "New Ticket: #".$ticketId."\nCreated by: ".$createdBy."\nSubject: ".$title.($body?"\nMessage:\n".$body:''), 37 | "parse_mode" => "html", 38 | "disable_web_page_preview" => "True" 39 | ) 40 | ); 41 | } 42 | 43 | function sendToTelegram($payload) 44 | { 45 | try { 46 | global $ost; 47 | 48 | $data_string = utf8_encode(json_encode($payload)); 49 | $url = $this->getConfig()->get('telegram-webhook-url'); 50 | 51 | $ch = curl_init($url); 52 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 53 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); 54 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 55 | curl_setopt($ch, CURLOPT_HTTPHEADER, array( 56 | 'Content-Type: application/json', 57 | 'Content-Length: ' . strlen($data_string) 58 | ) 59 | ); 60 | 61 | if (curl_exec($ch) === false) { 62 | throw new Exception($url . ' - ' . curl_error($ch)); 63 | } else { 64 | $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 65 | 66 | if ($statusCode != '200') { 67 | throw new Exception($url . ' Http code: ' . $statusCode); 68 | } 69 | } 70 | 71 | curl_close($ch); 72 | } catch(Exception $e) { 73 | error_log('Error posting to Telegram. '. $e->getMessage()); 74 | } 75 | } 76 | 77 | function escapeText($text) 78 | { 79 | $text = str_replace('&', '&', $text); 80 | $text = str_replace('<', '<', $text); 81 | $text = str_replace('>', '>', $text); 82 | 83 | return $text; 84 | } 85 | } 86 | --------------------------------------------------------------------------------