bot = new \TelegramBot\Api\BotApi($config['token']); $this->initialized = true; // Store chat IDs to notify as an array if (isset($config['chat'])) { if (is_array($config['chat'])) { $this->rcpts = $config['chat']; } else { $this->rcpts[] = $config['chat']; } } } } /** * This creates the listener that listens for new * threads to send out notifications */ public function run() { $dispatcher = EventDispatcher::getInstance(); $dispatcher->attachListener(Events::THREAD_CREATE, $this, 'sendTelegramNotification'); } /** * Sends notification to Telegram * @return boolean */ public function sendTelegramNotification(&$args) { try { foreach ($this->rcpts as $rcpt) { $this->bot->sendMessage($rcpt, getlocal('You have a new user waiting for response. Username: {0}', array($args['thread']->userName))); } } catch (\TelegramBot\Api\HttpException $e) { error_log('Exception while sending notification to Telegram: ' . $e->getMessage()); return false; } return true; } /** * Returns plugin's version. * * @return string */ public static function getVersion() { return '0.0.1'; } /** * Returns plugin's dependencies. * * @return type */ public static function getDependencies() { return array(); } }