├── .gitignore ├── README.md ├── bootstrap └── bootstrap.php ├── classes ├── Commands │ ├── CallbackqueryCommand.php │ ├── ChatCommand.php │ ├── EndchatCommand.php │ ├── EndchattopicCommand.php │ ├── GenericCommand.php │ ├── GenericmessageCommand.php │ ├── HelpCommand.php │ ├── RegisterCommand.php │ ├── StartCommand.php │ └── WhoamiCommand.php ├── Legacy │ ├── CancelCommand.php │ ├── DateCommand.php │ ├── EchoCommand.php │ ├── EditedmessageCommand.php │ ├── EditmessageCommand.php │ ├── ForcereplyCommand.php │ ├── HidekeyboardCommand.php │ ├── ImageCommand.php │ ├── InlinekeyboardCommand.php │ ├── KeyboardCommand.php │ ├── MarkdownCommand.php │ ├── ShortenerCommand.php │ ├── SlapCommand.php │ └── SurveyCommand.php ├── erlhcoreclassmodeltelegrambot.php ├── erlhcoreclassmodeltelegrambotdep.php ├── erlhcoreclassmodeltelegramchat.php ├── erlhcoreclassmodeltelegramlead.php ├── erlhcoreclassmodeltelegramoperator.php ├── erlhcoreclassmodeltelegramsignature.php ├── erlhcoreclasstelegramvalidator.php ├── filter.php ├── filter │ └── leads.php ├── filter_operators.php └── filter_signatures.php ├── design └── lhctelegramtheme │ ├── images │ ├── Telegram_logo.svg │ └── social │ │ └── telegram-ico.png │ └── tpl │ ├── lhchat │ └── cannedmsg │ │ ├── custom_fallback_lang_tab_content_multiinclude.tpl.php │ │ ├── custom_fallback_lang_tab_multiinclude.tpl.php │ │ ├── custom_fallback_tab_content_multiinclude.tpl.php │ │ └── custom_fallback_tab_multiinclude.tpl.php │ ├── lhtelegram │ ├── edit.tpl.php │ ├── editdepartments.tpl.php │ ├── editoperator.tpl.php │ ├── editsignature.tpl.php │ ├── editsignatureglobal.tpl.php │ ├── index.tpl.php │ ├── leads.tpl.php │ ├── list.tpl.php │ ├── new.tpl.php │ ├── newoperator.tpl.php │ ├── newsignature.tpl.php │ ├── operators.tpl.php │ ├── options.tpl.php │ ├── parts │ │ ├── filter.tpl.php │ │ ├── form.tpl.php │ │ ├── form_department.tpl.php │ │ ├── form_operator.tpl.php │ │ └── form_signature.tpl.php │ ├── setwebhook.tpl.php │ └── signatures.tpl.php │ └── pagelayouts │ └── parts │ └── modules_menu │ └── extension_module_multiinclude.tpl.php ├── doc ├── img │ ├── bot-as-admin.png │ ├── copylink.png │ ├── enable-topics.png │ ├── manage-group.png │ ├── start-command.png │ └── topic-chats.png ├── install.sql ├── structure.json └── telegram │ ├── bot-data.json │ ├── chat.before_auto_responder_msg_saved.json │ ├── chat.desktop_client_admin_msg.json │ ├── chat.web_add_msg_admin.json │ ├── chat.workflow.canned_message_before_save.json │ ├── incoming-webhook.json │ └── rest-api.json ├── modules ├── lhcron │ ├── test.php │ └── update_structure.php └── lhtelegram │ ├── callback.php │ ├── delete.php │ ├── deleteoperator.php │ ├── deletesignature.php │ ├── edit.php │ ├── editdepartments.php │ ├── editoperator.php │ ├── editsignature.php │ ├── editsignatureglobal.php │ ├── index.php │ ├── leads.php │ ├── list.php │ ├── module.php │ ├── new.php │ ├── newoperator.php │ ├── newsignature.php │ ├── operators.php │ ├── options.php │ ├── setwebhook.php │ └── signatures.php ├── pos ├── erlhcoreclassmodeltelegrambot.php ├── erlhcoreclassmodeltelegrambotdep.php ├── erlhcoreclassmodeltelegramchat.php ├── erlhcoreclassmodeltelegramlead.php ├── erlhcoreclassmodeltelegramoperator.php └── erlhcoreclassmodeltelegramsignature.php ├── providers └── TelegramLiveHelperChatActivator.php └── settings └── settings.ini.default.php /.gitignore: -------------------------------------------------------------------------------- 1 | composer.phar 2 | settings/settings.ini.php -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Telegram bot integration 2 | 3 | This extension allows for direct support of Telegram bots in Live Helper Chat. It supports sound messages, images, and files. 4 | 5 | ## Requirements 6 | 7 | * Minimum version required: Live Helper Chat 4.27v. 8 | * Webhooks has to be enabled - https://github.com/LiveHelperChat/livehelperchat/blob/master/lhc_web/settings/settings.ini.default.php#L86 9 | 10 | ## Upgrading 11 | 12 | 1. Run the command `php cron.php -s site_admin -e lhctelegram -c cron/update_structure` 13 | 2. Navigate to the Telegram options and activate the configuration. 14 | 15 | ## Integration tips 16 | 17 | 1. By default, HTML markdown is used for messages. 18 | 2. You can enable debug mode by unchecking the `Skip` option for the `TelegramIntegration` bot. 19 | 3. If you don't want HTML or Markdown support, you can edit the Rest API call by removing `"parse_mode":"HTML",` and change `{{msg_html_nobr}}` to `{{msg_url}}`. 20 | 4. In parse mode `"HTML"` not all tags are supported so don't use bbcode which translates to HTML which is not supported by telegram. You can always debug in Rest API enabling debug trigger. So you should have different bot or messages depending whom you are sending message. Telegram client or web widget. 21 | 22 | ## Installation instructions 23 | 24 | 1. Clone the GitHub repository. 25 | 2. Rename the cloned folder to "lhctelegram" and place it in the "extension/" directory. 26 | 3. Activate the extension by adding `'lhctelegram'` to the `'extensions'` array in the `lhc_web/settings/settings.ini.php` file. 27 | ``` 28 | 'extensions' => 29 | array ( 30 | 'lhctelegram' 31 | ), 32 | ``` 33 | 4. Install the composer requirements by running: 34 | ``` 35 | cd extension/lhctelegram && composer.phar update 36 | ``` 37 | 5. Clean the cache in the Live Helper Chat back office. 38 | 6. Execute the `doc/install.sql` on the database manager or run the command: 39 | ``` 40 | php cron.php -s site_admin -e lhctelegram -c cron/update_structure 41 | ``` 42 | 7. Register your bot with BotFather: https://core.telegram.org/bots#6-botfather 43 | 8. In the Telegram options, activate webhook configurations. 44 | 9. Create a bot in the LHC back office under Modules => Telegram Settings. 45 | 10. After creating the bot, click "Set webhook". 46 | 11. That's it! The integration should be set up. 47 | 48 | ## Using Telegram as a Support Client 49 | This feature allows you to use the Telegram bot as a gateway between chats on your website and your operators. Here's an example setup: 50 | 51 | Example of final setup. Each customer get's it's own topic. and you can use telegram to chat with your customers directly. Files are also supported! 52 | 53 | ### Watch YouTube video 54 | 55 | [![Watch the video](https://img.youtube.com/vi/wObbEaeopRU/default.jpg)](https://youtu.be/wObbEaeopRU) 56 | 57 | ### Instructions 58 | 59 | ![](https://raw.githubusercontent.com/LiveHelperChat/telegram/master/doc/img/topic-chats.png) 60 | 61 | 1. After you have completed the above steps, you have to do the following changes: In LHC back office, go back to the bot editing page and choose the departments tab. Check the departments you want to receive new chats notifications for but don't save yet. 62 | 2. Create a group chat in telegram and add your bot as an admin in the group chat. 63 | 3. ![](https://raw.githubusercontent.com/LiveHelperChat/telegram/master/doc/img/bot-as-admin.png) 64 | 4. Modify group chat settings and enable topics. Each customer will get their own topic. 65 | 1. ![](https://raw.githubusercontent.com/LiveHelperChat/telegram/master/doc/img/manage-group.png) 66 | 2. ![](https://raw.githubusercontent.com/LiveHelperChat/telegram/master/doc/img/enable-topics.png) 67 | 5. Create a dummy topic, send a dummy message, and copy the URL. 68 | 1. ![](https://raw.githubusercontent.com/LiveHelperChat/telegram/master/doc/img/copylink.png) 69 | 6. Your link will look like `https://t.me/c/1634340846/3/4`, and your group ID will be the middle number `1634340846` with the appended `-100`, so it will be like `-1001634340846` as a concatenated string of `-100` + `1634340846`. 70 | 7. In the LHC back office, go to the main `Telegram page`, then to `Telegram bots > Edit bot departments`. Copy-paste the Telegram group ID into the `Group Chat ID` field. In the same tab, check the `This bot acts as a client` box. Now save. 71 | 8. Go to the LHC back office main Telegram page and choose `Telegram operators`. Choose Operator and Bot, or create one. 72 | 9. Start a conversation in Telegram and register yourself within the bot by typing `/register `. The `` should be the registered operator id from the very first column in the operators list in LHC Modules => Telegram Settings => Telegram operators. 73 | 10. If you get an error message saying it can't find an operator with that ID, and the operator was just created, clean the cache (https://onlinehelpguide.com/delete-telegram-cache-files/) and start a chat as that operator using just the website (not Telegram). Then try registering the again. It should work now. 74 | 11. That's all. Just type /help to see what available commands are supported. 75 | 76 | ## General tips 77 | 78 | * If you are planning only to use Telegram to support your site visitors, it makes sense to set up department online hours so the widget will remain always online even if you are not using the default web back office. 79 | * For a chat to be accepted by the first message from Telegram, you have to be in `Visible` status. 80 | * You can listen for a `/start` command by defining event listener with keyword `/start`. The Same way you can listen to any other command. 81 | * ![](https://raw.githubusercontent.com/LiveHelperChat/telegram/master/doc/img/start-command.png) 82 | * Same visitor chats are written to the same topic as long Online Visitor record exists. You can extend it to be valid for one year in `Settings -> Chat configuration -> Online tracking -> How many days keep records of online users.` 83 | * Integration supports quick reply buttons. Using these, you can make a quick navigation. 84 | * Telegram API has limit of 20MB per file size limit. Please make sure you set the appropriate limit in lhc files sections. 85 | * You now can set bot option to delete topic on chat close/delete to keep it clean. 86 | 87 | Since version 3.36v, you can set your online condition to `Always online`, and you won't have to do anything else. 88 | 89 | https://livehelperchat.com/how-to-use-telegram-if-you-are-automated-hosting-client-489a.html 90 | -------------------------------------------------------------------------------- /classes/Commands/ChatCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Longman\TelegramBot\Commands\UserCommands; 12 | 13 | use Longman\TelegramBot\Commands\UserCommand; 14 | use Longman\TelegramBot\Request; 15 | use Longman\TelegramBot\Entities\InlineKeyboard; 16 | use Longman\TelegramBot\Entities\InlineKeyboardButton; 17 | use Longman\TelegramBot\Entities\ServerResponse; 18 | 19 | 20 | /** 21 | * User "/register" command 22 | * 23 | * Registers sender as operator in Live Helper Chat back office 24 | */ 25 | class ChatCommand extends UserCommand 26 | { 27 | /** 28 | * @var string 29 | */ 30 | protected $name = 'chat'; 31 | 32 | /** 33 | * @var string 34 | */ 35 | protected $description = 'Get information about currently assigned chat or any chat by id.'; 36 | 37 | /** 38 | * @var string 39 | */ 40 | protected $usage = 'Type /chat or /chat'; 41 | 42 | /** 43 | * @var string 44 | */ 45 | protected $version = '1.0'; 46 | 47 | /** 48 | * Command execute method 49 | * 50 | * @return \Longman\TelegramBot\Entities\ServerResponse 51 | * @throws \Longman\TelegramBot\Exception\TelegramException 52 | */ 53 | public function execute(): ServerResponse 54 | { 55 | $message = $this->getMessage(); 56 | $chat_id = $message->getChat()->getId(); 57 | 58 | $telegramExt = \erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionLhctelegram'); 59 | $tBot = $telegramExt->getBot(); 60 | 61 | if ($tBot->bot_client == 0) { 62 | $data = [ 63 | 'chat_id' => $chat_id, 64 | 'text' => "This command is available only if bot is set to act as a client!", 65 | ]; 66 | return Request::sendMessage($data); 67 | } 68 | 69 | $text = (int)trim($message->getText(true)); 70 | 71 | $operator = \erLhcoreClassModelTelegramOperator::findOne(array('filter' => array('tuser_id' => $message->getFrom()->getId(), 'confirmed' => 1, 'bot_id' => $tBot->id))); 72 | 73 | if ($operator instanceof \erLhcoreClassModelTelegramOperator) { 74 | 75 | foreach (\erLhcoreClassModelTelegramChat::getList(['filter' => ['bot_id' => $tBot->id, 'tchat_id' => $message->getMessageThreadId(), 'type' => 1]]) as $tchat) { 76 | 77 | $chat = $tchat->chat; 78 | 79 | if (!($chat instanceof \erLhcoreClassModelChat)) { 80 | $data = [ 81 | 'chat_id' => $chat_id, 82 | 'text' => "Chat could not be found!", 83 | ]; 84 | Request::sendMessage($data); 85 | continue; 86 | } 87 | 88 | $commands = []; 89 | if ($chat->user_id == 0){ 90 | $commands[] = ['text' => 'Accept Chat', 'callback_data' => 'accept_chat||' . $chat->id]; 91 | } else { 92 | $commands[] = ['text' => 'Change owner to me', 'callback_data' => 'take_over_chat||' . $chat->id]; 93 | } 94 | 95 | $inline_keyboard = new InlineKeyboard($commands); 96 | 97 | $data = [ 98 | 'chat_id' => $chat_id, 99 | 'message_thread_id' => $tchat->tchat_id, 100 | 'text' => "Operator: ". (string)$chat->n_off_full . " [{$chat->user_id}] " . $chat->id . (is_object($chat->online_user) && $chat->online_user->ip != '' ? "\nIP - ".$chat->online_user->ip : '') . ($chat->country_name != '' ? "\nGEO - ".$chat->country_name : '') . (is_object($chat->online_user) && $chat->online_user->current_page != '' ? "\nPage URL - ". ltrim($chat->online_user->current_page,"/") : '') . (is_object($chat->online_user) && $chat->online_user->page_title != '' ? "\nPage title - ".$chat->online_user->page_title : ''), 101 | 'reply_markup' => $inline_keyboard, 102 | ]; 103 | 104 | Request::sendMessage($data); 105 | } 106 | 107 | return Request::emptyResponse(); 108 | 109 | } else { 110 | $data = [ 111 | 'chat_id' => $chat_id, 112 | 'text' => "Associated operator could not be found", 113 | ]; 114 | return Request::sendMessage($data); 115 | } 116 | 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /classes/Commands/EndchatCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Longman\TelegramBot\Commands\UserCommands; 12 | 13 | use Longman\TelegramBot\Commands\UserCommand; 14 | use Longman\TelegramBot\Request; 15 | use Longman\TelegramBot\Entities\ServerResponse; 16 | 17 | /** 18 | * User "/register" command 19 | * 20 | * Registers sender as operator in Live Helper Chat back office 21 | */ 22 | class EndchatCommand extends UserCommand 23 | { 24 | /** 25 | * @var string 26 | */ 27 | protected $name = 'endchat'; 28 | 29 | /** 30 | * @var string 31 | */ 32 | protected $description = 'End and close active chat'; 33 | 34 | /** 35 | * @var string 36 | */ 37 | protected $usage = 'Type /endchat'; 38 | 39 | /** 40 | * @var string 41 | */ 42 | protected $version = '1.1.0'; 43 | 44 | /** 45 | * Command execute method 46 | * 47 | * @return \Longman\TelegramBot\Entities\ServerResponse 48 | * @throws \Longman\TelegramBot\Exception\TelegramException 49 | */ 50 | public function execute(): ServerResponse 51 | { 52 | $message = $this->getMessage(); 53 | $chat_id = $message->getChat()->getId(); 54 | 55 | $telegramExt = \erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionLhctelegram'); 56 | $tBot = $telegramExt->getBot(); 57 | 58 | if ($tBot->bot_client == 0) { 59 | $data = [ 60 | 'chat_id' => $chat_id, 61 | 'text' => "This command is available only if bot is set to act as a client!", 62 | ]; 63 | return Request::sendMessage($data); 64 | } 65 | 66 | $operator = \erLhcoreClassModelTelegramOperator::findOne(array('filter' => array('tuser_id' => $message->getFrom()->getId(), 'confirmed' => 1, 'bot_id' => $tBot->id))); 67 | 68 | if ($operator instanceof \erLhcoreClassModelTelegramOperator) { 69 | 70 | foreach (\erLhcoreClassModelTelegramChat::getList(['filter' => ['bot_id' => $tBot->id, 'tchat_id' => $message->getMessageThreadId(), 'type' => 1]]) as $tchat) { 71 | $chat = $tchat->chat; 72 | 73 | if ($chat instanceof \erLhcoreClassModelChat) { 74 | 75 | \erLhcoreClassChatHelper::closeChat(array( 76 | 'user' => $operator->user, 77 | 'chat' => $chat, 78 | )); 79 | 80 | $operator->chat_id = 0; 81 | $operator->saveThis(); 82 | 83 | $data = [ 84 | 'chat_id' => $chat_id, 85 | 'message_thread_id' => $tchat->tchat_id, 86 | 'text' => 'Chat was closed! To list your chats type /chats', 87 | ]; 88 | 89 | Request::sendMessage($data); 90 | 91 | } else { 92 | $data = [ 93 | 'chat_id' => $chat_id, 94 | 'message_thread_id' => $tchat->tchat_id, 95 | 'text' => 'Active chat could not be found!', 96 | ]; 97 | 98 | Request::sendMessage($data); 99 | } 100 | } 101 | 102 | return Request::emptyResponse(); 103 | 104 | } else { 105 | $data = [ 106 | 'chat_id' => $chat_id, 107 | 'text' => 'Operator could not be found!', 108 | ]; 109 | 110 | return Request::sendMessage($data); 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /classes/Commands/EndchattopicCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Longman\TelegramBot\Commands\UserCommands; 12 | 13 | use Longman\TelegramBot\Commands\UserCommand; 14 | use Longman\TelegramBot\Request; 15 | use Longman\TelegramBot\Entities\ServerResponse; 16 | 17 | /** 18 | * User "/register" command 19 | * 20 | * Registers sender as operator in Live Helper Chat back office 21 | */ 22 | class EndchattopicCommand extends UserCommand 23 | { 24 | /** 25 | * @var string 26 | */ 27 | protected $name = 'endchattopic'; 28 | 29 | /** 30 | * @var string 31 | */ 32 | protected $description = 'End active chat and delete topic. New topic will be created next time.'; 33 | 34 | /** 35 | * @var string 36 | */ 37 | protected $usage = 'Type /endchattopic'; 38 | 39 | /** 40 | * @var string 41 | */ 42 | protected $version = '1.1.0'; 43 | 44 | /** 45 | * Command execute method 46 | * 47 | * @return \Longman\TelegramBot\Entities\ServerResponse 48 | * @throws \Longman\TelegramBot\Exception\TelegramException 49 | */ 50 | public function execute(): ServerResponse 51 | { 52 | $message = $this->getMessage(); 53 | $chat_id = $message->getChat()->getId(); 54 | 55 | $telegramExt = \erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionLhctelegram'); 56 | $tBot = $telegramExt->getBot(); 57 | 58 | if ($tBot->bot_client == 0) { 59 | $data = [ 60 | 'chat_id' => $chat_id, 61 | 'text' => "This command is available only if bot is set to act as a client!", 62 | ]; 63 | return Request::sendMessage($data); 64 | } 65 | 66 | $operator = \erLhcoreClassModelTelegramOperator::findOne(array('filter' => array('tuser_id' => $message->getFrom()->getId(), 'confirmed' => 1, 'bot_id' => $tBot->id))); 67 | 68 | if ($operator instanceof \erLhcoreClassModelTelegramOperator) { 69 | 70 | foreach (\erLhcoreClassModelTelegramChat::getList(['filter' => ['bot_id' => $tBot->id, 'tchat_id' => $message->getMessageThreadId(), 'type' => 1]]) as $tchat) { 71 | $chat = $tchat->chat; 72 | 73 | if ($chat instanceof \erLhcoreClassModelChat) { 74 | 75 | \erLhcoreClassChatHelper::closeChat(array( 76 | 'user' => $operator->user, 77 | 'chat' => $chat, 78 | )); 79 | 80 | $operator->chat_id = 0; 81 | $operator->saveThis(); 82 | 83 | Request::send('deleteForumTopic', [ 84 | 'chat_id' => $chat_id, 85 | 'message_thread_id' => $tchat->tchat_id 86 | ]); 87 | 88 | $tchat->removeThis(); 89 | 90 | return Request::emptyResponse(); 91 | 92 | } else { 93 | $data = [ 94 | 'chat_id' => $chat_id, 95 | 'message_thread_id' => $tchat->tchat_id, 96 | 'text' => 'Active chat could not be found!', 97 | ]; 98 | 99 | Request::sendMessage($data); 100 | } 101 | } 102 | 103 | return Request::emptyResponse(); 104 | 105 | } else { 106 | $data = [ 107 | 'chat_id' => $chat_id, 108 | 'text' => 'Operator could not be found!', 109 | ]; 110 | 111 | return Request::sendMessage($data); 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /classes/Commands/GenericCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Longman\TelegramBot\Commands\SystemCommands; 12 | 13 | use Longman\TelegramBot\Commands\SystemCommand; 14 | use Longman\TelegramBot\Request; 15 | use Longman\TelegramBot\Entities\ServerResponse; 16 | 17 | /** 18 | * Generic command 19 | * 20 | * Gets executed for generic commands, when no other appropriate one is found. 21 | */ 22 | class GenericCommand extends SystemCommand 23 | { 24 | /** 25 | * @var string 26 | */ 27 | protected $name = 'generic'; 28 | 29 | /** 30 | * @var string 31 | */ 32 | protected $description = 'Handles generic commands or is executed by default when a command is not found'; 33 | 34 | /** 35 | * @var string 36 | */ 37 | protected $version = '1.1.0'; 38 | 39 | /** 40 | * Command execute method 41 | * 42 | * @return \Longman\TelegramBot\Entities\ServerResponse 43 | * @throws \Longman\TelegramBot\Exception\TelegramException 44 | */ 45 | public function execute(): ServerResponse 46 | { 47 | $message = $this->getMessage(); 48 | 49 | if ($message === null) { 50 | exit; 51 | } 52 | 53 | //You can use $command as param 54 | $chat_id = $message->getChat()->getId(); 55 | $user_id = $message->getFrom()->getId(); 56 | $command = $message->getCommand(); 57 | 58 | //If the user is an admin and the command is in the format "/whoisXYZ", call the /whois command 59 | if (stripos($command, 'whois') === 0 && $this->telegram->isAdmin($user_id)) { 60 | return $this->telegram->executeCommand('whois'); 61 | } 62 | 63 | $data = [ 64 | 'chat_id' => $chat_id, 65 | 'text' => 'Command /' . $command . ' not found.. :(', 66 | ]; 67 | 68 | return Request::sendMessage($data); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /classes/Commands/HelpCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Longman\TelegramBot\Commands\UserCommands; 12 | 13 | use Longman\TelegramBot\Commands\Command; 14 | use Longman\TelegramBot\Commands\UserCommand; 15 | use Longman\TelegramBot\Request; 16 | use Longman\TelegramBot\Entities\ServerResponse; 17 | 18 | /** 19 | * User "/help" command 20 | * 21 | * Command that lists all available commands and displays them in User and Admin sections. 22 | */ 23 | class HelpCommand extends UserCommand 24 | { 25 | /** 26 | * @var string 27 | */ 28 | protected $name = 'help'; 29 | 30 | /** 31 | * @var string 32 | */ 33 | protected $description = 'Show bot commands help'; 34 | 35 | /** 36 | * @var string 37 | */ 38 | protected $usage = '/help or /help '; 39 | 40 | /** 41 | * @var string 42 | */ 43 | protected $version = '1.3.0'; 44 | 45 | /** 46 | * @inheritdoc 47 | */ 48 | public function execute(): ServerResponse 49 | { 50 | $message = $this->getMessage(); 51 | $chat_id = $message->getChat()->getId(); 52 | $command_str = trim($message->getText(true)); 53 | 54 | $telegramExt = \erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionLhctelegram'); 55 | $tBot = $telegramExt->getBot(); 56 | 57 | // Admin commands shouldn't be shown in group chats 58 | $safe_to_show = $message->getChat()->isPrivateChat(); 59 | 60 | $data = [ 61 | 'chat_id' => $chat_id, 62 | ]; 63 | 64 | list($all_commands, $user_commands, $admin_commands) = $this->getUserAdminCommands(); 65 | 66 | // If no command parameter is passed, show the list. 67 | if ($command_str === '') { 68 | $data['text'] = 'Commands List:' . PHP_EOL; 69 | foreach ($user_commands as $user_command) { 70 | $data['text'] .= '/' . $user_command->getName() . ' - ' . $user_command->getDescription() . PHP_EOL; 71 | } 72 | 73 | if ($safe_to_show && count($admin_commands) > 0) { 74 | $data['text'] .= PHP_EOL . 'Admin Commands List:' . PHP_EOL; 75 | foreach ($admin_commands as $admin_command) { 76 | $data['text'] .= '/' . $admin_command->getName() . ' - ' . $admin_command->getDescription() . PHP_EOL; 77 | } 78 | } 79 | 80 | $data['text'] .= PHP_EOL . 'For exact command help type: /help '; 81 | 82 | if (is_numeric($message->getMessageThreadId())) { 83 | $data['chat_id'] = $tBot->group_chat_id; 84 | $data['message_thread_id'] = $message->getMessageThreadId(); 85 | } 86 | 87 | return Request::sendMessage($data); 88 | } 89 | 90 | $command_str = str_replace('/', '', $command_str); 91 | if (isset($all_commands[$command_str]) && ($safe_to_show || !$all_commands[$command_str]->isAdminCommand())) { 92 | $command = $all_commands[$command_str]; 93 | $data['text'] = sprintf( 94 | 'Command: %s (v%s)' . PHP_EOL . 95 | 'Description: %s' . PHP_EOL . 96 | 'Usage: %s', 97 | $command->getName(), 98 | $command->getVersion(), 99 | $command->getDescription(), 100 | $command->getUsage() 101 | ); 102 | 103 | return Request::sendMessage($data); 104 | } 105 | 106 | $data['text'] = 'No help available: Command /' . $command_str . ' not found'; 107 | 108 | if (is_numeric($message->getMessageThreadId())) { 109 | $data['chat_id'] = $tBot->group_chat_id; 110 | $data['message_thread_id'] = $message->getMessageThreadId(); 111 | } 112 | 113 | return Request::sendMessage($data); 114 | } 115 | 116 | /** 117 | * Get all available User and Admin commands to display in the help list. 118 | * 119 | * @return Command[][] 120 | */ 121 | protected function getUserAdminCommands() 122 | { 123 | // Only get enabled Admin and User commands that are allowed to be shown. 124 | /** @var Command[] $commands */ 125 | $commands = array_filter($this->telegram->getCommandsList(), function ($command) { 126 | /** @var Command $command */ 127 | return !$command->isSystemCommand() && $command->showInHelp() && $command->isEnabled(); 128 | }); 129 | 130 | $user_commands = array_filter($commands, function ($command) { 131 | /** @var Command $command */ 132 | return $command->isUserCommand(); 133 | }); 134 | 135 | $admin_commands = array_filter($commands, function ($command) { 136 | /** @var Command $command */ 137 | return $command->isAdminCommand(); 138 | }); 139 | 140 | ksort($commands); 141 | ksort($user_commands); 142 | ksort($admin_commands); 143 | 144 | return [$commands, $user_commands, $admin_commands]; 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /classes/Commands/RegisterCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Longman\TelegramBot\Commands\UserCommands; 12 | 13 | use Longman\TelegramBot\Commands\UserCommand; 14 | use Longman\TelegramBot\Request; 15 | use Longman\TelegramBot\Entities\ServerResponse; 16 | /** 17 | * User "/register" command 18 | * 19 | * Registers sender as operator in Live Helper Chat back office 20 | */ 21 | class RegisterCommand extends UserCommand 22 | { 23 | /** 24 | * @var string 25 | */ 26 | protected $name = 'register'; 27 | 28 | /** 29 | * @var string 30 | */ 31 | protected $description = 'Registers operator within LHC so this operator will receive a chat messages.'; 32 | 33 | /** 34 | * @var string 35 | */ 36 | protected $usage = 'Type /register to register operator within LHC'; 37 | 38 | /** 39 | * @var string 40 | */ 41 | protected $version = '1.1.0'; 42 | 43 | /** 44 | * Command execute method 45 | * 46 | * @return \Longman\TelegramBot\Entities\ServerResponse 47 | * @throws \Longman\TelegramBot\Exception\TelegramException 48 | */ 49 | public function execute(): ServerResponse 50 | { 51 | $message = $this->getMessage(); 52 | $chat_id = $message->getChat()->getId(); 53 | $user_id = $message->getFrom()->getId(); 54 | $text = trim($message->getText(true)); 55 | 56 | $telegramExt = \erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionLhctelegram'); 57 | $tBot = $telegramExt->getBot(); 58 | 59 | if ($tBot->bot_client == 0) { 60 | $data = [ 61 | 'chat_id' => $chat_id, 62 | 'text' => "This command is available only if bot is set to act as a client!", 63 | ]; 64 | return Request::sendMessage($data); 65 | } 66 | 67 | if ($text === '') { 68 | $text = 'Command usage: ' . $this->getUsage(); 69 | } else { 70 | $operator = \erLhcoreClassModelTelegramOperator::fetch((int)$text); 71 | 72 | if ($operator instanceof \erLhcoreClassModelTelegramOperator) { 73 | if ($operator->confirmed == 0) { 74 | $text = 'Operator was confirmed!'; 75 | $operator->tchat_id = $chat_id; 76 | $operator->tuser_id = $user_id; 77 | $operator->confirmed = 1; 78 | $operator->saveThis(); 79 | 80 | if ($operator->user->hide_online == 1) { 81 | $text .= PHP_EOL . 'You are offline. Type /whoami to switch your status'; 82 | } 83 | 84 | } else { 85 | $text = 'Operator is already confirmed! Please un-confirm operator first in back office'; 86 | } 87 | 88 | } else { 89 | $text = 'Operator could not be found! Please create operator in back office first!'; 90 | } 91 | } 92 | 93 | $data = [ 94 | 'chat_id' => $chat_id, 95 | 'text' => $text, 96 | ]; 97 | 98 | return Request::sendMessage($data); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /classes/Commands/StartCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Longman\TelegramBot\Commands\SystemCommands; 12 | 13 | use Longman\TelegramBot\Commands\SystemCommand; 14 | use Longman\TelegramBot\Request; 15 | use Longman\TelegramBot\Entities\ServerResponse; 16 | 17 | /** 18 | * Start command 19 | * 20 | * Gets executed when a user first starts using the bot. 21 | */ 22 | class StartCommand extends SystemCommand 23 | { 24 | /** 25 | * @var string 26 | */ 27 | protected $name = 'start'; 28 | 29 | /** 30 | * @var string 31 | */ 32 | protected $description = 'Start command'; 33 | 34 | /** 35 | * @var string 36 | */ 37 | protected $usage = '/start'; 38 | 39 | /** 40 | * @var string 41 | */ 42 | protected $version = '1.1.0'; 43 | 44 | /** 45 | * @var bool 46 | */ 47 | protected $private_only = true; 48 | 49 | /** 50 | * Command execute method 51 | * 52 | * @return \Longman\TelegramBot\Entities\ServerResponse 53 | * @throws \Longman\TelegramBot\Exception\TelegramException 54 | */ 55 | public function execute(): ServerResponse 56 | { 57 | $telegramExt = \erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionLhctelegram'); 58 | $tBot = $telegramExt->getBot(); 59 | 60 | // If it's bot as client indicate he can type help 61 | if ($tBot->bot_client == 1) { 62 | $message = $this->getMessage(); 63 | 64 | $chat_id = $message->getChat()->getId(); 65 | $text = 'Hi there!' . PHP_EOL . 'Type /help to see all commands!'; 66 | 67 | $data = [ 68 | 'chat_id' => $chat_id, 69 | 'text' => $text, 70 | ]; 71 | 72 | return Request::sendMessage($data); 73 | } else { 74 | return Request::emptyResponse(); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /classes/Commands/WhoamiCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | * 10 | * Written by Marco Boretto 11 | */ 12 | 13 | namespace Longman\TelegramBot\Commands\UserCommands; 14 | 15 | use Longman\TelegramBot\Commands\UserCommand; 16 | use Longman\TelegramBot\Entities\File; 17 | use Longman\TelegramBot\Entities\PhotoSize; 18 | use Longman\TelegramBot\Entities\UserProfilePhotos; 19 | use Longman\TelegramBot\Request; 20 | use Longman\TelegramBot\Entities\InlineKeyboard; 21 | use Longman\TelegramBot\Entities\ServerResponse; 22 | 23 | /** 24 | * User "/whoami" command 25 | * 26 | * Simple command that returns info about the current user. 27 | */ 28 | class WhoamiCommand extends UserCommand 29 | { 30 | /** 31 | * @var string 32 | */ 33 | protected $name = 'whoami'; 34 | 35 | /** 36 | * @var string 37 | */ 38 | protected $description = 'Show your id, name and username'; 39 | 40 | /** 41 | * @var string 42 | */ 43 | protected $usage = '/whoami'; 44 | 45 | /** 46 | * @var string 47 | */ 48 | protected $version = '1.1.0'; 49 | 50 | /** 51 | * @var bool 52 | */ 53 | protected $private_only = true; 54 | 55 | /** 56 | * Command execute method 57 | * 58 | * @return \Longman\TelegramBot\Entities\ServerResponse 59 | * @throws \Longman\TelegramBot\Exception\TelegramException 60 | */ 61 | public function execute(): ServerResponse 62 | { 63 | $message = $this->getMessage(); 64 | 65 | $from = $message->getFrom(); 66 | $user_id = $from->getId(); 67 | $chat_id = $message->getChat()->getId(); 68 | $message_id = $message->getMessageId(); 69 | 70 | $data = [ 71 | 'chat_id' => $chat_id, 72 | 'reply_to_message_id' => $message_id, 73 | ]; 74 | 75 | //Send chat action 76 | Request::sendChatAction([ 77 | 'chat_id' => $chat_id, 78 | 'action' => 'typing', 79 | ]); 80 | 81 | $caption = sprintf( 82 | 'Your Id: %d' . PHP_EOL . 83 | 'Name: %s %s' . PHP_EOL . 84 | 'Username: %s', 85 | $user_id, 86 | $from->getFirstName(), 87 | $from->getLastName(), 88 | $from->getUsername() 89 | ); 90 | 91 | //Fetch user profile photo 92 | $limit = 10; 93 | $offset = null; 94 | $response = Request::getUserProfilePhotos( 95 | [ 96 | 'user_id' => $user_id, 97 | 'limit' => $limit, 98 | 'offset' => $offset, 99 | ] 100 | ); 101 | 102 | if ($response->isOk()) { 103 | /** @var UserProfilePhotos $user_profile_photos */ 104 | $user_profile_photos = $response->getResult(); 105 | 106 | if ($user_profile_photos->getTotalCount() > 0) { 107 | $photos = $user_profile_photos->getPhotos(); 108 | 109 | /** @var PhotoSize $photo */ 110 | $photo = $photos[0][2]; 111 | $file_id = $photo->getFileId(); 112 | 113 | $data['photo'] = $file_id; 114 | $data['caption'] = $caption; 115 | 116 | $result = Request::sendPhoto($data); 117 | 118 | //Download the photo after send message response to speedup response 119 | $response2 = Request::getFile(['file_id' => $file_id]); 120 | if ($response2->isOk()) { 121 | /** @var File $photo_file */ 122 | $photo_file = $response2->getResult(); 123 | Request::downloadFile($photo_file); 124 | } 125 | 126 | return $result; 127 | } 128 | } 129 | 130 | //No Photo just send text 131 | $data['text'] = $caption; 132 | 133 | $telegramExt = \erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionLhctelegram'); 134 | $tBot = $telegramExt->getBot(); 135 | 136 | $operator = \erLhcoreClassModelTelegramOperator::findOne(array('filter' => array('tchat_id' => $chat_id, 'confirmed' => 1, 'bot_id' => $tBot->id))); 137 | 138 | if ($operator instanceof \erLhcoreClassModelTelegramOperator) { 139 | if ($operator->user->hide_online == 0) { 140 | $inlineKeyboards[] = ['text' => "Go offline", 'callback_data' => 'go_offline']; 141 | } else { 142 | $inlineKeyboards[] = ['text' => "Go online", 'callback_data' => 'go_online']; 143 | } 144 | 145 | $inlineKeyboard = new InlineKeyboard($inlineKeyboards); 146 | $data['reply_markup'] = $inlineKeyboard; 147 | $data['text'] .= PHP_EOL . 'Status: ' . ($operator->user->hide_online == 0 ? 'Online' : 'Offline'); 148 | $data['text'] .= PHP_EOL . 'Associated operator: [' . $operator->user_id . '] Official name - ' . ($operator->user->name_official) .' Support name - '. ($operator->user->name_support); 149 | $data['text'] .= PHP_EOL . 'Bot as client: ' . ($tBot->bot_client == 1 ? 'Yes (you will receive new chat requests)' : 'No (you will NOT receive new chat requests)'); 150 | 151 | } else { 152 | $data['text'] .= PHP_EOL . "You are not registered within Live Helper Chat. Please register. See /register"; 153 | } 154 | 155 | return Request::sendMessage($data); 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /classes/Legacy/CancelCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Longman\TelegramBot\Commands\UserCommands; 12 | 13 | use Longman\TelegramBot\Commands\UserCommand; 14 | use Longman\TelegramBot\Conversation; 15 | use Longman\TelegramBot\Entities\Keyboard; 16 | use Longman\TelegramBot\Request; 17 | 18 | /** 19 | * User "/cancel" command 20 | * 21 | * This command cancels the currently active conversation and 22 | * returns a message to let the user know which conversation it was. 23 | * If no conversation is active, the returned message says so. 24 | */ 25 | class CancelCommand extends UserCommand 26 | { 27 | /** 28 | * @var string 29 | */ 30 | protected $name = 'cancel'; 31 | 32 | /** 33 | * @var string 34 | */ 35 | protected $description = 'Cancel the currently active conversation'; 36 | 37 | /** 38 | * @var string 39 | */ 40 | protected $usage = '/cancel'; 41 | 42 | /** 43 | * @var string 44 | */ 45 | protected $version = '0.2.1'; 46 | 47 | /** 48 | * @var bool 49 | */ 50 | protected $need_mysql = true; 51 | 52 | /** 53 | * Command execute method 54 | * 55 | * @return \Longman\TelegramBot\Entities\ServerResponse 56 | * @throws \Longman\TelegramBot\Exception\TelegramException 57 | */ 58 | public function execute() 59 | { 60 | $text = 'No active conversation!'; 61 | 62 | //Cancel current conversation if any 63 | $conversation = new Conversation( 64 | $this->getMessage()->getFrom()->getId(), 65 | $this->getMessage()->getChat()->getId() 66 | ); 67 | 68 | if ($conversation_command = $conversation->getCommand()) { 69 | $conversation->cancel(); 70 | $text = 'Conversation "' . $conversation_command . '" cancelled!'; 71 | } 72 | 73 | return $this->removeKeyboard($text); 74 | } 75 | 76 | /** 77 | * Remove the keyboard and output a text 78 | * 79 | * @param string $text 80 | * 81 | * @return \Longman\TelegramBot\Entities\ServerResponse 82 | * @throws \Longman\TelegramBot\Exception\TelegramException 83 | */ 84 | private function removeKeyboard($text) 85 | { 86 | return Request::sendMessage([ 87 | 'reply_markup' => Keyboard::remove(['selective' => true]), 88 | 'chat_id' => $this->getMessage()->getChat()->getId(), 89 | 'text' => $text, 90 | ]); 91 | } 92 | 93 | /** 94 | * Command execute method if MySQL is required but not available 95 | * 96 | * @return \Longman\TelegramBot\Entities\ServerResponse 97 | * @throws \Longman\TelegramBot\Exception\TelegramException 98 | */ 99 | public function executeNoDb() 100 | { 101 | return $this->removeKeyboard('Nothing to cancel.'); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /classes/Legacy/DateCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Longman\TelegramBot\Commands\UserCommands; 12 | 13 | use GuzzleHttp\Client; 14 | use GuzzleHttp\Exception\RequestException; 15 | use Longman\TelegramBot\Commands\UserCommand; 16 | use Longman\TelegramBot\Request; 17 | use Longman\TelegramBot\TelegramLog; 18 | 19 | /** 20 | * User "/date" command 21 | * 22 | * Shows the date and time of the location passed as the parameter. 23 | * 24 | * A Google API key is required for this command, and it can be set in your hook file: 25 | * $telegram->setCommandConfig('date', ['google_api_key' => 'your_api_key']); 26 | */ 27 | class DateCommand extends UserCommand 28 | { 29 | /** 30 | * @var string 31 | */ 32 | protected $name = 'date'; 33 | 34 | /** 35 | * @var string 36 | */ 37 | protected $description = 'Show date/time by location'; 38 | 39 | /** 40 | * @var string 41 | */ 42 | protected $usage = '/date '; 43 | 44 | /** 45 | * @var string 46 | */ 47 | protected $version = '1.4.1'; 48 | 49 | /** 50 | * Guzzle Client object 51 | * 52 | * @var \GuzzleHttp\Client 53 | */ 54 | private $client; 55 | 56 | /** 57 | * Base URI for Google Maps API 58 | * 59 | * @var string 60 | */ 61 | private $google_api_base_uri = 'https://maps.googleapis.com/maps/api/'; 62 | 63 | /** 64 | * The Google API Key from the command config 65 | * 66 | * @var string 67 | */ 68 | private $google_api_key; 69 | 70 | /** 71 | * Date format 72 | * 73 | * @var string 74 | */ 75 | private $date_format = 'd-m-Y H:i:s'; 76 | 77 | /** 78 | * Get coordinates of passed location 79 | * 80 | * @param string $location 81 | * 82 | * @return array 83 | */ 84 | private function getCoordinates($location) 85 | { 86 | $path = 'geocode/json'; 87 | $query = ['address' => urlencode($location)]; 88 | 89 | if ($this->google_api_key !== null) { 90 | $query['key'] = $this->google_api_key; 91 | } 92 | 93 | try { 94 | $response = $this->client->get($path, ['query' => $query]); 95 | } catch (RequestException $e) { 96 | TelegramLog::error($e->getMessage()); 97 | 98 | return []; 99 | } 100 | 101 | if (!($data = $this->validateResponseData($response->getBody()))) { 102 | return []; 103 | } 104 | 105 | $result = $data['results'][0]; 106 | $lat = $result['geometry']['location']['lat']; 107 | $lng = $result['geometry']['location']['lng']; 108 | $acc = $result['geometry']['location_type']; 109 | $types = $result['types']; 110 | 111 | return [$lat, $lng, $acc, $types]; 112 | } 113 | 114 | /** 115 | * Get date for location passed via coordinates 116 | * 117 | * @param string $lat 118 | * @param string $lng 119 | * 120 | * @return array 121 | */ 122 | private function getDate($lat, $lng) 123 | { 124 | $path = 'timezone/json'; 125 | 126 | $date_utc = new \DateTimeImmutable(null, new \DateTimeZone('UTC')); 127 | $timestamp = $date_utc->format('U'); 128 | 129 | $query = [ 130 | 'location' => urlencode($lat) . ',' . urlencode($lng), 131 | 'timestamp' => urlencode($timestamp), 132 | ]; 133 | 134 | if ($this->google_api_key !== null) { 135 | $query['key'] = $this->google_api_key; 136 | } 137 | 138 | try { 139 | $response = $this->client->get($path, ['query' => $query]); 140 | } catch (RequestException $e) { 141 | TelegramLog::error($e->getMessage()); 142 | 143 | return []; 144 | } 145 | 146 | if (!($data = $this->validateResponseData($response->getBody()))) { 147 | return []; 148 | } 149 | 150 | $local_time = $timestamp + $data['rawOffset'] + $data['dstOffset']; 151 | 152 | return [$local_time, $data['timeZoneId']]; 153 | } 154 | 155 | /** 156 | * Evaluate the response data and see if the request was successful 157 | * 158 | * @param string $data 159 | * 160 | * @return array 161 | */ 162 | private function validateResponseData($data) 163 | { 164 | if (empty($data)) { 165 | return []; 166 | } 167 | 168 | $data = json_decode($data, true); 169 | if (empty($data)) { 170 | return []; 171 | } 172 | 173 | if (isset($data['status']) && $data['status'] !== 'OK') { 174 | return []; 175 | } 176 | 177 | return $data; 178 | } 179 | 180 | /** 181 | * Get formatted date at the passed location 182 | * 183 | * @param string $location 184 | * 185 | * @return string 186 | * @throws \Longman\TelegramBot\Exception\TelegramException 187 | */ 188 | private function getFormattedDate($location) 189 | { 190 | if ($location === null || $location === '') { 191 | return 'The time in nowhere is never'; 192 | } 193 | 194 | list($lat, $lng) = $this->getCoordinates($location); 195 | if (empty($lat) || empty($lng)) { 196 | return 'It seems that in "' . $location . '" they do not have a concept of time.'; 197 | } 198 | 199 | list($local_time, $timezone_id) = $this->getDate($lat, $lng); 200 | 201 | $date_utc = new \DateTimeImmutable(gmdate('Y-m-d H:i:s', $local_time), new \DateTimeZone($timezone_id)); 202 | 203 | return 'The local time in ' . $timezone_id . ' is: ' . $date_utc->format($this->date_format); 204 | } 205 | 206 | /** 207 | * Command execute method 208 | * 209 | * @return \Longman\TelegramBot\Entities\ServerResponse 210 | * @throws \Longman\TelegramBot\Exception\TelegramException 211 | */ 212 | public function execute() 213 | { 214 | //First we set up the necessary member variables. 215 | $this->client = new Client(['base_uri' => $this->google_api_base_uri]); 216 | if (($this->google_api_key = trim($this->getConfig('google_api_key'))) === '') { 217 | $this->google_api_key = null; 218 | } 219 | 220 | $message = $this->getMessage(); 221 | 222 | $chat_id = $message->getChat()->getId(); 223 | $location = $message->getText(true); 224 | 225 | $text = 'You must specify location in format: /date '; 226 | 227 | if ($location !== '') { 228 | $text = $this->getFormattedDate($location); 229 | } 230 | 231 | $data = [ 232 | 'chat_id' => $chat_id, 233 | 'text' => $text, 234 | ]; 235 | 236 | return Request::sendMessage($data); 237 | } 238 | } 239 | -------------------------------------------------------------------------------- /classes/Legacy/EchoCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Longman\TelegramBot\Commands\UserCommands; 12 | 13 | use Longman\TelegramBot\Commands\UserCommand; 14 | use Longman\TelegramBot\Request; 15 | 16 | /** 17 | * User "/echo" command 18 | * 19 | * Simply echo the input back to the user. 20 | */ 21 | class EchoCommand extends UserCommand 22 | { 23 | /** 24 | * @var string 25 | */ 26 | protected $name = 'echo'; 27 | 28 | /** 29 | * @var string 30 | */ 31 | protected $description = 'Show text'; 32 | 33 | /** 34 | * @var string 35 | */ 36 | protected $usage = '/echo '; 37 | 38 | /** 39 | * @var string 40 | */ 41 | protected $version = '1.1.0'; 42 | 43 | /** 44 | * Command execute method 45 | * 46 | * @return \Longman\TelegramBot\Entities\ServerResponse 47 | * @throws \Longman\TelegramBot\Exception\TelegramException 48 | */ 49 | public function execute() 50 | { 51 | $message = $this->getMessage(); 52 | $chat_id = $message->getChat()->getId(); 53 | $text = trim($message->getText(true)); 54 | 55 | if ($text === '') { 56 | $text = 'Command usage: ' . $this->getUsage(); 57 | } 58 | 59 | $data = [ 60 | 'chat_id' => $chat_id, 61 | 'text' => 'remdex here - '.$text, 62 | ]; 63 | 64 | return Request::sendMessage($data); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /classes/Legacy/EditedmessageCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Longman\TelegramBot\Commands\SystemCommands; 12 | 13 | use Longman\TelegramBot\Commands\SystemCommand; 14 | 15 | /** 16 | * Edited message command 17 | * 18 | * Gets executed when a user message is edited. 19 | */ 20 | class EditedmessageCommand extends SystemCommand 21 | { 22 | /** 23 | * @var string 24 | */ 25 | protected $name = 'editedmessage'; 26 | 27 | /** 28 | * @var string 29 | */ 30 | protected $description = 'User edited message'; 31 | 32 | /** 33 | * @var string 34 | */ 35 | protected $version = '1.1.1'; 36 | 37 | /** 38 | * Command execute method 39 | * 40 | * @return \Longman\TelegramBot\Entities\ServerResponse 41 | * @throws \Longman\TelegramBot\Exception\TelegramException 42 | */ 43 | public function execute() 44 | { 45 | //$edited_message = $this->getEditedMessage(); 46 | 47 | return parent::execute(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /classes/Legacy/EditmessageCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Longman\TelegramBot\Commands\UserCommands; 12 | 13 | use Longman\TelegramBot\Commands\UserCommand; 14 | use Longman\TelegramBot\Request; 15 | 16 | /** 17 | * User "/editmessage" command 18 | * 19 | * Command to edit a message via bot. 20 | */ 21 | class EditmessageCommand extends UserCommand 22 | { 23 | /** 24 | * @var string 25 | */ 26 | protected $name = 'editmessage'; 27 | 28 | /** 29 | * @var string 30 | */ 31 | protected $description = 'Edit message'; 32 | 33 | /** 34 | * @var string 35 | */ 36 | protected $usage = '/editmessage'; 37 | 38 | /** 39 | * @var string 40 | */ 41 | protected $version = '1.1.0'; 42 | 43 | /** 44 | * Command execute method 45 | * 46 | * @return \Longman\TelegramBot\Entities\ServerResponse 47 | * @throws \Longman\TelegramBot\Exception\TelegramException 48 | */ 49 | public function execute() 50 | { 51 | $message = $this->getMessage(); 52 | $chat_id = $message->getChat()->getId(); 53 | $reply_to_message = $message->getReplyToMessage(); 54 | $text = $message->getText(true); 55 | 56 | if ($reply_to_message && $message_to_edit = $reply_to_message->getMessageId()) { 57 | $data_edit = [ 58 | 'chat_id' => $chat_id, 59 | 'message_id' => $message_to_edit, 60 | 'text' => $text ?: 'Edited message', 61 | ]; 62 | 63 | // Try to edit selected message. 64 | $result = Request::editMessageText($data_edit); 65 | 66 | if ($result->isOk()) { 67 | // Delete this editing reply message. 68 | Request::deleteMessage([ 69 | 'chat_id' => $chat_id, 70 | 'message_id' => $message->getMessageId(), 71 | ]); 72 | } 73 | 74 | return $result; 75 | } 76 | 77 | $data = [ 78 | 'chat_id' => $chat_id, 79 | 'text' => sprintf("Reply to any bots' message and use /%s to edit it.", $this->name), 80 | ]; 81 | 82 | return Request::sendMessage($data); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /classes/Legacy/ForcereplyCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Longman\TelegramBot\Commands\UserCommands; 12 | 13 | use Longman\TelegramBot\Commands\UserCommand; 14 | use Longman\TelegramBot\Entities\Keyboard; 15 | use Longman\TelegramBot\Request; 16 | 17 | /** 18 | * User "/forcereply" command 19 | * 20 | * Force a reply to a message. 21 | */ 22 | class ForcereplyCommand extends UserCommand 23 | { 24 | /** 25 | * @var string 26 | */ 27 | protected $name = 'forcereply'; 28 | 29 | /** 30 | * @var string 31 | */ 32 | protected $description = 'Force reply with reply markup'; 33 | 34 | /** 35 | * @var string 36 | */ 37 | protected $usage = '/forcereply'; 38 | 39 | /** 40 | * @var string 41 | */ 42 | protected $version = '0.1.0'; 43 | 44 | /** 45 | * Command execute method 46 | * 47 | * @return \Longman\TelegramBot\Entities\ServerResponse 48 | * @throws \Longman\TelegramBot\Exception\TelegramException 49 | */ 50 | public function execute() 51 | { 52 | $chat_id = $this->getMessage()->getChat()->getId(); 53 | 54 | $data = [ 55 | 'chat_id' => $chat_id, 56 | 'text' => 'Write something:', 57 | 'reply_markup' => Keyboard::forceReply(), 58 | ]; 59 | 60 | return Request::sendMessage($data); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /classes/Legacy/HidekeyboardCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Longman\TelegramBot\Commands\UserCommands; 12 | 13 | use Longman\TelegramBot\Commands\UserCommand; 14 | use Longman\TelegramBot\Entities\Keyboard; 15 | use Longman\TelegramBot\Request; 16 | 17 | /** 18 | * User "/hidekeyboard" command 19 | * 20 | * Command to hide the keyboard. 21 | */ 22 | class HidekeyboardCommand extends UserCommand 23 | { 24 | /** 25 | * @var string 26 | */ 27 | protected $name = 'hidekeyboard'; 28 | 29 | /** 30 | * @var string 31 | */ 32 | protected $description = 'Hide the custom keyboard'; 33 | 34 | /** 35 | * @var string 36 | */ 37 | protected $usage = '/hidekeyboard'; 38 | 39 | /** 40 | * @var string 41 | */ 42 | protected $version = '0.1.0'; 43 | 44 | /** 45 | * Command execute method 46 | * 47 | * @return \Longman\TelegramBot\Entities\ServerResponse 48 | * @throws \Longman\TelegramBot\Exception\TelegramException 49 | */ 50 | public function execute() 51 | { 52 | $chat_id = $this->getMessage()->getChat()->getId(); 53 | 54 | $data = [ 55 | 'chat_id' => $chat_id, 56 | 'text' => 'Keyboard Hidden', 57 | 'reply_markup' => Keyboard::remove(), 58 | ]; 59 | 60 | return Request::sendMessage($data); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /classes/Legacy/ImageCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Longman\TelegramBot\Commands\UserCommands; 12 | 13 | use Longman\TelegramBot\Commands\UserCommand; 14 | use Longman\TelegramBot\Request; 15 | 16 | /** 17 | * User "/image" command 18 | * 19 | * Fetch any uploaded image from the Uploads path. 20 | */ 21 | class ImageCommand extends UserCommand 22 | { 23 | /** 24 | * @var string 25 | */ 26 | protected $name = 'image'; 27 | 28 | /** 29 | * @var string 30 | */ 31 | protected $description = 'Send Image'; 32 | 33 | /** 34 | * @var string 35 | */ 36 | protected $usage = '/image'; 37 | 38 | /** 39 | * @var string 40 | */ 41 | protected $version = '1.1.0'; 42 | 43 | /** 44 | * Command execute method 45 | * 46 | * @return \Longman\TelegramBot\Entities\ServerResponse 47 | * @throws \Longman\TelegramBot\Exception\TelegramException 48 | */ 49 | public function execute() 50 | { 51 | $message = $this->getMessage(); 52 | 53 | // Use any extra parameters as the caption text. 54 | $caption = trim($message->getText(true)); 55 | 56 | // Get a random picture from the telegram->getUploadPath() directory. 57 | $random_image = $this->GetRandomImagePath($this->telegram->getUploadPath()); 58 | 59 | $data = [ 60 | 'chat_id' => $message->getChat()->getId(), 61 | ]; 62 | 63 | if (!$random_image) { 64 | $data['text'] = 'No image found!'; 65 | return Request::sendMessage($data); 66 | } 67 | 68 | // If no caption is set, use the filename. 69 | if ($caption === '') { 70 | $caption = basename($random_image); 71 | } 72 | 73 | $data['caption'] = $caption; 74 | $data['photo'] = Request::encodeFile($random_image); 75 | 76 | return Request::sendPhoto($data); 77 | } 78 | 79 | /** 80 | * Return the path to a random image in the passed directory. 81 | * 82 | * @param string $dir 83 | * 84 | * @return string 85 | */ 86 | private function GetRandomImagePath($dir) 87 | { 88 | // Slice off the . and .. "directories" 89 | if ($image_list = array_slice(scandir($dir, SCANDIR_SORT_NONE), 2)) { 90 | shuffle($image_list); 91 | return $dir . '/' . $image_list[0]; 92 | } 93 | 94 | return ''; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /classes/Legacy/InlinekeyboardCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Longman\TelegramBot\Commands\UserCommands; 12 | 13 | use Longman\TelegramBot\Commands\UserCommand; 14 | use Longman\TelegramBot\Entities\InlineKeyboard; 15 | use Longman\TelegramBot\Request; 16 | 17 | /** 18 | * User "/inlinekeyboard" command 19 | * 20 | * Display an inline keyboard with a few buttons. 21 | */ 22 | class InlinekeyboardCommand extends UserCommand 23 | { 24 | /** 25 | * @var string 26 | */ 27 | protected $name = 'inlinekeyboard'; 28 | 29 | /** 30 | * @var string 31 | */ 32 | protected $description = 'Show inline keyboard'; 33 | 34 | /** 35 | * @var string 36 | */ 37 | protected $usage = '/inlinekeyboard'; 38 | 39 | /** 40 | * @var string 41 | */ 42 | protected $version = '0.1.0'; 43 | 44 | /** 45 | * Command execute method 46 | * 47 | * @return \Longman\TelegramBot\Entities\ServerResponse 48 | * @throws \Longman\TelegramBot\Exception\TelegramException 49 | */ 50 | public function execute() 51 | { 52 | $chat_id = $this->getMessage()->getChat()->getId(); 53 | 54 | $switch_element = mt_rand(0, 9) < 5 ? 'true' : 'false'; 55 | 56 | $inline_keyboard = new InlineKeyboard([ 57 | /*['text' => 'inline', 'switch_inline_query' => $switch_element],*/ 58 | ['text' => 'inline current chat', 'switch_inline_query_current_chat' => $switch_element], 59 | ], [ 60 | /* ['text' => 'callback', 'callback_data' => 'identifier'],*/ 61 | ['text' => 'open url', 'url' => 'https://github.com/php-telegram-bot/core'], 62 | ]); 63 | 64 | $data = [ 65 | 'chat_id' => $chat_id, 66 | 'text' => 'inline keyboard', 67 | 'reply_markup' => $inline_keyboard, 68 | ]; 69 | 70 | return Request::sendMessage($data); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /classes/Legacy/KeyboardCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Longman\TelegramBot\Commands\UserCommands; 12 | 13 | use Longman\TelegramBot\Commands\UserCommand; 14 | use Longman\TelegramBot\Entities\Keyboard; 15 | use Longman\TelegramBot\Request; 16 | 17 | /** 18 | * User "/keyboard" command 19 | * 20 | * Display a keyboard with a few buttons. 21 | */ 22 | class KeyboardCommand extends UserCommand 23 | { 24 | /** 25 | * @var string 26 | */ 27 | protected $name = 'keyboard'; 28 | 29 | /** 30 | * @var string 31 | */ 32 | protected $description = 'Show a custom keyboard with reply markup'; 33 | 34 | /** 35 | * @var string 36 | */ 37 | protected $usage = '/keyboard'; 38 | 39 | /** 40 | * @var string 41 | */ 42 | protected $version = '0.2.0'; 43 | 44 | /** 45 | * Command execute method 46 | * 47 | * @return \Longman\TelegramBot\Entities\ServerResponse 48 | * @throws \Longman\TelegramBot\Exception\TelegramException 49 | */ 50 | public function execute() 51 | { 52 | //Keyboard examples 53 | /** @var Keyboard[] $keyboards */ 54 | $keyboards = []; 55 | 56 | //Example 0 57 | $keyboards[] = new Keyboard( 58 | ['7', '8', '9'], 59 | ['4', '5', '6'], 60 | ['1', '2', '3'], 61 | [' ', '0', ' '] 62 | ); 63 | 64 | //Example 1 65 | $keyboards[] = new Keyboard( 66 | ['7', '8', '9', '+'], 67 | ['4', '5', '6', '-'], 68 | ['1', '2', '3', '*'], 69 | [' ', '0', ' ', '/'] 70 | ); 71 | 72 | //Example 2 73 | $keyboards[] = new Keyboard('A', 'B', 'C'); 74 | 75 | //Example 3 76 | $keyboards[] = new Keyboard( 77 | ['text' => 'A'], 78 | 'B', 79 | ['C', 'D'] 80 | ); 81 | 82 | //Example 4 (bots version 2.0) 83 | $keyboards[] = new Keyboard([ 84 | ['text' => 'Send my contact', 'request_contact' => true], 85 | ['text' => 'Send my location', 'request_location' => true], 86 | ]); 87 | 88 | //Return a random keyboard. 89 | $keyboard = $keyboards[mt_rand(0, count($keyboards) - 1)] 90 | ->setResizeKeyboard(true) 91 | ->setOneTimeKeyboard(true) 92 | ->setSelective(false); 93 | 94 | $chat_id = $this->getMessage()->getChat()->getId(); 95 | $data = [ 96 | 'chat_id' => $chat_id, 97 | 'text' => 'Press a Button:', 98 | 'reply_markup' => $keyboard, 99 | ]; 100 | 101 | return Request::sendMessage($data); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /classes/Legacy/MarkdownCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Longman\TelegramBot\Commands\UserCommands; 12 | 13 | use Longman\TelegramBot\Commands\UserCommand; 14 | use Longman\TelegramBot\Entities\ReplyKeyboardMarkup; 15 | use Longman\TelegramBot\Request; 16 | 17 | /** 18 | * User "/markdown" command 19 | * 20 | * Print some markdown text. 21 | */ 22 | class MarkdownCommand extends UserCommand 23 | { 24 | /** 25 | * @var string 26 | */ 27 | protected $name = 'markdown'; 28 | 29 | /** 30 | * @var string 31 | */ 32 | protected $description = 'Print Markdown text'; 33 | 34 | /** 35 | * @var string 36 | */ 37 | protected $usage = '/markdown'; 38 | 39 | /** 40 | * @var string 41 | */ 42 | protected $version = '1.0.1'; 43 | 44 | /** 45 | * Command execute method 46 | * 47 | * @return \Longman\TelegramBot\Entities\ServerResponse 48 | * @throws \Longman\TelegramBot\Exception\TelegramException 49 | */ 50 | public function execute() 51 | { 52 | $message = $this->getMessage(); 53 | $chat_id = $message->getChat()->getId(); 54 | 55 | $data = [ 56 | 'chat_id' => $chat_id, 57 | 'parse_mode' => 'MARKDOWN', 58 | 'text' => '*bold* _italic_ `inline fixed width code` 59 | ``` 60 | preformatted code block 61 | code block 62 | ``` 63 | [Best Telegram bot api!!](https://github.com/php-telegram-bot/core) 64 | ', 65 | ]; 66 | 67 | return Request::sendMessage($data); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /classes/Legacy/ShortenerCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Longman\TelegramBot\Commands\UserCommands; 12 | 13 | use Longman\TelegramBot\Botan; 14 | use Longman\TelegramBot\Commands\UserCommand; 15 | use Longman\TelegramBot\Request; 16 | 17 | /** 18 | * User "/shortener" command 19 | * 20 | * Create a shortened URL using Botan. 21 | */ 22 | class ShortenerCommand extends UserCommand 23 | { 24 | /** 25 | * @var string 26 | */ 27 | protected $name = 'shortener'; 28 | 29 | /** 30 | * @var string 31 | */ 32 | protected $description = 'Botan Shortener example'; 33 | 34 | /** 35 | * @var string 36 | */ 37 | protected $usage = '/shortener'; 38 | 39 | /** 40 | * @var string 41 | */ 42 | protected $version = '1.0.0'; 43 | 44 | /** 45 | * Command execute method 46 | * 47 | * @return \Longman\TelegramBot\Entities\ServerResponse 48 | * @throws \Longman\TelegramBot\Exception\TelegramException 49 | */ 50 | public function execute() 51 | { 52 | $message = $this->getMessage(); 53 | $chat_id = $message->getChat()->getId(); 54 | $user_id = $message->getFrom()->getId(); 55 | 56 | $text = Botan::shortenUrl('https://github.com/php-telegram-bot/core', $user_id); 57 | 58 | $data = [ 59 | 'chat_id' => $chat_id, 60 | 'text' => $text, 61 | ]; 62 | 63 | return Request::sendMessage($data); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /classes/Legacy/SlapCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Longman\TelegramBot\Commands\UserCommands; 12 | 13 | use Longman\TelegramBot\Commands\UserCommand; 14 | use Longman\TelegramBot\Request; 15 | 16 | /** 17 | * User "/slap" command 18 | * 19 | * Slap a user around with a big trout! 20 | */ 21 | class SlapCommand extends UserCommand 22 | { 23 | /** 24 | * @var string 25 | */ 26 | protected $name = 'slap'; 27 | 28 | /** 29 | * @var string 30 | */ 31 | protected $description = 'Slap someone with their username'; 32 | 33 | /** 34 | * @var string 35 | */ 36 | protected $usage = '/slap <@user>'; 37 | 38 | /** 39 | * @var string 40 | */ 41 | protected $version = '1.1.0'; 42 | 43 | /** 44 | * Command execute method 45 | * 46 | * @return \Longman\TelegramBot\Entities\ServerResponse 47 | * @throws \Longman\TelegramBot\Exception\TelegramException 48 | */ 49 | public function execute() 50 | { 51 | $message = $this->getMessage(); 52 | 53 | $chat_id = $message->getChat()->getId(); 54 | $text = $message->getText(true); 55 | 56 | $sender = '@' . $message->getFrom()->getUsername(); 57 | 58 | //username validation 59 | $test = preg_match('/@[\w_]{5,}/', $text); 60 | if ($test === 0) { 61 | $text = $sender . ' sorry no one to slap around..'; 62 | } else { 63 | $text = $sender . ' slaps ' . $text . ' around a bit with a large trout'; 64 | } 65 | 66 | $data = [ 67 | 'chat_id' => $chat_id, 68 | 'text' => $text, 69 | ]; 70 | 71 | return Request::sendMessage($data); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /classes/Legacy/SurveyCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Longman\TelegramBot\Commands\UserCommands; 12 | 13 | use Longman\TelegramBot\Commands\UserCommand; 14 | use Longman\TelegramBot\Conversation; 15 | use Longman\TelegramBot\Entities\Keyboard; 16 | use Longman\TelegramBot\Entities\KeyboardButton; 17 | use Longman\TelegramBot\Entities\PhotoSize; 18 | use Longman\TelegramBot\Request; 19 | 20 | /** 21 | * User "/survey" command 22 | * 23 | * Command that demonstrated the Conversation funtionality in form of a simple survey. 24 | */ 25 | class SurveyCommand extends UserCommand 26 | { 27 | /** 28 | * @var string 29 | */ 30 | protected $name = 'survey'; 31 | 32 | /** 33 | * @var string 34 | */ 35 | protected $description = 'Survery for bot users'; 36 | 37 | /** 38 | * @var string 39 | */ 40 | protected $usage = '/survey'; 41 | 42 | /** 43 | * @var string 44 | */ 45 | protected $version = '0.3.0'; 46 | 47 | /** 48 | * @var bool 49 | */ 50 | protected $need_mysql = true; 51 | 52 | /** 53 | * @var bool 54 | */ 55 | protected $private_only = true; 56 | 57 | /** 58 | * Conversation Object 59 | * 60 | * @var \Longman\TelegramBot\Conversation 61 | */ 62 | protected $conversation; 63 | 64 | /** 65 | * Command execute method 66 | * 67 | * @return \Longman\TelegramBot\Entities\ServerResponse 68 | * @throws \Longman\TelegramBot\Exception\TelegramException 69 | */ 70 | public function execute() 71 | { 72 | $message = $this->getMessage(); 73 | 74 | $chat = $message->getChat(); 75 | $user = $message->getFrom(); 76 | $text = trim($message->getText(true)); 77 | $chat_id = $chat->getId(); 78 | $user_id = $user->getId(); 79 | 80 | //Preparing Response 81 | $data = [ 82 | 'chat_id' => $chat_id, 83 | ]; 84 | 85 | if ($chat->isGroupChat() || $chat->isSuperGroup()) { 86 | //reply to message id is applied by default 87 | //Force reply is applied by default so it can work with privacy on 88 | $data['reply_markup'] = Keyboard::forceReply(['selective' => true]); 89 | } 90 | 91 | //Conversation start 92 | $this->conversation = new Conversation($user_id, $chat_id, $this->getName()); 93 | 94 | $notes = &$this->conversation->notes; 95 | !is_array($notes) && $notes = []; 96 | 97 | //cache data from the tracking session if any 98 | $state = 0; 99 | if (isset($notes['state'])) { 100 | $state = $notes['state']; 101 | } 102 | 103 | $result = Request::emptyResponse(); 104 | 105 | //State machine 106 | //Entrypoint of the machine state if given by the track 107 | //Every time a step is achieved the track is updated 108 | switch ($state) { 109 | case 0: 110 | if ($text === '') { 111 | $notes['state'] = 0; 112 | $this->conversation->update(); 113 | 114 | $data['text'] = 'Type your name:'; 115 | $data['reply_markup'] = Keyboard::remove(['selective' => true]); 116 | 117 | $result = Request::sendMessage($data); 118 | break; 119 | } 120 | 121 | $notes['name'] = $text; 122 | $text = ''; 123 | 124 | // no break 125 | case 1: 126 | if ($text === '') { 127 | $notes['state'] = 1; 128 | $this->conversation->update(); 129 | 130 | $data['text'] = 'Type your surname:'; 131 | 132 | $result = Request::sendMessage($data); 133 | break; 134 | } 135 | 136 | $notes['surname'] = $text; 137 | $text = ''; 138 | 139 | // no break 140 | case 2: 141 | if ($text === '' || !is_numeric($text)) { 142 | $notes['state'] = 2; 143 | $this->conversation->update(); 144 | 145 | $data['text'] = 'Type your age:'; 146 | if ($text !== '') { 147 | $data['text'] = 'Type your age, must be a number:'; 148 | } 149 | 150 | $result = Request::sendMessage($data); 151 | break; 152 | } 153 | 154 | $notes['age'] = $text; 155 | $text = ''; 156 | 157 | // no break 158 | case 3: 159 | if ($text === '' || !in_array($text, ['M', 'F'], true)) { 160 | $notes['state'] = 3; 161 | $this->conversation->update(); 162 | 163 | $data['reply_markup'] = (new Keyboard(['M', 'F'])) 164 | ->setResizeKeyboard(true) 165 | ->setOneTimeKeyboard(true) 166 | ->setSelective(true); 167 | 168 | $data['text'] = 'Select your gender:'; 169 | if ($text !== '') { 170 | $data['text'] = 'Select your gender, choose a keyboard option:'; 171 | } 172 | 173 | $result = Request::sendMessage($data); 174 | break; 175 | } 176 | 177 | $notes['gender'] = $text; 178 | 179 | // no break 180 | case 4: 181 | if ($message->getLocation() === null) { 182 | $notes['state'] = 4; 183 | $this->conversation->update(); 184 | 185 | $data['reply_markup'] = (new Keyboard( 186 | (new KeyboardButton('Share Location'))->setRequestLocation(true) 187 | )) 188 | ->setOneTimeKeyboard(true) 189 | ->setResizeKeyboard(true) 190 | ->setSelective(true); 191 | 192 | $data['text'] = 'Share your location:'; 193 | 194 | $result = Request::sendMessage($data); 195 | break; 196 | } 197 | 198 | $notes['longitude'] = $message->getLocation()->getLongitude(); 199 | $notes['latitude'] = $message->getLocation()->getLatitude(); 200 | 201 | // no break 202 | case 5: 203 | if ($message->getPhoto() === null) { 204 | $notes['state'] = 5; 205 | $this->conversation->update(); 206 | 207 | $data['text'] = 'Insert your picture:'; 208 | 209 | $result = Request::sendMessage($data); 210 | break; 211 | } 212 | 213 | /** @var PhotoSize $photo */ 214 | $photo = $message->getPhoto()[0]; 215 | $notes['photo_id'] = $photo->getFileId(); 216 | 217 | // no break 218 | case 6: 219 | if ($message->getContact() === null) { 220 | $notes['state'] = 6; 221 | $this->conversation->update(); 222 | 223 | $data['reply_markup'] = (new Keyboard( 224 | (new KeyboardButton('Share Contact'))->setRequestContact(true) 225 | )) 226 | ->setOneTimeKeyboard(true) 227 | ->setResizeKeyboard(true) 228 | ->setSelective(true); 229 | 230 | $data['text'] = 'Share your contact information:'; 231 | 232 | $result = Request::sendMessage($data); 233 | break; 234 | } 235 | 236 | $notes['phone_number'] = $message->getContact()->getPhoneNumber(); 237 | 238 | // no break 239 | case 7: 240 | $this->conversation->update(); 241 | $out_text = '/Survey result:' . PHP_EOL; 242 | unset($notes['state']); 243 | foreach ($notes as $k => $v) { 244 | $out_text .= PHP_EOL . ucfirst($k) . ': ' . $v; 245 | } 246 | 247 | $data['photo'] = $notes['photo_id']; 248 | $data['reply_markup'] = Keyboard::remove(['selective' => true]); 249 | $data['caption'] = $out_text; 250 | $this->conversation->stop(); 251 | 252 | $result = Request::sendPhoto($data); 253 | break; 254 | } 255 | 256 | return $result; 257 | } 258 | } 259 | -------------------------------------------------------------------------------- /classes/erlhcoreclassmodeltelegrambot.php: -------------------------------------------------------------------------------- 1 | $this->id, 19 | 'bot_username' => $this->bot_username, 20 | 'webhook_set' => $this->webhook_set, 21 | 'bot_api' => $this->bot_api, 22 | 'dep_id' => $this->dep_id, 23 | 'bot_client' => $this->bot_client, 24 | 'chat_timeout' => $this->chat_timeout, 25 | 'bot_disabled' => $this->bot_disabled, 26 | 'group_chat_id' => $this->group_chat_id, 27 | 'delete_on_close' => $this->delete_on_close, 28 | 'notify_page_change' => $this->notify_page_change 29 | ); 30 | } 31 | 32 | public function __toString() 33 | { 34 | return $this->bot_username; 35 | } 36 | 37 | public function __get($var) 38 | { 39 | switch ($var) { 40 | 41 | case 'callback_url': 42 | if ($this->bot_client == 1) { 43 | $this->callback_url = erLhcoreClassXMP::getBaseHost() . $_SERVER['HTTP_HOST'] . erLhcoreClassDesign::baseurldirect(($this->site_access != '' ? '/' . $this->site_access : '') . '/telegram/callback'). '/' . $this->id; 44 | } else { 45 | $this->callback_url = null; 46 | $callbackData = erLhcoreClassModelChatIncomingWebhook::findOne(['filter' => ['name' => 'TelegramIntegration']]); 47 | if (is_object($callbackData)) { 48 | $this->callback_url = erLhcoreClassSystem::getHost() . erLhcoreClassDesign::baseurldirect( ($this->site_access != '' ? '/' . $this->site_access : '') . '/webhooks/incoming') . '/' . $callbackData->identifier . '?telegram_bot_id=' . $this->id; 49 | } 50 | } 51 | return $this->callback_url; 52 | 53 | default: 54 | ; 55 | break; 56 | } 57 | } 58 | 59 | public function getDepartments() 60 | { 61 | $items = erLhcoreClassModelTelegramBotDep::getList(array('filter' => array('bot_id' => $this->id))); 62 | $returnItems = array(); 63 | foreach ($items as $item) { 64 | $returnItems[$item->dep_id] = $item; 65 | } 66 | 67 | return $returnItems; 68 | } 69 | 70 | /** 71 | * Delete page chat's 72 | */ 73 | public function beforeRemove() 74 | { 75 | $q = ezcDbInstance::get()->createDeleteQuery(); 76 | $q->deleteFrom('lhc_telegram_chat')->where($q->expr->eq('bot_id', ezcDbInstance::get()->quote($this->id))); 77 | $stmt = $q->prepare(); 78 | $stmt->execute(); 79 | } 80 | 81 | public $id = null; 82 | 83 | public $site_access = null; 84 | 85 | public $bot_username = null; 86 | 87 | public $bot_api = null; 88 | 89 | public $bot_client = 0; 90 | 91 | public $dep_id = null; 92 | 93 | public $webhook_set = 0; 94 | 95 | public $bot_disabled = 0; 96 | public $group_chat_id = 0; 97 | public $delete_on_close = 0; 98 | public $notify_page_change = 0; 99 | 100 | public $chat_timeout = 259200; 101 | } 102 | 103 | ?> 104 | -------------------------------------------------------------------------------- /classes/erlhcoreclassmodeltelegrambotdep.php: -------------------------------------------------------------------------------- 1 | $this->id, 19 | 'bot_id' => $this->bot_id, 20 | 'dep_id' => $this->dep_id 21 | ); 22 | } 23 | 24 | public function __get($var) 25 | { 26 | switch ($var) { 27 | 28 | case 'bot': 29 | $this->bot = erLhcoreClassModelTelegramBot::fetch($this->bot_id); 30 | return $this->bot; 31 | break; 32 | 33 | default: 34 | ; 35 | break; 36 | } 37 | } 38 | 39 | public $id = null; 40 | 41 | public $bot_id = null; 42 | 43 | public $dep_id = null; 44 | } 45 | 46 | ?> -------------------------------------------------------------------------------- /classes/erlhcoreclassmodeltelegramchat.php: -------------------------------------------------------------------------------- 1 | $this->id, 19 | 'bot_id' => $this->bot_id, 20 | 'tchat_id' => $this->tchat_id, 21 | 'chat_id' => $this->chat_id, 22 | 'ctime' => $this->ctime, 23 | 'utime' => $this->utime, 24 | 'type' => $this->type, 25 | 'chat_id_internal' => $this->chat_id_internal 26 | ); 27 | } 28 | 29 | public function __toString() 30 | { 31 | return $this->bot; 32 | } 33 | 34 | public function __get($var) 35 | { 36 | switch ($var) { 37 | 38 | case 'bot': 39 | $this->bot = erLhcoreClassModelTelegramBot::fetch($this->bot_id); 40 | return $this->bot; 41 | break; 42 | 43 | case 'chat': 44 | $this->chat = erLhcoreClassModelChat::fetch($this->chat_id); 45 | return $this->chat; 46 | break; 47 | 48 | default: 49 | ; 50 | break; 51 | } 52 | } 53 | 54 | public $id = null; 55 | 56 | public $bot_id = null; 57 | 58 | public $tchat_id = null; 59 | 60 | public $chat_id = null; 61 | public $chat_id_internal = null; 62 | 63 | public $ctime = null; 64 | 65 | public $utime = null; 66 | 67 | // 0 - Standard chat 68 | // 1 - Topic chat Bot As Client 69 | public $type = 0; 70 | 71 | } 72 | 73 | ?> -------------------------------------------------------------------------------- /classes/erlhcoreclassmodeltelegramlead.php: -------------------------------------------------------------------------------- 1 | $this->id, 19 | 'language_code' => $this->language_code, 20 | 'username' => $this->username, 21 | 'last_name' => $this->last_name, 22 | 'first_name' => $this->first_name, 23 | 'utime' => $this->utime, 24 | 'ctime' => $this->ctime, 25 | 'tbot_id' => $this->tbot_id, 26 | 'dep_id' => $this->dep_id, 27 | 'tchat_id' => $this->tchat_id 28 | ); 29 | } 30 | 31 | public function __toString() 32 | { 33 | return trim($this->first_name . ' ' . $this->last_name); 34 | } 35 | 36 | public function __get($var) 37 | { 38 | switch ($var) { 39 | 40 | case 'tbot': 41 | $this->tbot = erLhcoreClassModelTelegramBot::fetch($this->tbot_id); 42 | return $this->tbot; 43 | break; 44 | 45 | case 'dep': 46 | $this->dep = erLhcoreClassModelDepartament::fetch($this->dep_id); 47 | return $this->dep; 48 | break; 49 | 50 | default: 51 | ; 52 | break; 53 | } 54 | } 55 | 56 | public $id = null; 57 | 58 | public $language_code = null; 59 | 60 | public $username = null; 61 | 62 | public $last_name = null; 63 | 64 | public $first_name = null; 65 | 66 | public $utime = null; 67 | 68 | public $ctime = null; 69 | 70 | public $tbot_id = null; 71 | 72 | public $dep_id = null; 73 | 74 | public $tchat_id = null; 75 | } 76 | 77 | ?> -------------------------------------------------------------------------------- /classes/erlhcoreclassmodeltelegramoperator.php: -------------------------------------------------------------------------------- 1 | $this->id, 19 | 'bot_id' => $this->bot_id, 20 | 'tchat_id' => $this->tchat_id, 21 | 'chat_id' => $this->chat_id, 22 | 'tuser_id' => $this->tuser_id, 23 | 'user_id' => $this->user_id, 24 | 'confirmed' => $this->confirmed 25 | ); 26 | } 27 | 28 | public function __toString() 29 | { 30 | return $this->bot; 31 | } 32 | 33 | public function __get($var) 34 | { 35 | switch ($var) { 36 | 37 | case 'bot': 38 | $this->bot = erLhcoreClassModelTelegramBot::fetch($this->bot_id); 39 | return $this->bot; 40 | break; 41 | 42 | case 'user': 43 | $this->user = erLhcoreClassModelUser::fetch($this->user_id); 44 | return $this->user; 45 | break; 46 | 47 | case 'chat': 48 | $this->chat = erLhcoreClassModelChat::fetch($this->chat_id); 49 | return $this->chat; 50 | break; 51 | 52 | default: 53 | ; 54 | break; 55 | } 56 | } 57 | 58 | public $id = null; 59 | 60 | public $bot_id = null; 61 | 62 | public $tchat_id = 0; 63 | 64 | public $chat_id = 0; 65 | 66 | public $tuser_id = 0; 67 | 68 | public $user_id = null; 69 | 70 | public $confirmed = 0; 71 | } 72 | 73 | ?> -------------------------------------------------------------------------------- /classes/erlhcoreclassmodeltelegramsignature.php: -------------------------------------------------------------------------------- 1 | $this->id, 19 | 'bot_id' => $this->bot_id, 20 | 'user_id' => $this->user_id, 21 | 'signature' => $this->signature 22 | ); 23 | } 24 | 25 | public function __toString() 26 | { 27 | return $this->bot; 28 | } 29 | 30 | public function __get($var) 31 | { 32 | switch ($var) { 33 | 34 | case 'bot': 35 | $this->bot = erLhcoreClassModelTelegramBot::fetch($this->bot_id); 36 | return $this->bot; 37 | break; 38 | 39 | case 'user': 40 | $this->user = erLhcoreClassModelUser::fetch($this->user_id); 41 | return $this->user; 42 | break; 43 | 44 | default: 45 | ; 46 | break; 47 | } 48 | } 49 | 50 | public $id = null; 51 | 52 | public $bot_id = null; 53 | 54 | public $user_id = null; 55 | 56 | public $signature = null; 57 | } 58 | 59 | ?> -------------------------------------------------------------------------------- /classes/erlhcoreclasstelegramvalidator.php: -------------------------------------------------------------------------------- 1 | new ezcInputFormDefinitionElement( 9 | ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw' 10 | ), 11 | 'bot_api' => new ezcInputFormDefinitionElement( 12 | ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw' 13 | ), 14 | 'chat_timeout' => new ezcInputFormDefinitionElement( 15 | ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw' 16 | ), 17 | 'bot_disabled' => new ezcInputFormDefinitionElement( 18 | ezcInputFormDefinitionElement::OPTIONAL, 'boolean' 19 | ), 20 | 'dep_id' => new ezcInputFormDefinitionElement( 21 | ezcInputFormDefinitionElement::OPTIONAL, 'int', array('min_range' => 1) 22 | ) 23 | ); 24 | 25 | $form = new ezcInputForm(INPUT_POST, $definition); 26 | $Errors = array(); 27 | 28 | if ($form->hasValidData('bot_username') && $form->bot_username != '') { 29 | $item->bot_username = $form->bot_username; 30 | } else { 31 | $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('xmppservice/operatorvalidator', 'Please enter phone number!'); 32 | } 33 | 34 | if ($form->hasValidData('bot_api') && $form->bot_api != '') { 35 | $item->bot_api = $form->bot_api; 36 | } else { 37 | $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('xmppservice/operatorvalidator', 'Please enter Account SID!'); 38 | } 39 | 40 | if ($form->hasValidData('bot_disabled') && $form->bot_disabled == true) { 41 | $item->bot_disabled = 1; 42 | } else { 43 | $item->bot_disabled = 0; 44 | } 45 | 46 | if ($form->hasValidData('dep_id')) { 47 | $item->dep_id = $form->dep_id; 48 | } else { 49 | $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('xmppservice/operatorvalidator', 'Please choose a department!'); 50 | } 51 | 52 | if ($form->hasValidData('chat_timeout')) { 53 | $item->chat_timeout = $form->chat_timeout; 54 | } else { 55 | $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('xmppservice/operatorvalidator', 'Please enter chat timeout!'); 56 | } 57 | 58 | return $Errors; 59 | } 60 | 61 | public static function validateSignature(erLhcoreClassModelTelegramSignature & $item) 62 | { 63 | $definition = array( 64 | 'signature' => new ezcInputFormDefinitionElement( 65 | ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw' 66 | ), 67 | 'user_id' => new ezcInputFormDefinitionElement( 68 | ezcInputFormDefinitionElement::OPTIONAL, 'int', array('min_range' => 1) 69 | ) 70 | ); 71 | 72 | $form = new ezcInputForm(INPUT_POST, $definition); 73 | $Errors = array(); 74 | 75 | if ($form->hasValidData('signature') && $form->signature != '') { 76 | $item->signature = $_POST['signature']; 77 | } else { 78 | $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('xmppservice/operatorvalidator', 'Please enter signature!'); 79 | } 80 | 81 | if ($form->hasValidData('user_id')) { 82 | $item->user_id = $form->user_id; 83 | } else { 84 | $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('xmppservice/operatorvalidator', 'Please choose a user!'); 85 | } 86 | 87 | return $Errors; 88 | } 89 | 90 | public static function validateSignatureGlobal(erLhcoreClassModelTelegramSignature & $item) 91 | { 92 | $definition = array( 93 | 'bot_id' => new ezcInputFormDefinitionElement( 94 | ezcInputFormDefinitionElement::OPTIONAL, 'int', array('min_range' => 1) 95 | ) 96 | ); 97 | 98 | $form = new ezcInputForm(INPUT_POST, $definition); 99 | 100 | if ($form->hasValidData('bot_id')) { 101 | $item->bot_id = $form->bot_id; 102 | } else { 103 | $item->bot_id = 0; 104 | } 105 | 106 | $Errors = self::validateSignature($item); 107 | 108 | return $Errors; 109 | } 110 | 111 | public static function validateDepartments(erLhcoreClassModelTelegramBot & $item) 112 | { 113 | $definition = array( 114 | 'bot_client' => new ezcInputFormDefinitionElement( 115 | ezcInputFormDefinitionElement::OPTIONAL, 'boolean' 116 | ), 117 | 'delete_on_close' => new ezcInputFormDefinitionElement( 118 | ezcInputFormDefinitionElement::OPTIONAL, 'boolean' 119 | ), 120 | 'notify_page_change' => new ezcInputFormDefinitionElement( 121 | ezcInputFormDefinitionElement::OPTIONAL, 'boolean' 122 | ), 123 | 'dep' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'int',null,FILTER_REQUIRE_ARRAY), 124 | 'group_chat_id' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'int',null), 125 | ); 126 | 127 | $form = new ezcInputForm(INPUT_POST, $definition); 128 | 129 | if ($form->hasValidData('delete_on_close') && $form->delete_on_close == true) { 130 | $item->delete_on_close = 1; 131 | } else { 132 | $item->delete_on_close = 0; 133 | } 134 | 135 | if ($form->hasValidData('notify_page_change') && $form->notify_page_change == true) { 136 | $item->notify_page_change = 1; 137 | } else { 138 | $item->notify_page_change = 0; 139 | } 140 | 141 | if ($form->hasValidData('bot_client') && $form->bot_client == true) { 142 | if ($item->bot_client != 1) { 143 | $item->webhook_set = 0; 144 | } 145 | $item->bot_client = 1; 146 | } else { 147 | if ($item->bot_client != 0) { 148 | $item->webhook_set = 0; 149 | } 150 | $item->bot_client = 0; 151 | } 152 | 153 | if ($form->hasValidData('group_chat_id')) { 154 | $item->group_chat_id = $form->group_chat_id; 155 | } else { 156 | $item->group_chat_id = 0; 157 | } 158 | 159 | $db = ezcDbInstance::get(); 160 | $stmt = $db->prepare('DELETE FROM lhc_telegram_bot_dep WHERE bot_id = :bot_id'); 161 | $stmt->bindValue(':bot_id', $item->id, PDO::PARAM_STR); 162 | $stmt->execute(); 163 | 164 | if ($form->hasValidData('dep') && !empty($form->dep)) { 165 | foreach ($form->dep as $depId) { 166 | $botDep = new erLhcoreClassModelTelegramBotDep(); 167 | $botDep->dep_id = $depId; 168 | $botDep->bot_id = $item->id; 169 | $botDep->saveThis(); 170 | } 171 | } 172 | 173 | return []; 174 | } 175 | 176 | public static function validateOperator(erLhcoreClassModelTelegramOperator & $item) 177 | { 178 | $definition = array( 179 | 'user_id' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'int', array('min_range' => 1)), 180 | 'bot_id' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'int', array('min_range' => 1)), 181 | 'confirmed' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'boolean'), 182 | ); 183 | 184 | $Errors = array(); 185 | $form = new ezcInputForm(INPUT_POST, $definition); 186 | 187 | if ($form->hasValidData('user_id')) { 188 | $item->user_id = $form->user_id; 189 | } else { 190 | $Errors[] = 'Please choose a user!'; 191 | } 192 | 193 | if ($form->hasValidData('bot_id')) { 194 | $item->bot_id = $form->bot_id; 195 | } else { 196 | $Errors[] = 'Please choose a bot!'; 197 | } 198 | 199 | if ($form->hasValidData('confirmed') && $form->confirmed == 1) { 200 | $item->confirmed = 1; 201 | } else { 202 | $item->confirmed = 0; 203 | } 204 | 205 | return $Errors; 206 | } 207 | } -------------------------------------------------------------------------------- /classes/filter.php: -------------------------------------------------------------------------------- 1 | 'text', 7 | 'trans' => 'Name', 8 | 'required' => false, 9 | 'valid_if_filled' => false, 10 | 'filter_type' => 'like', 11 | 'filter_table_field' => 'name', 12 | 'validation_definition' => new ezcInputFormDefinitionElement ( 13 | ezcInputFormDefinitionElement::OPTIONAL, 'string' 14 | ) 15 | ); 16 | 17 | $fieldSortAttr = array ( 18 | 'field' => false, 19 | 'default' => false, 20 | 'serialised' => true, 21 | 'disabled' => true, 22 | 'options' => array() 23 | ); 24 | 25 | return array( 26 | 'filterAttributes' => $fieldsSearch, 27 | 'sortAttributes' => $fieldSortAttr 28 | ); -------------------------------------------------------------------------------- /classes/filter/leads.php: -------------------------------------------------------------------------------- 1 | 'text', 7 | 'trans' => 'Name', 8 | 'required' => false, 9 | 'valid_if_filled' => false, 10 | 'filter_type' => 'like', 11 | 'filter_table_field' => 'name', 12 | 'validation_definition' => new ezcInputFormDefinitionElement ( 13 | ezcInputFormDefinitionElement::OPTIONAL, 'string' 14 | ) 15 | ); 16 | 17 | $fieldSortAttr = array ( 18 | 'field' => false, 19 | 'default' => false, 20 | 'serialised' => true, 21 | 'disabled' => true, 22 | 'options' => array() 23 | ); 24 | 25 | return array( 26 | 'filterAttributes' => $fieldsSearch, 27 | 'sortAttributes' => $fieldSortAttr 28 | ); -------------------------------------------------------------------------------- /classes/filter_operators.php: -------------------------------------------------------------------------------- 1 | 'text', 7 | 'trans' => 'User', 8 | 'required' => false, 9 | 'valid_if_filled' => false, 10 | 'filter_type' => 'filter', 11 | 'filter_table_field' => 'user_id', 12 | 'validation_definition' => new ezcInputFormDefinitionElement( 13 | ezcInputFormDefinitionElement::OPTIONAL, 'int', array( 'min_range' => 1) 14 | ) 15 | ); 16 | 17 | $fieldsSearch['bot_id'] = array ( 18 | 'type' => 'text', 19 | 'trans' => 'Bot', 20 | 'required' => false, 21 | 'valid_if_filled' => false, 22 | 'filter_type' => 'filter', 23 | 'filter_table_field' => 'bot_id', 24 | 'validation_definition' => new ezcInputFormDefinitionElement( 25 | ezcInputFormDefinitionElement::OPTIONAL, 'int', array( 'min_range' => 1) 26 | ) 27 | ); 28 | 29 | $fieldSortAttr = array ( 30 | 'field' => false, 31 | 'default' => false, 32 | 'serialised' => true, 33 | 'disabled' => true, 34 | 'options' => array() 35 | ); 36 | 37 | return array( 38 | 'filterAttributes' => $fieldsSearch, 39 | 'sortAttributes' => $fieldSortAttr 40 | ); -------------------------------------------------------------------------------- /classes/filter_signatures.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiveHelperChat/telegram/6ae80031037979c01335e9ebdb4fa9caa41eaca0/classes/filter_signatures.php -------------------------------------------------------------------------------- /design/lhctelegramtheme/images/Telegram_logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /design/lhctelegramtheme/images/social/telegram-ico.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiveHelperChat/telegram/6ae80031037979c01335e9ebdb4fa9caa41eaca0/design/lhctelegramtheme/images/social/telegram-ico.png -------------------------------------------------------------------------------- /design/lhctelegramtheme/tpl/lhchat/cannedmsg/custom_fallback_lang_tab_content_multiinclude.tpl.php: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 | 5 |
6 |
7 | 8 | 9 |
10 |
-------------------------------------------------------------------------------- /design/lhctelegramtheme/tpl/lhchat/cannedmsg/custom_fallback_lang_tab_multiinclude.tpl.php: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /design/lhctelegramtheme/tpl/lhchat/cannedmsg/custom_fallback_tab_content_multiinclude.tpl.php: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 | 5 |
6 |
7 | 8 | 9 |
10 |
-------------------------------------------------------------------------------- /design/lhctelegramtheme/tpl/lhchat/cannedmsg/custom_fallback_tab_multiinclude.tpl.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /design/lhctelegramtheme/tpl/lhtelegram/edit.tpl.php: -------------------------------------------------------------------------------- 1 |

getTranslation('module/fbmessenger','Edit bot');?>

2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 |
14 |
15 | 16 |
17 | 18 |
19 | 20 | 21 |
22 |
23 | 24 |
25 |
-------------------------------------------------------------------------------- /design/lhctelegramtheme/tpl/lhtelegram/editdepartments.tpl.php: -------------------------------------------------------------------------------- 1 |

getTranslation('module/fbmessenger','Edit bot');?>

2 | 3 | 4 | 5 | 6 | 7 | 8 | getTranslation('user/account','Updated!'); ?> 9 | 10 | 11 | 12 | 17 | 18 |
19 |
20 | 21 |
22 | 23 |
24 | 25 | 26 |
27 |
28 | 29 |
30 |
-------------------------------------------------------------------------------- /design/lhctelegramtheme/tpl/lhtelegram/editoperator.tpl.php: -------------------------------------------------------------------------------- 1 |

getTranslation('module/fbmessenger','Edit operator');?>

2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 |
10 | 11 | 12 |
13 |
14 | -------------------------------------------------------------------------------- /design/lhctelegramtheme/tpl/lhtelegram/editsignature.tpl.php: -------------------------------------------------------------------------------- 1 |

getTranslation('module/fbmessenger','Edit bot');?>

2 | 3 | 4 | 5 | 6 | 7 | 8 | getTranslation('user/account','Updated!'); ?> 9 | 10 | 11 | 12 | 13 | getTranslation('user/account','Removed!'); ?> 14 | 15 | 16 | 17 | 18 | getTranslation('user/account','Saved!'); ?> 19 | 20 | 21 | 22 | 23 | 28 | 29 |
30 |
31 | 32 | 33 |

Existing signatures

34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
UserSignature
user)?>signature,30,'...',30,ENT_QUOTES);?>getTranslation('user/userlist','Edit');?>getTranslation('user/userlist','Delete');?>
51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | id == null) : ?> 60 |

New signature

61 | 62 |

Edit signature

63 | 64 |
65 |
66 | 67 | 'user_id', 69 | 'optional_field' => erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Select operator'), 70 | 'selected_id' => $newSignature->user_id, 71 | 'css_class' => 'form-control input-sm', 72 | 'display_name' => 'name_official', 73 | 'list_function' => 'erLhcoreClassModelUser::getUserList' 74 | )); ?> 75 |
76 | 77 |
78 | 79 | 80 |
81 | 82 | 83 |
84 | 85 |
86 |
-------------------------------------------------------------------------------- /design/lhctelegramtheme/tpl/lhtelegram/editsignatureglobal.tpl.php: -------------------------------------------------------------------------------- 1 |

getTranslation('module/fbmessenger','Edit signature');?>

2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 |
12 | 13 | 14 |
15 | 16 |
-------------------------------------------------------------------------------- /design/lhctelegramtheme/tpl/lhtelegram/index.tpl.php: -------------------------------------------------------------------------------- 1 |

getTranslation('module/twilio','Telegram');?>

2 | 3 | -------------------------------------------------------------------------------- /design/lhctelegramtheme/tpl/lhtelegram/leads.tpl.php: -------------------------------------------------------------------------------- 1 |

getTranslation('module/fbmessenger','Telegram leads list');?>

2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 |
getTranslation('module/fbmessenger','Bot');?>getTranslation('module/fbmessenger','Name');?>getTranslation('module/fbmessenger','Surname');?>getTranslation('module/fbmessenger','Username');?>getTranslation('module/fbmessenger','Locale');?>getTranslation('module/fbmessenger','Department');?>getTranslation('module/fbmessenger','Telegram Chat ID');?>
tbot)?>first_name)?>last_name)?>username)?>language_code)?>dep)?>tchat_id)?>
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /design/lhctelegramtheme/tpl/lhtelegram/list.tpl.php: -------------------------------------------------------------------------------- 1 |

getTranslation('module/fbmessenger','Telegram bots');?>

2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 40 | 46 | 47 | 48 |
IDgetTranslation('module/fbmessenger','Bot');?>getTranslation('module/fbmessenger','Callback URL');?>
id?>bot_username)?> 19 | callback_url !== null) : ?> 20 | 21 |
22 | 23 | Language, after choosing a language click `Set webhook`. After setting webhook this option will remain the same, but webhook URL will be set to a chosen language. 24 |
25 | 30 | 31 | webhook_set == 1) : ?>YesNo  32 | 33 |
34 |
35 | 36 | 37 | getTranslation('module/telegram','Please finish');?> getTranslation('module/telegram','configuration');?> 38 | 39 |
41 |
42 | 43 | 44 |
45 |
49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | getTranslation('module/fbmessenger','New');?> -------------------------------------------------------------------------------- /design/lhctelegramtheme/tpl/lhtelegram/new.tpl.php: -------------------------------------------------------------------------------- 1 |

getTranslation('module/fbmessenger','New bot');?>

2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 |
12 | 13 | 14 |
15 | 16 |
-------------------------------------------------------------------------------- /design/lhctelegramtheme/tpl/lhtelegram/newoperator.tpl.php: -------------------------------------------------------------------------------- 1 |

New operator

2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 |
12 | 13 | 14 |
15 | 16 |
-------------------------------------------------------------------------------- /design/lhctelegramtheme/tpl/lhtelegram/newsignature.tpl.php: -------------------------------------------------------------------------------- 1 |

getTranslation('module/fbmessenger','New bot');?>

2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 |
12 | 13 | 14 |
15 | 16 |
-------------------------------------------------------------------------------- /design/lhctelegramtheme/tpl/lhtelegram/operators.tpl.php: -------------------------------------------------------------------------------- 1 |

getTranslation('module/fbmessenger','Telegram operators');?>

2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 29 | 30 | 31 | 32 | 33 | 34 | 40 | 41 | 42 |
getTranslation('module/fbmessenger','ID');?>getTranslation('module/fbmessenger','Operator');?>getTranslation('module/fbmessenger','Bot');?>getTranslation('module/fbmessenger','Chat ID');?>getTranslation('module/fbmessenger','Confirmed with bot');?>getTranslation('module/fbmessenger','Telegram Chat ID');?>getTranslation('module/fbmessenger','Telegram User ID');?>
id)?> 23 | user)) : ?> 24 | user->name_official)?> 25 | 26 | - 27 | 28 | bot)?>chat_id)?>confirmed?>tchat_id?>tuser_id?> 35 |
36 | 37 | 38 |
39 |
43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | getTranslation('module/fbmessenger','New');?> -------------------------------------------------------------------------------- /design/lhctelegramtheme/tpl/lhtelegram/options.tpl.php: -------------------------------------------------------------------------------- 1 |

Telegram Options

2 | 3 |
4 | 5 | 6 | 7 | getTranslation('chat/onlineusers','Settings updated'); ?> 8 | 9 | 10 | 11 |

You will see what information you have to put

12 | 13 |
Incoming webhook
14 | ['name' => 'TelegramIntegration']])) : ?> 15 |

Exists

16 |
17 | 18 | 19 |
20 | 21 |

Missing

22 | 23 | 24 |
Rest API configuration
25 | 26 | ['name' => 'TelegramIntegration']]) > 0) : ?> 27 |

Exists

28 | 29 |

Missing

30 | 31 | 32 |
Bot Configuration
33 | ['name' => 'TelegramIntegration']])) : ?> 34 |

Exists

35 | 36 |

Missing

37 | 38 | 39 |
Event listeners
40 | ['event' => 'chat.desktop_client_admin_msg', 'bot_id' => $bot->id]])) : ?> 41 |

chat.desktop_client_admin_msg

42 | 43 |

chat.desktop_client_admin_msg

44 | 45 | 46 | ['event' => 'chat.web_add_msg_admin', 'bot_id' => $bot->id]])) : ?> 47 |

chat.web_add_msg_admin

48 | 49 |

chat.web_add_msg_admin

50 | 51 | 52 | ['event' => 'chat.workflow.canned_message_before_save', 'bot_id' => $bot->id]])) : ?> 53 |

chat.workflow.canned_message_before_save

54 | 55 |

chat.workflow.canned_message_before_save

56 | 57 | 58 | ['event' => 'chat.before_auto_responder_msg_saved', 'bot_id' => $bot->id]])) : ?> 59 |

chat.before_auto_responder_msg_saved

60 | 61 |

chat.before_auto_responder_msg_saved

62 | 63 | 64 |   65 | 66 | 67 |
68 | -------------------------------------------------------------------------------- /design/lhctelegramtheme/tpl/lhtelegram/parts/filter.tpl.php: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 |
7 |
8 |
9 | 10 | 'bot_id', 12 | 'optional_field' => erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Choose bot'), 13 | 'selected_id' => $input->bot_id, 14 | 'css_class' => 'form-control', 15 | 'display_name' => 'bot_username', 16 | 'list_function' => 'erLhcoreClassModelTelegramBot::getList' 17 | )); ?> 18 |
19 |
20 |
21 |
22 | 23 | 'user_id', 25 | 'optional_field' => erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Select user'), 26 | 'selected_id' => $input->user_id, 27 | 'css_class' => 'form-control', 28 | 'display_name' => 'name_official', 29 | 'list_function' => 'erLhcoreClassModelUser::getUserList' 30 | )); ?> 31 |
32 |
33 |
34 |
35 | 36 |
37 |
38 | 39 |
-------------------------------------------------------------------------------- /design/lhctelegramtheme/tpl/lhtelegram/parts/form.tpl.php: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
5 | 6 |
7 | 8 | 9 |
10 | 11 |
12 | 13 | 14 |

How long chat is considered existing before new chat is created

15 |
16 | 17 |
18 | 19 | 'dep_id', 21 | 'optional_field' => erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Select department'), 22 | 'selected_id' => $item->dep_id, 23 | 'css_class' => 'form-control', 24 | 'list_function' => 'erLhcoreClassModelDepartament::getList', 25 | 'list_function_params' => array(), 26 | )); ?> 27 |
28 | 29 |
30 |
31 |
-------------------------------------------------------------------------------- /design/lhctelegramtheme/tpl/lhtelegram/parts/form_department.tpl.php: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 | 5 |
6 | 7 |
8 | 9 |
10 | 11 |
12 | 13 |
14 | 15 | 16 |
17 | 18 |

If checked. Bot will acts as client. So you will receive new chat requests and messages from visitors and will be able to chat with them.

19 |
20 | getDepartments(); foreach (erLhcoreClassModelDepartament::getList() as $dep) : ?> 21 |
22 | 23 | -------------------------------------------------------------------------------- /design/lhctelegramtheme/tpl/lhtelegram/parts/form_operator.tpl.php: -------------------------------------------------------------------------------- 1 |
2 | 3 |

getTranslation('module/fbmessenger','Do not check this unless you know what you are doing. This value will be automatically checked once you confirm your operator from telegram.')?>

4 |
5 | 6 |
7 | 8 | 'user_id', 10 | 'optional_field' => erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Select operator'), 11 | 'selected_id' => $item->user_id, 12 | 'css_class' => 'form-control', 13 | 'display_name' => 'name_official', 14 | 'list_function' => 'erLhcoreClassModelUser::getUserList', 15 | 'list_function_params' => array(), 16 | )); ?> 17 |
18 | 19 |
20 | 21 | 'bot_id', 23 | 'optional_field' => erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Select bot'), 24 | 'selected_id' => $item->bot_id, 25 | 'css_class' => 'form-control', 26 | 'display_name' => 'bot_username', 27 | 'list_function' => 'erLhcoreClassModelTelegramBot::getList', 28 | 'list_function_params' => array('filter' => array('bot_client' => 1)), 29 | )); ?> 30 |
-------------------------------------------------------------------------------- /design/lhctelegramtheme/tpl/lhtelegram/parts/form_signature.tpl.php: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 'bot_id', 6 | 'optional_field' => erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','All bots'), 7 | 'selected_id' => $item->bot_id, 8 | 'css_class' => 'form-control input-sm', 9 | 'display_name' => 'bot_username', 10 | 'list_function' => 'erLhcoreClassModelTelegramBot::getList' 11 | )); ?> 12 |
13 | 14 |
15 | 16 | 'user_id', 18 | 'optional_field' => erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Select operator'), 19 | 'selected_id' => $item->user_id, 20 | 'css_class' => 'form-control input-sm', 21 | 'display_name' => 'name_official', 22 | 'list_function' => 'erLhcoreClassModelUser::getUserList' 23 | )); ?> 24 |
25 | 26 |
27 | 28 | 29 |
-------------------------------------------------------------------------------- /design/lhctelegramtheme/tpl/lhtelegram/setwebhook.tpl.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

Webhook URL set to - callback_url?>

8 | -------------------------------------------------------------------------------- /design/lhctelegramtheme/tpl/lhtelegram/signatures.tpl.php: -------------------------------------------------------------------------------- 1 |

getTranslation('module/fbmessenger','Signatures');?>

2 | 3 | 4 | getTranslation('user/account','Removed!'); ?> 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
UserSignatureBot
user)?>signature,30,'...',30,ENT_QUOTES);?>bot)?>getTranslation('user/userlist','Edit');?>getTranslation('user/userlist','Delete');?>
27 | 28 | 29 | 30 | 31 | New 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /design/lhctelegramtheme/tpl/pagelayouts/parts/modules_menu/extension_module_multiinclude.tpl.php: -------------------------------------------------------------------------------- 1 | hasAccessTo('lhtelegram','use_admin')) : ?> 2 | 3 | -------------------------------------------------------------------------------- /doc/img/bot-as-admin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiveHelperChat/telegram/6ae80031037979c01335e9ebdb4fa9caa41eaca0/doc/img/bot-as-admin.png -------------------------------------------------------------------------------- /doc/img/copylink.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiveHelperChat/telegram/6ae80031037979c01335e9ebdb4fa9caa41eaca0/doc/img/copylink.png -------------------------------------------------------------------------------- /doc/img/enable-topics.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiveHelperChat/telegram/6ae80031037979c01335e9ebdb4fa9caa41eaca0/doc/img/enable-topics.png -------------------------------------------------------------------------------- /doc/img/manage-group.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiveHelperChat/telegram/6ae80031037979c01335e9ebdb4fa9caa41eaca0/doc/img/manage-group.png -------------------------------------------------------------------------------- /doc/img/start-command.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiveHelperChat/telegram/6ae80031037979c01335e9ebdb4fa9caa41eaca0/doc/img/start-command.png -------------------------------------------------------------------------------- /doc/img/topic-chats.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiveHelperChat/telegram/6ae80031037979c01335e9ebdb4fa9caa41eaca0/doc/img/topic-chats.png -------------------------------------------------------------------------------- /doc/install.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `lhc_telegram_chat` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `chat_id` bigint(20) unsigned NOT NULL, `chat_id_internal` bigint(20) NOT NULL, `tchat_id` bigint(20) unsigned NOT NULL, `type` tinyint(1) unsigned NOT NULL DEFAULT '0', `bot_id` bigint(20) unsigned NOT NULL, `ctime` bigint(20) unsigned NOT NULL, `utime` bigint(20) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `tchat_id_utime` (`tchat_id`,`utime`), KEY `chat_id` (`chat_id`), KEY `chat_id_internal` (`chat_id_internal`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; 2 | CREATE TABLE `lhc_telegram_bot` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `bot_username` varchar(50) NOT NULL, `notify_page_change` tinyint(1) unsigned NOT NULL DEFAULT '0', `delete_on_close` tinyint(1) unsigned NOT NULL DEFAULT '0', `bot_disabled` tinyint(1) unsigned NOT NULL, `bot_api` varchar(50) NOT NULL, `group_chat_id` bigint(20) NOT NULL, `dep_id` bigint(20) unsigned NOT NULL, `bot_client` bigint(20) unsigned NOT NULL, `webhook_set` bigint(20) unsigned NOT NULL, `chat_timeout` bigint(20) unsigned NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; 3 | CREATE TABLE `lhc_telegram_signature` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `bot_id` bigint(20) unsigned NOT NULL, `user_id` bigint(20) unsigned NOT NULL, `signature` text NOT NULL, PRIMARY KEY (`id`), KEY `bot_id_user_id` (`bot_id`,`user_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; 4 | CREATE TABLE `lhc_telegram_operator` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `bot_id` bigint(20) unsigned NOT NULL, `chat_id` bigint(20) unsigned NOT NULL,`tchat_id` bigint(20) unsigned NOT NULL, `tuser_id` bigint(20) unsigned NOT NULL, `user_id` bigint(20) unsigned NOT NULL ,`confirmed` tinyint(1) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `bot_id` (`bot_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; 5 | CREATE TABLE `lhc_telegram_bot_dep` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `bot_id` bigint(20) unsigned NOT NULL, `dep_id` bigint(20) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `bot_id` (`bot_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; 6 | CREATE TABLE `lhc_telegram_lead` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `tchat_id` bigint(20) unsigned NOT NULL, `dep_id` bigint(20) unsigned NOT NULL, `tbot_id` bigint(20) unsigned NOT NULL, `utime` bigint(20) unsigned NOT NULL, `ctime` bigint(20) unsigned NOT NULL, `first_name` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `last_name` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `username` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `language_code` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), KEY `tchat_id` (`tchat_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -------------------------------------------------------------------------------- /doc/telegram/bot-data.json: -------------------------------------------------------------------------------- 1 | {"bot":{"name":"TelegramIntegration"},"groups":[{"group":{"name":"Default","is_collapsed":0,"pos":0},"triggers":[{"trigger":{"id":1768,"name":"Send","actions":"[{\"_id\":\"CsLix6iiX\",\"type\":\"restapi\",\"content\":{\"text\":\"\",\"rest_api\":62,\"rest_api_method\":\"temp1695212526903\",\"rest_api_method_params\":[],\"rest_api_method_output\":{\"default_trigger\":\"1769\"},\"attr_options\":{\"no_body\":true}}}]","default":0,"default_unknown":0,"default_always":0,"default_unknown_btn":0,"as_argument":0,"in_progress":0},"events":[],"payloads":[]},{"trigger":{"id":1769,"name":"Debug","actions":"[{\"_id\":\"tV0edgixf\",\"type\":\"text\",\"content\":{\"text\":\"{http_code}\\n{http_error}\\n{content_raw}\\n{http_data}\",\"attr_options\":{\"as_system\":true}},\"skip_resp\":false}]","default":0,"default_unknown":0,"default_always":0,"default_unknown_btn":0,"as_argument":0,"in_progress":0},"events":[],"payloads":[]}]}]} -------------------------------------------------------------------------------- /doc/telegram/chat.before_auto_responder_msg_saved.json: -------------------------------------------------------------------------------- 1 | { 2 | "event": "chat.before_auto_responder_msg_saved", 3 | "bot_id": 134, 4 | "trigger_id": 1387, 5 | "trigger_id_alt": 0, 6 | "bot_id_alt": 0, 7 | "disabled": 0, 8 | "type": 0, 9 | "configuration": "[{\"_id\":\"wmR0a5cSSq\",\"type\":\"3\",\"logic\":\"and\",\"attr\":\"{args.chat.incoming_chat.incoming.scope}\",\"condition\":\"eq\",\"value\":\"telegram\"},{\"_id\":\"2yw41CoIM2\",\"type\":\"3\",\"logic\":\"and\",\"attr\":\"{args.chat.last_message.meta_msg_array.content.whisper}\",\"condition\":\"neq\",\"value\":\"1\"},{\"_id\":\"upxotszFTO\",\"type\":\"3\",\"logic\":\"and\",\"attr\":\"{args.chat.last_message.user_id}\",\"condition\":\"neq\",\"value\":\"-1\"}]" 10 | } -------------------------------------------------------------------------------- /doc/telegram/chat.desktop_client_admin_msg.json: -------------------------------------------------------------------------------- 1 | { 2 | "event": "chat.desktop_client_admin_msg", 3 | "bot_id": 134, 4 | "trigger_id": 1387, 5 | "trigger_id_alt": 0, 6 | "bot_id_alt": 0, 7 | "disabled": 0, 8 | "type": 0, 9 | "configuration": "[{\"_id\":\"wmR0a5cSSq\",\"type\":\"3\",\"logic\":\"and\",\"attr\":\"{args.chat.incoming_chat.incoming.scope}\",\"condition\":\"eq\",\"value\":\"telegram\"},{\"_id\":\"2yw41CoIM2\",\"type\":\"3\",\"logic\":\"and\",\"attr\":\"{args.chat.last_message.meta_msg_array.content.whisper}\",\"condition\":\"neq\",\"value\":\"1\"},{\"_id\":\"upxotszFTO\",\"type\":\"3\",\"logic\":\"and\",\"attr\":\"{args.chat.last_message.user_id}\",\"condition\":\"neq\",\"value\":\"-1\"}]" 10 | } -------------------------------------------------------------------------------- /doc/telegram/chat.web_add_msg_admin.json: -------------------------------------------------------------------------------- 1 | { 2 | "event": "chat.web_add_msg_admin", 3 | "bot_id": 134, 4 | "trigger_id": 1387, 5 | "trigger_id_alt": 0, 6 | "bot_id_alt": 0, 7 | "disabled": 0, 8 | "type": 0, 9 | "configuration": "[{\"_id\":\"wmR0a5cSSq\",\"type\":\"3\",\"logic\":\"and\",\"attr\":\"{args.chat.incoming_chat.incoming.scope}\",\"condition\":\"eq\",\"value\":\"telegram\"},{\"_id\":\"2yw41CoIM2\",\"type\":\"3\",\"logic\":\"and\",\"attr\":\"{args.chat.last_message.meta_msg_array.content.whisper}\",\"condition\":\"neq\",\"value\":\"1\"},{\"_id\":\"upxotszFTO\",\"type\":\"3\",\"logic\":\"and\",\"attr\":\"{args.chat.last_message.user_id}\",\"condition\":\"neq\",\"value\":\"-1\"}]" 10 | } -------------------------------------------------------------------------------- /doc/telegram/chat.workflow.canned_message_before_save.json: -------------------------------------------------------------------------------- 1 | { 2 | "event": "chat.workflow.canned_message_before_save", 3 | "bot_id": 134, 4 | "trigger_id": 1387, 5 | "trigger_id_alt": 0, 6 | "bot_id_alt": 0, 7 | "disabled": 0, 8 | "type": 0, 9 | "configuration": "[{\"_id\":\"wmR0a5cSSq\",\"type\":\"3\",\"logic\":\"and\",\"attr\":\"{args.chat.incoming_chat.incoming.scope}\",\"condition\":\"eq\",\"value\":\"telegram\"},{\"_id\":\"2yw41CoIM2\",\"type\":\"3\",\"logic\":\"and\",\"attr\":\"{args.chat.last_message.meta_msg_array.content.whisper}\",\"condition\":\"neq\",\"value\":\"1\"},{\"_id\":\"upxotszFTO\",\"type\":\"3\",\"logic\":\"and\",\"attr\":\"{args.chat.last_message.user_id}\",\"condition\":\"neq\",\"value\":\"-1\"}]" 10 | } -------------------------------------------------------------------------------- /doc/telegram/incoming-webhook.json: -------------------------------------------------------------------------------- 1 | {"name":"TelegramIntegration","dep_id":1,"disabled":0,"identifier":"","scope":"telegram","configuration":"{\"attr\":[{\"key\":\"access_token\",\"value\":\"___replace_me___\",\"id\":\"temp1694762926692\",\"$$hashKey\":\"object:195\"},{\"key\":\"bot_username\",\"value\":\"___replace_me___\",\"id\":\"temp1695295631652\",\"$$hashKey\":\"object:300\"}],\"messages\":\"\",\"message_direct\":true,\"nick\":\"message.from.first_name|||message.from.last_name|||callback_query.from.first_name|||callback_query.from.last_name|||message_reaction.chat.first_name|||message_reaction.chat.last_name|||edited_message.from.first_name|||edited_message.from.last_name\",\"country_code\":\"\",\"chat_id\":\"message.chat.id|||callback_query.message.chat.id|||message_reaction.chat.id|||edited_message.chat.id\",\"msg_body\":\"{{msg.message.text}}\",\"msg_cond\":\"message.text=__exists__\",\"msg_cond_img\":\"message.photo=__exists__\",\"msg_img\":\"{{msg.message.caption}}\\n{{msg.body}}\",\"msg_cond_2\":\"\",\"msg_body_2\":\"\",\"msg_cond_img_url_decode\":\"https:\/\/api.telegram.org\/bot{{msg.incoming_webhook.incoming_dynamic_array.access_token}}\/getFile?file_id={{msg.message.photo___array_pop.file_id}}\",\"msg_cond_img_url_decode_output\":\"result.file_path||https:\/\/api.telegram.org\/file\/bot{{msg.incoming_webhook.incoming_dynamic_array.access_token}}\/{{response}}\",\"msg_cond_img_body\":\"body\",\"msg_img_download\":false,\"msg_cond_img_url_remote_location\":true,\"msg_cond_attachments\":\"message.document=__exists__\",\"msg_attachments\":\"{{msg.body}}\\n{{msg.message.document.file_name}}\",\"msg_cond_attachments_body\":\"body\",\"msg_cond_attachments_url_decode\":\"https:\/\/api.telegram.org\/bot{{msg.incoming_webhook.incoming_dynamic_array.access_token}}\/getFile?file_id={{msg.message.document.file_id}}\",\"msg_cond_attachments_url_remote_location\":true,\"msg_cond_attachments_url_remote_headers_content\":\"\",\"msg_cond_attachments_url_decode_output\":\"result.file_path||https:\/\/api.telegram.org\/file\/bot{{msg.incoming_webhook.incoming_dynamic_array.access_token}}\/{{response}}\",\"msg_cond_attachments_file_name\":\"\",\"msg_img_2\":\"{{msg.body}}\\n{{msg.message.sticker.set_name}}\",\"msg_cond_img_2_body\":\"body\",\"msg_cond_img_2_url_decode\":\"https:\/\/api.telegram.org\/bot{{msg.incoming_webhook.incoming_dynamic_array.access_token}}\/getFile?file_id={{msg.message.sticker.file_id}}\",\"msg_cond_img_2_url_decode_output\":\"result.file_path||https:\/\/api.telegram.org\/file\/bot{{msg.incoming_webhook.incoming_dynamic_array.access_token}}\/{{response}}\",\"msg_cond_img_2_url_remote_location\":true,\"msg_cond_img_2\":\"message.sticker=__exists__\",\"msg_img_3\":\"{{msg.body}}\",\"msg_cond_img_3_body\":\"body\",\"msg_cond_img_3_url_decode\":\"https:\/\/api.telegram.org\/bot{{msg.incoming_webhook.incoming_dynamic_array.access_token}}\/getFile?file_id={{msg.message.voice.file_id}}\",\"msg_cond_img_3_url_decode_output\":\"result.file_path||https:\/\/api.telegram.org\/file\/bot{{msg.incoming_webhook.incoming_dynamic_array.access_token}}\/{{response}}\",\"msg_cond_img_3_url_remote_location\":true,\"msg_cond_img_3\":\"message.voice=__exists__\",\"msg_img_4\":\"{{msg.body}}\",\"msg_cond_img_4_body\":\"body\",\"msg_cond_img_4_url_decode\":\"https:\/\/api.telegram.org\/bot{{msg.incoming_webhook.incoming_dynamic_array.access_token}}\/getFile?file_id={{msg.message.video_note.file_id}}\",\"msg_cond_img_4_url_decode_output\":\"result.file_path||https:\/\/api.telegram.org\/file\/bot{{msg.incoming_webhook.incoming_dynamic_array.access_token}}\/{{response}}\",\"msg_cond_img_4_url_remote_location\":true,\"msg_cond_img_4\":\"message.video_note=__exists__\",\"msg_img_5\":\"{{msg.body}}\\n{{msg.message.audio.file_name}}\",\"msg_cond_img_5_body\":\"body\",\"msg_cond_img_5_url_decode\":\"https:\/\/api.telegram.org\/bot{{msg.incoming_webhook.incoming_dynamic_array.access_token}}\/getFile?file_id={{msg.message.audio.file_id}}\",\"msg_cond_img_5_url_decode_output\":\"result.file_path||https:\/\/api.telegram.org\/file\/bot{{msg.incoming_webhook.incoming_dynamic_array.access_token}}\/{{response}}\",\"msg_cond_img_5_url_remote_location\":true,\"msg_cond_img_5\":\"message.audio=__exists__\",\"msg_btn_cond_1\":\"callback_query.data=__exists__\",\"msg_btn_payload_1\":\"callback_query.data\",\"add_field_2_value\":\"telegram_bot_id\",\"add_field_value\":\"message.from.username|||callback_query.from.username|||message_reaction.chat.username|||edited_message.chat.username\",\"msg_cond_img_file_size\":\"message.photo___array_pop.file_size\",\"msg_cond_img_2_file_size\":\"message.sticker.file_size\",\"msg_cond_img_3_file_size\":\"message.voice.file_size\",\"msg_cond_img_4_file_size\":\"message.video_note.file_size\",\"msg_cond_img_5_file_size\":\"message.audio.file_size\",\"msg_cond_attachments_file_size\":\"message.document.file_size\",\"msg_img_6\":\"{{msg.body}}\\n{{msg.message.video.file_name}}\",\"msg_cond_img_6_file_size\":\"message.video.file_size\",\"msg_cond_img_6_url_decode\":\"https:\/\/api.telegram.org\/bot{{msg.incoming_webhook.incoming_dynamic_array.access_token}}\/getFile?file_id={{msg.message.video.file_id}}\",\"msg_cond_img_6_url_decode_output\":\"result.file_path||https:\/\/api.telegram.org\/file\/bot{{msg.incoming_webhook.incoming_dynamic_array.access_token}}\/{{response}}\",\"msg_cond_img_6_url_remote_location\":true,\"msg_cond_img_6\":\"message.video=__exists__\",\"msg_cond_img_6_body\":\"body\",\"msg_delivery_reaction_id\":\"message_reaction.message_id\",\"msg_delivery_reaction_condition\":\"message_reaction.new_reaction.0.type=__exists__\",\"msg_delivery_reaction_use_emoji\":true,\"msg_delivery_reaction_location\":\"message_reaction.new_reaction.0.emoji\",\"msg_delivery_reaction_remove_if_empty\":false,\"msg_delivery_reaction_remove_prev\":true,\"msg_delivery_un_reaction_id\":\"message_reaction.message_id\",\"msg_delivery_un_reaction_condition\":\"message_reaction.old_reaction.0.type=__exists__\",\"msg_delivery_un_reaction_use_emoji\":true,\"msg_delivery_edited_id\":\"edited_message.message_id\",\"msg_delivery_edited_condition\":\"edited_message=__exists__\",\"msg_delivery_edited_location\":\"edited_message.text\",\"message_id\":\"message.message_id\"}","icon":"social\/telegram-ico.png","icon_color":"","log_incoming":0,"log_failed_parse":0} -------------------------------------------------------------------------------- /doc/telegram/rest-api.json: -------------------------------------------------------------------------------- 1 | {"name":"TelegramIntegration","description":"","configuration":"{\"host\":\"https:\/\/api.telegram.org\",\"ecache\":false,\"parameters\":[{\"method\":\"POST\",\"authorization\":\"\",\"api_key_location\":\"header\",\"query\":[],\"header\":[],\"conditions\":[],\"postparams\":[],\"userparams\":[],\"output\":[{\"key\":\"\",\"value\":\"\",\"id\":\"temp1706685738487\",\"success_name\":\"Success\",\"success_header\":\"200\"}],\"id\":\"temp1695212526903\",\"name\":\"Send\",\"suburl\":\"\/bot{{args.chat.incoming_chat.incoming_dynamic_array.access_token}}\/sendMessage\",\"body_request_type\":\"raw\",\"body_raw\":\"{\\n \\\"chat_id\\\":{{args.chat.incoming_chat.chat_external_id}},\\\"parse_mode\\\":\\\"HTML\\\",\\n \\\"text\\\":{{msg_html_nobr}}\\n{interactive_api}\\n,\\\"reply_markup\\\":{\\n \\\"resize_keyboard\\\":true,\\n\\\"inline_keyboard\\\":[\\n{button_template}\\n [{\\n \\\"text\\\": {{button_title}},\\n \\\"{is_url}url{\/is_url}{is_button}callback_data{\/is_button}\\\":{{button_payload}}\\n }]\\n{\/button_template}\\n]\\n}\\n\\n{\/interactive_api}\\n}\",\"body_request_type_content\":\"json\",\"remote_message_id\":\"result:message_id\",\"suburl_file\":\"\/bot{{args.chat.incoming_chat.incoming_dynamic_array.access_token}}\/{api_by_ext__tgs}sendSticker{\/api_by_ext}{api_by_ext__ogg}sendVoice{\/api_by_ext}{api_by_ext__mp3_m4a}sendAudio{\/api_by_ext}{api_by_ext__mp4}sendVideo{\/api_by_ext}{image_api}sendPhoto{\/image_api}{file_api}sendDocument{\/file_api}\",\"body_raw_file\":\"{\\n \\\"chat_id\\\":{{args.chat.incoming_chat.chat_external_id}},\\n \\\"{api_by_ext__tgs}sticker{\/api_by_ext}{api_by_ext__ogg}voice{\/api_by_ext}{api_by_ext__mp3_m4a}audio{\/api_by_ext}{api_by_ext__mp4}video{\/api_by_ext}{file_api}document{\/file_api}{image_api}photo{\/image_api}\\\":{{file_url}}\\n}\",\"suburl_file_convert\":\"tgs,file_api,mp3_m4a,ogg\"}]}"} -------------------------------------------------------------------------------- /modules/lhcron/test.php: -------------------------------------------------------------------------------- 1 | dispatch('chat.chat_started',array('chat' => & $chat, 'msg' => $msg));*/ 10 | 11 | $telegram = new Longman\TelegramBot\Telegram('', ''); 12 | 13 | print_r(Longman\TelegramBot\Request::send('createForumTopic',[ 14 | 'chat_id' => -1001634340846, 15 | 'name' => 'dummy topic' 16 | ])); 17 | 18 | 19 | 20 | ?> -------------------------------------------------------------------------------- /modules/lhcron/update_structure.php: -------------------------------------------------------------------------------- 1 | $status) { 12 | $queries = array_merge($queries,$status['queries']); 13 | } 14 | 15 | if (empty($queries)){ 16 | echo "No queries to execute found\n"; 17 | } else { 18 | echo "The following queries will be executed\nYou have 10 seconds to stop executing these quries\n"; 19 | echo implode("\n", $queries)."\n"; 20 | sleep(10); 21 | 22 | erLhcoreClassUpdate::doTablesUpdate(json_decode($contentData,true)); 23 | echo "Tables were updated"; 24 | } 25 | 26 | 27 | ?> -------------------------------------------------------------------------------- /modules/lhtelegram/callback.php: -------------------------------------------------------------------------------- 1 | setBot($tBot); 11 | 12 | // Add you bot's API key and name 13 | $bot_api_key = $tBot->bot_api; // $telegramExt->settings['bot_api']; 14 | $bot_username = $tBot->bot_username; // $telegramExt->settings['bot_username']; 15 | 16 | // Define all IDs of admin users in this array (leave as empty array if not used) 17 | $admin_users = [ 18 | // 123, 19 | ]; 20 | 21 | // Define all paths for your custom commands in this array (leave as empty array if not used) 22 | $commands_paths = [ 23 | 'extension/lhctelegram/classes/Commands/', 24 | ]; 25 | 26 | try { 27 | 28 | 29 | // Create Telegram API object 30 | $telegram = new Longman\TelegramBot\Telegram($bot_api_key, $bot_username); 31 | 32 | // Add commands paths containing your custom commands 33 | $telegram->addCommandsPaths($commands_paths); 34 | 35 | // Enable admin users 36 | $telegram->enableAdmins($admin_users); 37 | 38 | // Enable MySQL 39 | //$telegram->enableMySql($mysql_credentials); 40 | 41 | // Logging (Error, Debug and Raw Updates) 42 | //Longman\TelegramBot\TelegramLog::initErrorLog(__DIR__ . "/{$bot_username}_error.log"); 43 | //Longman\TelegramBot\TelegramLog::initDebugLog(__DIR__ . "/{$bot_username}_debug.log"); 44 | //Longman\TelegramBot\TelegramLog::initUpdateLog(__DIR__ . "/{$bot_username}_update.log"); 45 | 46 | // If you are using a custom Monolog instance for logging, use this instead of the above 47 | //Longman\TelegramBot\TelegramLog::initialize($your_external_monolog_instance); 48 | 49 | // Set custom Upload and Download paths 50 | //$telegram->setDownloadPath(__DIR__ . '/Download'); 51 | //$telegram->setUploadPath(__DIR__ . '/Upload'); 52 | 53 | // Here you can set some command specific parameters 54 | // e.g. Google geocode/timezone api key for /date command 55 | //$telegram->setCommandConfig('date', ['google_api_key' => 'your_google_api_key_here']); 56 | 57 | // Botan.io integration 58 | //$telegram->enableBotan('your_botan_token'); 59 | 60 | // Requests Limiter (tries to prevent reaching Telegram API limits) 61 | $telegram->enableLimiter(); 62 | 63 | // Handle telegram webhook request 64 | $telegram->handle(); 65 | 66 | } catch (Longman\TelegramBot\Exception\TelegramException $e) { 67 | erLhcoreClassLog::write($e->getMessage()); 68 | } catch (Longman\TelegramBot\Exception\TelegramLogException $e) { 69 | erLhcoreClassLog::write($e->getMessage()); 70 | } catch (Exception $e) { 71 | erLhcoreClassLog::write($e->getMessage()); 72 | } 73 | 74 | exit; 75 | ?> -------------------------------------------------------------------------------- /modules/lhtelegram/delete.php: -------------------------------------------------------------------------------- 1 | validateCSFRToken($Params['user_parameters_unordered']['csfr'])) { 4 | die('Invalid CSFR Token'); 5 | exit; 6 | } 7 | 8 | try { 9 | $item = erLhcoreClassModelTelegramBot::fetch( $Params['user_parameters']['id']); 10 | $item->removeThis(); 11 | 12 | erLhcoreClassModule::redirect('telegram/list'); 13 | exit; 14 | 15 | } catch (Exception $e) { 16 | 17 | print_r( $e); 18 | 19 | $tpl = erLhcoreClassTemplate::getInstance('lhkernel/validation_error.tpl.php'); 20 | $tpl->set('errors',array($e->getMessage())); 21 | $Result['content'] = $tpl->fetch(); 22 | } 23 | 24 | ?> -------------------------------------------------------------------------------- /modules/lhtelegram/deleteoperator.php: -------------------------------------------------------------------------------- 1 | validateCSFRToken($Params['user_parameters_unordered']['csfr'])) { 4 | die('Invalid CSFR Token'); 5 | exit; 6 | } 7 | 8 | try { 9 | $item = erLhcoreClassModelTelegramOperator::fetch( $Params['user_parameters']['id']); 10 | $item->removeThis(); 11 | 12 | erLhcoreClassModule::redirect('telegram/operators'); 13 | exit; 14 | 15 | } catch (Exception $e) { 16 | 17 | $tpl = erLhcoreClassTemplate::getInstance('lhkernel/validation_error.tpl.php'); 18 | $tpl->set('errors',array($e->getMessage())); 19 | $Result['content'] = $tpl->fetch(); 20 | } 21 | 22 | ?> -------------------------------------------------------------------------------- /modules/lhtelegram/deletesignature.php: -------------------------------------------------------------------------------- 1 | validateCSFRToken($Params['user_parameters_unordered']['csfr'])) { 4 | die('Invalid CSFR Token'); 5 | exit; 6 | } 7 | 8 | try { 9 | $item = erLhcoreClassModelTelegramSignature::fetch( $Params['user_parameters']['id']); 10 | $item->removeThis(); 11 | 12 | erLhcoreClassModule::redirect('telegram/signatures'); 13 | exit; 14 | 15 | } catch (Exception $e) { 16 | 17 | $tpl = erLhcoreClassTemplate::getInstance('lhkernel/validation_error.tpl.php'); 18 | $tpl->set('errors',array($e->getMessage())); 19 | $Result['content'] = $tpl->fetch(); 20 | } 21 | 22 | ?> -------------------------------------------------------------------------------- /modules/lhtelegram/edit.php: -------------------------------------------------------------------------------- 1 | saveThis(); 19 | 20 | erLhcoreClassModule::redirect('telegram/list'); 21 | exit; 22 | 23 | } catch (Exception $e) { 24 | $tpl->set('errors',array($e->getMessage())); 25 | } 26 | 27 | } else { 28 | $tpl->set('errors',$Errors); 29 | } 30 | } 31 | 32 | $tpl->setArray(array( 33 | 'item' => $item, 34 | )); 35 | 36 | $Result['content'] = $tpl->fetch(); 37 | 38 | $Result['path'] = array( 39 | array('url' =>erLhcoreClassDesign::baseurl('telegram/index'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger','Telegram')), 40 | array ( 41 | 'url' =>erLhcoreClassDesign::baseurl('telegram/list'), 42 | 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger','Telegram bots') 43 | ), 44 | array ( 45 | 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger', 'Edit bot') 46 | ) 47 | ); 48 | 49 | ?> -------------------------------------------------------------------------------- /modules/lhtelegram/editdepartments.php: -------------------------------------------------------------------------------- 1 | saveThis(); 14 | $tpl->set('status', 'updated'); 15 | } catch (Exception $e) { 16 | $tpl->set('errors',array($e->getMessage())); 17 | } 18 | } else { 19 | $tpl->set('errors',$Errors); 20 | } 21 | } 22 | 23 | $tpl->setArray(array( 24 | 'item' => $item, 25 | )); 26 | 27 | $Result['content'] = $tpl->fetch(); 28 | 29 | $Result['path'] = array( 30 | array('url' =>erLhcoreClassDesign::baseurl('telegram/index'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger','Telegram')), 31 | array ( 32 | 'url' =>erLhcoreClassDesign::baseurl('telegram/list'), 33 | 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger','Telegram bots') 34 | ), 35 | array ( 36 | 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger', 'Edit bot departments') 37 | ) 38 | ); 39 | 40 | ?> -------------------------------------------------------------------------------- /modules/lhtelegram/editoperator.php: -------------------------------------------------------------------------------- 1 | saveThis(); 19 | 20 | erLhcoreClassModule::redirect('telegram/operators'); 21 | exit; 22 | 23 | } catch (Exception $e) { 24 | $tpl->set('errors',array($e->getMessage())); 25 | } 26 | 27 | } else { 28 | $tpl->set('errors',$Errors); 29 | } 30 | } 31 | 32 | $tpl->setArray(array( 33 | 'item' => $item, 34 | )); 35 | 36 | $Result['content'] = $tpl->fetch(); 37 | 38 | $Result['path'] = array( 39 | array('url' =>erLhcoreClassDesign::baseurl('telegram/index'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger','Telegram')), 40 | array ( 41 | 'url' =>erLhcoreClassDesign::baseurl('telegram/operators'), 42 | 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger','Telegram operators') 43 | ), 44 | array ( 45 | 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger', 'Edit operator') 46 | ) 47 | ); 48 | 49 | ?> -------------------------------------------------------------------------------- /modules/lhtelegram/editsignature.php: -------------------------------------------------------------------------------- 1 | removeThis(); 10 | 11 | erLhcoreClassModule::redirect('telegram/editsignature', '/' . $item->id . '/(status)/removed'); 12 | exit; 13 | } 14 | 15 | $prependURLEdit = ''; 16 | 17 | if (is_numeric($Params['user_parameters_unordered']['itemid']) && $Params['user_parameters_unordered']['action'] == 'edit') { 18 | $newSignature = erLhcoreClassModelTelegramSignature::fetch($Params['user_parameters_unordered']['itemid']); 19 | $prependURLEdit = '/(action)/edit/(itemid)/' . $newSignature->id; 20 | } else { 21 | $newSignature = new erLhcoreClassModelTelegramSignature(); 22 | } 23 | 24 | if (ezcInputForm::hasPostData()) { 25 | 26 | $Errors = erLhcoreClassTelegramValidator::validateSignature($newSignature); 27 | 28 | if (count($Errors) == 0) { 29 | try { 30 | $newSignature->bot_id = $item->id; 31 | $newSignature->saveThis(); 32 | 33 | if ($Params['user_parameters_unordered']['action'] == 'edit'){ 34 | erLhcoreClassModule::redirect('telegram/editsignature', '/' . $item->id . '/(status)/updated'); 35 | exit; 36 | } 37 | 38 | erLhcoreClassModule::redirect('telegram/editsignature', '/' . $item->id . '/(status)/saved'); 39 | exit; 40 | 41 | } catch (Exception $e) { 42 | $tpl->set('errors',array($e->getMessage())); 43 | } 44 | 45 | } else { 46 | $tpl->set('errors',$Errors); 47 | } 48 | } 49 | 50 | $tpl->setArray(array( 51 | 'item' => $item, 52 | 'prependURLEdit' => $prependURLEdit, 53 | 'status' => $Params['user_parameters_unordered']['status'], 54 | 'newSignature' => $newSignature, 55 | 'signatures' => erLhcoreClassModelTelegramSignature::getList(array('filter' => array('bot_id' => $item->id))) 56 | )); 57 | 58 | 59 | $Result['content'] = $tpl->fetch(); 60 | 61 | $Result['path'] = array( 62 | array('url' =>erLhcoreClassDesign::baseurl('telegram/index'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger','Telegram')), 63 | array ( 64 | 'url' =>erLhcoreClassDesign::baseurl('telegram/list'), 65 | 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger','Telegram bots') 66 | ), 67 | array ( 68 | 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger', 'Edit bot') 69 | ) 70 | ); 71 | 72 | ?> -------------------------------------------------------------------------------- /modules/lhtelegram/editsignatureglobal.php: -------------------------------------------------------------------------------- 1 | saveThis(); 19 | 20 | erLhcoreClassModule::redirect('telegram/signatures'); 21 | exit; 22 | 23 | } catch (Exception $e) { 24 | $tpl->set('errors',array($e->getMessage())); 25 | } 26 | 27 | } else { 28 | $tpl->set('errors',$Errors); 29 | } 30 | } 31 | 32 | $tpl->setArray(array( 33 | 'item' => $item, 34 | )); 35 | 36 | $Result['content'] = $tpl->fetch(); 37 | 38 | $Result['path'] = array( 39 | array('url' =>erLhcoreClassDesign::baseurl('telegram/index'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger','Telegram')), 40 | array ( 41 | 'url' =>erLhcoreClassDesign::baseurl('telegram/signatures'), 42 | 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger','Signatures') 43 | ), 44 | array ( 45 | 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger', 'Edit signature') 46 | ) 47 | ); 48 | 49 | ?> -------------------------------------------------------------------------------- /modules/lhtelegram/index.php: -------------------------------------------------------------------------------- 1 | fetch(); 5 | 6 | $Result['path'] = array( 7 | array( 8 | 'url' => erLhcoreClassDesign::baseurl('telegram/index'), 9 | 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger', 'Telegram') 10 | ) 11 | ); 12 | 13 | ?> -------------------------------------------------------------------------------- /modules/lhtelegram/leads.php: -------------------------------------------------------------------------------- 1 | 'extension/lhctelegram/classes/filter/leads.php','format_filter' => true, 'use_override' => true, 'uparams' => $Params['user_parameters_unordered'])); 7 | $filterParams['is_search'] = true; 8 | } else { 9 | $filterParams = erLhcoreClassSearchHandler::getParams(array('customfilterfile' => 'extension/lhctelegram/classes/filter/leads.php','format_filter' => true, 'uparams' => $Params['user_parameters_unordered'])); 10 | $filterParams['is_search'] = false; 11 | } 12 | 13 | $append = erLhcoreClassSearchHandler::getURLAppendFromInput($filterParams['input_form']); 14 | 15 | $pages = new lhPaginator(); 16 | $pages->items_total = erLhcoreClassModelTelegramLead::getCount($filterParams['filter']); 17 | $pages->translationContext = 'chat/activechats'; 18 | $pages->serverURL = erLhcoreClassDesign::baseurl('telegram/leads').$append; 19 | $pages->paginate(); 20 | $tpl->set('pages',$pages); 21 | 22 | if ($pages->items_total > 0) { 23 | $items = erLhcoreClassModelTelegramLead::getList(array_merge(array('limit' => $pages->items_per_page, 'offset' => $pages->low),$filterParams['filter'])); 24 | $tpl->set('items',$items); 25 | } 26 | 27 | $filterParams['input_form']->form_action = erLhcoreClassDesign::baseurl('telegram/leads'); 28 | $tpl->set('input',$filterParams['input_form']); 29 | $tpl->set('inputAppend',$append); 30 | 31 | $Result['content'] = $tpl->fetch(); 32 | 33 | $Result['path'] = array( 34 | array('url' =>erLhcoreClassDesign::baseurl('telegram/index'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger','Telegram')), 35 | array('url' =>erLhcoreClassDesign::baseurl('telegram/leads'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger','Leads')) 36 | ); 37 | 38 | ?> -------------------------------------------------------------------------------- /modules/lhtelegram/list.php: -------------------------------------------------------------------------------- 1 | 'extension/lhctelegram/classes/filter.php','format_filter' => true, 'use_override' => true, 'uparams' => $Params['user_parameters_unordered'])); 7 | $filterParams['is_search'] = true; 8 | } else { 9 | $filterParams = erLhcoreClassSearchHandler::getParams(array('customfilterfile' => 'extension/lhctelegram/classes/filter.php','format_filter' => true, 'uparams' => $Params['user_parameters_unordered'])); 10 | $filterParams['is_search'] = false; 11 | } 12 | 13 | $append = erLhcoreClassSearchHandler::getURLAppendFromInput($filterParams['input_form']); 14 | 15 | $pages = new lhPaginator(); 16 | $pages->items_total = erLhcoreClassModelTelegramBot::getCount($filterParams['filter']); 17 | $pages->translationContext = 'chat/activechats'; 18 | $pages->serverURL = erLhcoreClassDesign::baseurl('telegram/list').$append; 19 | $pages->paginate(); 20 | $tpl->set('pages',$pages); 21 | 22 | if ($pages->items_total > 0) { 23 | $items = erLhcoreClassModelTelegramBot::getList(array_merge(array('limit' => $pages->items_per_page, 'offset' => $pages->low),$filterParams['filter'])); 24 | $tpl->set('items',$items); 25 | } 26 | 27 | $filterParams['input_form']->form_action = erLhcoreClassDesign::baseurl('telegram/list'); 28 | $tpl->set('input',$filterParams['input_form']); 29 | $tpl->set('inputAppend',$append); 30 | 31 | $Result['content'] = $tpl->fetch(); 32 | 33 | $Result['path'] = array( 34 | array('url' =>erLhcoreClassDesign::baseurl('telegram/index'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger','Telegram')), 35 | array('url' =>erLhcoreClassDesign::baseurl('telegram/list'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger','Telegram bots')) 36 | ); 37 | 38 | ?> -------------------------------------------------------------------------------- /modules/lhtelegram/module.php: -------------------------------------------------------------------------------- 1 | "Telegram", 4 | 'variable_params' => true ); 5 | 6 | $ViewList = array(); 7 | 8 | $ViewList['callback'] = array( 9 | 'params' => array('id'), 10 | 'uparams' => array() 11 | ); 12 | 13 | $ViewList['list'] = array( 14 | 'params' => array(), 15 | 'uparams' => array(), 16 | 'functions' => array('use_admin'), 17 | ); 18 | 19 | $ViewList['operators'] = array( 20 | 'params' => array(), 21 | 'uparams' => array('user_id','bot_id'), 22 | 'functions' => array('use_admin'), 23 | ); 24 | 25 | $ViewList['index'] = array( 26 | 'params' => array(), 27 | 'uparams' => array(), 28 | 'functions' => array('use_admin'), 29 | ); 30 | 31 | $ViewList['new'] = array( 32 | 'params' => array(), 33 | 'uparams' => array(), 34 | 'functions' => array('use_admin'), 35 | ); 36 | 37 | $ViewList['edit'] = array( 38 | 'params' => array('id'), 39 | 'uparams' => array(), 40 | 'functions' => array('use_admin'), 41 | ); 42 | 43 | $ViewList['editsignature'] = array( 44 | 'params' => array('id'), 45 | 'uparams' => array('action','itemid','status'), 46 | 'functions' => array('use_admin'), 47 | ); 48 | 49 | $ViewList['editdepartments'] = array( 50 | 'params' => array('id'), 51 | 'uparams' => array(), 52 | 'functions' => array('use_admin'), 53 | ); 54 | 55 | $ViewList['editsignatureglobal'] = array( 56 | 'params' => array('id'), 57 | 'uparams' => array('action','itemid','status'), 58 | 'functions' => array('use_admin'), 59 | ); 60 | 61 | $ViewList['deletesignature'] = array( 62 | 'params' => array('id'), 63 | 'uparams' => array('csfr'), 64 | 'functions' => array('use_admin'), 65 | ); 66 | 67 | $ViewList['deleteoperator'] = array( 68 | 'params' => array('id'), 69 | 'uparams' => array('csfr'), 70 | 'functions' => array('use_admin'), 71 | ); 72 | 73 | $ViewList['editoperator'] = array( 74 | 'params' => array('id'), 75 | 'uparams' => array(), 76 | 'functions' => array('use_admin'), 77 | ); 78 | 79 | $ViewList['signatures'] = array( 80 | 'params' => array(), 81 | 'uparams' => array(), 82 | 'functions' => array('use_admin'), 83 | ); 84 | 85 | $ViewList['newsignature'] = array( 86 | 'params' => array(), 87 | 'uparams' => array(), 88 | 'functions' => array('use_admin'), 89 | ); 90 | 91 | $ViewList['newoperator'] = array( 92 | 'params' => array(), 93 | 'uparams' => array(), 94 | 'functions' => array('use_admin'), 95 | ); 96 | 97 | $ViewList['setwebhook'] = array( 98 | 'params' => array('id'), 99 | 'uparams' => array(), 100 | 'functions' => array('use_admin'), 101 | ); 102 | 103 | $ViewList['options'] = array( 104 | 'params' => array(), 105 | 'uparams' => array(), 106 | 'functions' => array('use_admin'), 107 | ); 108 | 109 | $ViewList['delete'] = array( 110 | 'params' => array('id'), 111 | 'uparams' => array('csfr'), 112 | 'functions' => array('use_admin'), 113 | ); 114 | 115 | $ViewList['leads'] = array( 116 | 'params' => array(), 117 | 'uparams' => array(), 118 | 'functions' => array('use_admin'), 119 | ); 120 | 121 | $FunctionList['use_admin'] = array('explain' => 'Allow operator to configure telegram bot'); -------------------------------------------------------------------------------- /modules/lhtelegram/new.php: -------------------------------------------------------------------------------- 1 | set('item',$item); 7 | 8 | if (ezcInputForm::hasPostData()) { 9 | 10 | $Errors = erLhcoreClassTelegramValidator::validateBot($item); 11 | 12 | if (count($Errors) == 0) { 13 | try { 14 | $item->saveThis(); 15 | 16 | erLhcoreClassModule::redirect('telegram/list'); 17 | exit ; 18 | 19 | } catch (Exception $e) { 20 | $tpl->set('errors',array($e->getMessage())); 21 | } 22 | 23 | } else { 24 | $tpl->set('errors',$Errors); 25 | } 26 | } 27 | 28 | $Result['content'] = $tpl->fetch(); 29 | $Result['path'] = array( 30 | array('url' =>erLhcoreClassDesign::baseurl('telegram/index'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger','Telegram')), 31 | array ( 32 | 'url' =>erLhcoreClassDesign::baseurl('telegram/list'), 33 | 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger','Telegram bots') 34 | ), 35 | array( 36 | 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger', 'New') 37 | ) 38 | ); 39 | 40 | ?> -------------------------------------------------------------------------------- /modules/lhtelegram/newoperator.php: -------------------------------------------------------------------------------- 1 | set('item',$item); 7 | 8 | if (ezcInputForm::hasPostData()) { 9 | 10 | $Errors = erLhcoreClassTelegramValidator::validateOperator($item); 11 | 12 | if (count($Errors) == 0) { 13 | try { 14 | $item->saveThis(); 15 | erLhcoreClassModule::redirect('telegram/operators'); 16 | exit ; 17 | 18 | } catch (Exception $e) { 19 | $tpl->set('errors',array($e->getMessage())); 20 | } 21 | 22 | } else { 23 | $tpl->set('errors',$Errors); 24 | } 25 | } 26 | 27 | $Result['content'] = $tpl->fetch(); 28 | $Result['path'] = array( 29 | array('url' =>erLhcoreClassDesign::baseurl('telegram/index'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger','Telegram')), 30 | array ( 31 | 'url' =>erLhcoreClassDesign::baseurl('telegram/operators'), 32 | 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger','Telegram operators') 33 | ), 34 | array( 35 | 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger', 'New') 36 | ) 37 | ); 38 | 39 | ?> -------------------------------------------------------------------------------- /modules/lhtelegram/newsignature.php: -------------------------------------------------------------------------------- 1 | set('item',$item); 7 | 8 | if (ezcInputForm::hasPostData()) { 9 | 10 | $Errors = erLhcoreClassTelegramValidator::validateSignatureGlobal($item); 11 | 12 | if (count($Errors) == 0) { 13 | try { 14 | $item->saveThis(); 15 | 16 | erLhcoreClassModule::redirect('telegram/signatures'); 17 | exit ; 18 | 19 | } catch (Exception $e) { 20 | $tpl->set('errors',array($e->getMessage())); 21 | } 22 | 23 | } else { 24 | $tpl->set('errors',$Errors); 25 | } 26 | } 27 | 28 | $Result['content'] = $tpl->fetch(); 29 | $Result['path'] = array( 30 | array('url' =>erLhcoreClassDesign::baseurl('telegram/index'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger','Telegram')), 31 | array ( 32 | 'url' =>erLhcoreClassDesign::baseurl('telegram/signatures'), 33 | 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger','Signatures') 34 | ), 35 | array( 36 | 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger', 'New') 37 | ) 38 | ); 39 | 40 | ?> -------------------------------------------------------------------------------- /modules/lhtelegram/operators.php: -------------------------------------------------------------------------------- 1 | 'extension/lhctelegram/classes/filter_operators.php','format_filter' => true, 'use_override' => true, 'uparams' => $Params['user_parameters_unordered'])); 7 | $filterParams['is_search'] = true; 8 | } else { 9 | $filterParams = erLhcoreClassSearchHandler::getParams(array('customfilterfile' => 'extension/lhctelegram/classes/filter_operators.php','format_filter' => true, 'uparams' => $Params['user_parameters_unordered'])); 10 | $filterParams['is_search'] = false; 11 | } 12 | 13 | $append = erLhcoreClassSearchHandler::getURLAppendFromInput($filterParams['input_form']); 14 | 15 | $pages = new lhPaginator(); 16 | $pages->items_total = erLhcoreClassModelTelegramOperator::getCount($filterParams['filter']); 17 | $pages->translationContext = 'chat/activechats'; 18 | $pages->serverURL = erLhcoreClassDesign::baseurl('telegram/operators').$append; 19 | $pages->paginate(); 20 | $tpl->set('pages',$pages); 21 | 22 | if ($pages->items_total > 0) { 23 | $items = erLhcoreClassModelTelegramOperator::getList(array_merge(array('limit' => $pages->items_per_page, 'offset' => $pages->low),$filterParams['filter'])); 24 | $tpl->set('items',$items); 25 | } 26 | 27 | $filterParams['input_form']->form_action = erLhcoreClassDesign::baseurl('telegram/operators'); 28 | $tpl->set('input',$filterParams['input_form']); 29 | $tpl->set('inputAppend',$append); 30 | 31 | $Result['content'] = $tpl->fetch(); 32 | 33 | $Result['path'] = array( 34 | array('url' =>erLhcoreClassDesign::baseurl('telegram/index'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger','Telegram')), 35 | array('url' =>erLhcoreClassDesign::baseurl('telegram/operators'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger','Telegram operators')) 36 | ); 37 | 38 | ?> -------------------------------------------------------------------------------- /modules/lhtelegram/options.php: -------------------------------------------------------------------------------- 1 | set('updated','done'); 8 | 9 | if (isset($_POST['StoreOptionsTelegram']) ) { 10 | LiveHelperChatExtension\lhctelegram\providers\TelegramLiveHelperChatActivator::installOrUpdate(); 11 | } 12 | 13 | if (isset($_POST['StoreOptionsTelegramRemove']) ) { 14 | LiveHelperChatExtension\lhctelegram\providers\TelegramLiveHelperChatActivator::remove(); 15 | } 16 | } 17 | 18 | $Result['content'] = $tpl->fetch(); 19 | 20 | $Result['path'] = array( 21 | array( 22 | 'url' => erLhcoreClassDesign::baseurl('telegram/index'), 23 | 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('lhelasticsearch/module', 'Telegram') 24 | ), 25 | array( 26 | 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('lhelasticsearch/module', 'Options') 27 | ) 28 | ); 29 | 30 | ?> -------------------------------------------------------------------------------- /modules/lhtelegram/setwebhook.php: -------------------------------------------------------------------------------- 1 | validateCSFRToken($_POST['csfr_token'])) { 10 | erLhcoreClassModule::redirect('telegram/list'); 11 | exit; 12 | } 13 | 14 | // Create Telegram API object 15 | $telegram = new Longman\TelegramBot\Telegram($item->bot_api, $item->bot_username); 16 | 17 | $locates = erConfigClassLhConfig::getInstance()->getSetting( 'site', 'available_site_access' ); 18 | 19 | if (isset($_POST['site_access']) && !empty($_POST['site_access']) && in_array($_POST['site_access'], $locates)) { 20 | $item->site_access = $_POST['site_access']; 21 | } 22 | 23 | // Set webhook 24 | $result = $telegram->setWebhook($item->callback_url,['allowed_updates' => ['message','callback_query','message_reaction','edited_message','inline_query']]); 25 | if ($result->isOk()) { 26 | $item->webhook_set = 1; 27 | $item->saveThis(); 28 | $tpl->set('msg', $result->getDescription()); 29 | $tpl->set('updated', true); 30 | } 31 | 32 | } catch (Longman\TelegramBot\Exception\TelegramException $e) { 33 | $tpl->set('errors', array($e->getMessage())); 34 | } 35 | $tpl->set('item', $item); 36 | $Result['content'] = $tpl->fetch(); 37 | 38 | $Result['path'] = array( 39 | array('url' =>erLhcoreClassDesign::baseurl('telegram/index'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger','Telegram')), 40 | array ( 41 | 'url' =>erLhcoreClassDesign::baseurl('telegram/list'), 42 | 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger','Telegram bots') 43 | ), 44 | array ( 45 | 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger', 'Set webhook') 46 | ) 47 | ); 48 | 49 | ?> -------------------------------------------------------------------------------- /modules/lhtelegram/signatures.php: -------------------------------------------------------------------------------- 1 | 'extension/lhctelegram/classes/filter.php','format_filter' => true, 'use_override' => true, 'uparams' => $Params['user_parameters_unordered'])); 7 | $filterParams['is_search'] = true; 8 | } else { 9 | $filterParams = erLhcoreClassSearchHandler::getParams(array('customfilterfile' => 'extension/lhctelegram/classes/filter.php','format_filter' => true, 'uparams' => $Params['user_parameters_unordered'])); 10 | $filterParams['is_search'] = false; 11 | } 12 | 13 | $append = erLhcoreClassSearchHandler::getURLAppendFromInput($filterParams['input_form']); 14 | 15 | $pages = new lhPaginator(); 16 | $pages->items_total = erLhcoreClassModelTelegramSignature::getCount($filterParams['filter']); 17 | $pages->translationContext = 'chat/activechats'; 18 | $pages->serverURL = erLhcoreClassDesign::baseurl('telegram/signatures').$append; 19 | $pages->paginate(); 20 | $tpl->set('pages',$pages); 21 | 22 | if ($pages->items_total > 0) { 23 | $items = erLhcoreClassModelTelegramSignature::getList(array_merge(array('limit' => $pages->items_per_page, 'offset' => $pages->low),$filterParams['filter'])); 24 | $tpl->set('items',$items); 25 | } 26 | 27 | $filterParams['input_form']->form_action = erLhcoreClassDesign::baseurl('telegram/signatures'); 28 | $tpl->set('input',$filterParams['input_form']); 29 | $tpl->set('inputAppend',$append); 30 | 31 | $Result['content'] = $tpl->fetch(); 32 | 33 | $Result['path'] = array( 34 | array('url' =>erLhcoreClassDesign::baseurl('telegram/index'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger','Telegram')), 35 | array('url' =>erLhcoreClassDesign::baseurl('telegram/signatures'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('module/fbmessenger','Signatures')) 36 | ); 37 | 38 | ?> -------------------------------------------------------------------------------- /pos/erlhcoreclassmodeltelegrambot.php: -------------------------------------------------------------------------------- 1 | table = "lhc_telegram_bot"; 5 | $def->class = "erLhcoreClassModelTelegramBot"; 6 | 7 | $def->idProperty = new ezcPersistentObjectIdProperty(); 8 | $def->idProperty->columnName = 'id'; 9 | $def->idProperty->propertyName = 'id'; 10 | $def->idProperty->generator = new ezcPersistentGeneratorDefinition( 'ezcPersistentNativeGenerator' ); 11 | 12 | foreach (['bot_username','bot_api'] as $posAttr) { 13 | $def->properties[$posAttr] = new ezcPersistentObjectProperty(); 14 | $def->properties[$posAttr]->columnName = $posAttr; 15 | $def->properties[$posAttr]->propertyName = $posAttr; 16 | $def->properties[$posAttr]->propertyType = ezcPersistentObjectProperty::PHP_TYPE_STRING; 17 | } 18 | 19 | foreach (['delete_on_close','group_chat_id','chat_timeout','bot_client','bot_disabled','dep_id','webhook_set','notify_page_change'] as $posAttr) { 20 | $def->properties[$posAttr] = new ezcPersistentObjectProperty(); 21 | $def->properties[$posAttr]->columnName = $posAttr; 22 | $def->properties[$posAttr]->propertyName = $posAttr; 23 | $def->properties[$posAttr]->propertyType = ezcPersistentObjectProperty::PHP_TYPE_INT; 24 | } 25 | 26 | return $def; 27 | 28 | ?> -------------------------------------------------------------------------------- /pos/erlhcoreclassmodeltelegrambotdep.php: -------------------------------------------------------------------------------- 1 | table = "lhc_telegram_bot_dep"; 5 | $def->class = "erLhcoreClassModelTelegramBotDep"; 6 | 7 | $def->idProperty = new ezcPersistentObjectIdProperty(); 8 | $def->idProperty->columnName = 'id'; 9 | $def->idProperty->propertyName = 'id'; 10 | $def->idProperty->generator = new ezcPersistentGeneratorDefinition( 'ezcPersistentNativeGenerator' ); 11 | 12 | $def->properties['bot_id'] = new ezcPersistentObjectProperty(); 13 | $def->properties['bot_id']->columnName = 'bot_id'; 14 | $def->properties['bot_id']->propertyName = 'bot_id'; 15 | $def->properties['bot_id']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_INT; 16 | 17 | $def->properties['dep_id'] = new ezcPersistentObjectProperty(); 18 | $def->properties['dep_id']->columnName = 'dep_id'; 19 | $def->properties['dep_id']->propertyName = 'dep_id'; 20 | $def->properties['dep_id']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_INT; 21 | 22 | return $def; 23 | 24 | ?> -------------------------------------------------------------------------------- /pos/erlhcoreclassmodeltelegramchat.php: -------------------------------------------------------------------------------- 1 | table = "lhc_telegram_chat"; 5 | $def->class = "erLhcoreClassModelTelegramChat"; 6 | 7 | $def->idProperty = new ezcPersistentObjectIdProperty(); 8 | $def->idProperty->columnName = 'id'; 9 | $def->idProperty->propertyName = 'id'; 10 | $def->idProperty->generator = new ezcPersistentGeneratorDefinition( 'ezcPersistentNativeGenerator' ); 11 | 12 | $def->properties['bot_id'] = new ezcPersistentObjectProperty(); 13 | $def->properties['bot_id']->columnName = 'bot_id'; 14 | $def->properties['bot_id']->propertyName = 'bot_id'; 15 | $def->properties['bot_id']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_INT; 16 | 17 | $def->properties['chat_id'] = new ezcPersistentObjectProperty(); 18 | $def->properties['chat_id']->columnName = 'chat_id'; 19 | $def->properties['chat_id']->propertyName = 'chat_id'; 20 | $def->properties['chat_id']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_INT; 21 | 22 | $def->properties['chat_id_internal'] = new ezcPersistentObjectProperty(); 23 | $def->properties['chat_id_internal']->columnName = 'chat_id_internal'; 24 | $def->properties['chat_id_internal']->propertyName = 'chat_id_internal'; 25 | $def->properties['chat_id_internal']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_INT; 26 | 27 | $def->properties['tchat_id'] = new ezcPersistentObjectProperty(); 28 | $def->properties['tchat_id']->columnName = 'tchat_id'; 29 | $def->properties['tchat_id']->propertyName = 'tchat_id'; 30 | $def->properties['tchat_id']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_INT; 31 | 32 | $def->properties['ctime'] = new ezcPersistentObjectProperty(); 33 | $def->properties['ctime']->columnName = 'ctime'; 34 | $def->properties['ctime']->propertyName = 'ctime'; 35 | $def->properties['ctime']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_INT; 36 | 37 | $def->properties['utime'] = new ezcPersistentObjectProperty(); 38 | $def->properties['utime']->columnName = 'utime'; 39 | $def->properties['utime']->propertyName = 'utime'; 40 | $def->properties['utime']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_INT; 41 | 42 | $def->properties['type'] = new ezcPersistentObjectProperty(); 43 | $def->properties['type']->columnName = 'type'; 44 | $def->properties['type']->propertyName = 'type'; 45 | $def->properties['type']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_INT; 46 | 47 | return $def; 48 | 49 | ?> -------------------------------------------------------------------------------- /pos/erlhcoreclassmodeltelegramlead.php: -------------------------------------------------------------------------------- 1 | table = "lhc_telegram_lead"; 5 | $def->class = "erLhcoreClassModelTelegramLead"; 6 | 7 | $def->idProperty = new ezcPersistentObjectIdProperty(); 8 | $def->idProperty->columnName = 'id'; 9 | $def->idProperty->propertyName = 'id'; 10 | $def->idProperty->generator = new ezcPersistentGeneratorDefinition( 'ezcPersistentNativeGenerator' ); 11 | 12 | $def->properties['dep_id'] = new ezcPersistentObjectProperty(); 13 | $def->properties['dep_id']->columnName = 'dep_id'; 14 | $def->properties['dep_id']->propertyName = 'dep_id'; 15 | $def->properties['dep_id']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_INT; 16 | 17 | $def->properties['tchat_id'] = new ezcPersistentObjectProperty(); 18 | $def->properties['tchat_id']->columnName = 'tchat_id'; 19 | $def->properties['tchat_id']->propertyName = 'tchat_id'; 20 | $def->properties['tchat_id']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_INT; 21 | 22 | $def->properties['tbot_id'] = new ezcPersistentObjectProperty(); 23 | $def->properties['tbot_id']->columnName = 'tbot_id'; 24 | $def->properties['tbot_id']->propertyName = 'tbot_id'; 25 | $def->properties['tbot_id']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_INT; 26 | 27 | $def->properties['ctime'] = new ezcPersistentObjectProperty(); 28 | $def->properties['ctime']->columnName = 'ctime'; 29 | $def->properties['ctime']->propertyName = 'ctime'; 30 | $def->properties['ctime']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_INT; 31 | 32 | $def->properties['utime'] = new ezcPersistentObjectProperty(); 33 | $def->properties['utime']->columnName = 'utime'; 34 | $def->properties['utime']->propertyName = 'utime'; 35 | $def->properties['utime']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_INT; 36 | 37 | $def->properties['utime'] = new ezcPersistentObjectProperty(); 38 | $def->properties['utime']->columnName = 'utime'; 39 | $def->properties['utime']->propertyName = 'utime'; 40 | $def->properties['utime']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_INT; 41 | 42 | $def->properties['first_name'] = new ezcPersistentObjectProperty(); 43 | $def->properties['first_name']->columnName = 'first_name'; 44 | $def->properties['first_name']->propertyName = 'first_name'; 45 | $def->properties['first_name']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_STRING; 46 | 47 | $def->properties['last_name'] = new ezcPersistentObjectProperty(); 48 | $def->properties['last_name']->columnName = 'last_name'; 49 | $def->properties['last_name']->propertyName = 'last_name'; 50 | $def->properties['last_name']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_STRING; 51 | 52 | $def->properties['username'] = new ezcPersistentObjectProperty(); 53 | $def->properties['username']->columnName = 'username'; 54 | $def->properties['username']->propertyName = 'username'; 55 | $def->properties['username']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_STRING; 56 | 57 | $def->properties['language_code'] = new ezcPersistentObjectProperty(); 58 | $def->properties['language_code']->columnName = 'language_code'; 59 | $def->properties['language_code']->propertyName = 'language_code'; 60 | $def->properties['language_code']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_STRING; 61 | 62 | return $def; 63 | 64 | ?> -------------------------------------------------------------------------------- /pos/erlhcoreclassmodeltelegramoperator.php: -------------------------------------------------------------------------------- 1 | table = "lhc_telegram_operator"; 5 | $def->class = "erLhcoreClassModelTelegramOperator"; 6 | 7 | $def->idProperty = new ezcPersistentObjectIdProperty(); 8 | $def->idProperty->columnName = 'id'; 9 | $def->idProperty->propertyName = 'id'; 10 | $def->idProperty->generator = new ezcPersistentGeneratorDefinition( 'ezcPersistentNativeGenerator' ); 11 | 12 | $def->properties['bot_id'] = new ezcPersistentObjectProperty(); 13 | $def->properties['bot_id']->columnName = 'bot_id'; 14 | $def->properties['bot_id']->propertyName = 'bot_id'; 15 | $def->properties['bot_id']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_INT; 16 | 17 | $def->properties['tchat_id'] = new ezcPersistentObjectProperty(); 18 | $def->properties['tchat_id']->columnName = 'tchat_id'; 19 | $def->properties['tchat_id']->propertyName = 'tchat_id'; 20 | $def->properties['tchat_id']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_INT; 21 | 22 | $def->properties['tuser_id'] = new ezcPersistentObjectProperty(); 23 | $def->properties['tuser_id']->columnName = 'tuser_id'; 24 | $def->properties['tuser_id']->propertyName = 'tuser_id'; 25 | $def->properties['tuser_id']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_INT; 26 | 27 | $def->properties['user_id'] = new ezcPersistentObjectProperty(); 28 | $def->properties['user_id']->columnName = 'user_id'; 29 | $def->properties['user_id']->propertyName = 'user_id'; 30 | $def->properties['user_id']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_INT; 31 | 32 | // Current chat id operator is chatting 33 | $def->properties['chat_id'] = new ezcPersistentObjectProperty(); 34 | $def->properties['chat_id']->columnName = 'chat_id'; 35 | $def->properties['chat_id']->propertyName = 'chat_id'; 36 | $def->properties['chat_id']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_INT; 37 | 38 | $def->properties['confirmed'] = new ezcPersistentObjectProperty(); 39 | $def->properties['confirmed']->columnName = 'confirmed'; 40 | $def->properties['confirmed']->propertyName = 'confirmed'; 41 | $def->properties['confirmed']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_INT; 42 | 43 | return $def; 44 | 45 | ?> -------------------------------------------------------------------------------- /pos/erlhcoreclassmodeltelegramsignature.php: -------------------------------------------------------------------------------- 1 | table = "lhc_telegram_signature"; 5 | $def->class = "erLhcoreClassModelTelegramSignature"; 6 | 7 | $def->idProperty = new ezcPersistentObjectIdProperty(); 8 | $def->idProperty->columnName = 'id'; 9 | $def->idProperty->propertyName = 'id'; 10 | $def->idProperty->generator = new ezcPersistentGeneratorDefinition( 'ezcPersistentNativeGenerator' ); 11 | 12 | $def->properties['bot_id'] = new ezcPersistentObjectProperty(); 13 | $def->properties['bot_id']->columnName = 'bot_id'; 14 | $def->properties['bot_id']->propertyName = 'bot_id'; 15 | $def->properties['bot_id']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_INT; 16 | 17 | $def->properties['user_id'] = new ezcPersistentObjectProperty(); 18 | $def->properties['user_id']->columnName = 'user_id'; 19 | $def->properties['user_id']->propertyName = 'user_id'; 20 | $def->properties['user_id']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_INT; 21 | 22 | $def->properties['signature'] = new ezcPersistentObjectProperty(); 23 | $def->properties['signature']->columnName = 'signature'; 24 | $def->properties['signature']->propertyName = 'signature'; 25 | $def->properties['signature']->propertyType = ezcPersistentObjectProperty::PHP_TYPE_STRING; 26 | 27 | return $def; 28 | 29 | ?> -------------------------------------------------------------------------------- /providers/TelegramLiveHelperChatActivator.php: -------------------------------------------------------------------------------- 1 | ['name' => 'TelegramIntegration']])) { 10 | $incomingWebhook->removeThis(); 11 | } 12 | 13 | if ($restAPI = \erLhcoreClassModelGenericBotRestAPI::findOne(['filter' => ['name' => 'TelegramIntegration']])) { 14 | $restAPI->removeThis(); 15 | } 16 | 17 | if ($botPrevious = \erLhcoreClassModelGenericBotBot::findOne(['filter' => ['name' => 'TelegramIntegration']])) { 18 | $botPrevious->removeThis(); 19 | 20 | if ($event = \erLhcoreClassModelChatWebhook::findOne(['filter' => ['event' => ['chat.desktop_client_admin_msg', 'bot_id' => $botPrevious->id]]])) { 21 | $event->removeThis(); 22 | } 23 | 24 | if ($event = \erLhcoreClassModelChatWebhook::findOne(['filter' => ['event' => ['chat.workflow.canned_message_before_save', 'bot_id' => $botPrevious->id]]])) { 25 | $event->removeThis(); 26 | } 27 | 28 | if ($event = \erLhcoreClassModelChatWebhook::findOne(['filter' => ['event' => ['chat.web_add_msg_admin', 'bot_id' => $botPrevious->id]]])) { 29 | $event->removeThis(); 30 | } 31 | 32 | if ($event = \erLhcoreClassModelChatWebhook::findOne(['filter' => ['event' => ['chat.before_auto_responder_msg_saved', 'bot_id' => $botPrevious->id]]])) { 33 | $event->removeThis(); 34 | } 35 | } 36 | } 37 | 38 | public static function installOrUpdate() 39 | { 40 | $incomingWebhook = \erLhcoreClassModelChatIncomingWebhook::findOne(['filter' => ['name' => 'TelegramIntegration']]); 41 | 42 | $incomingWebhookContent = file_get_contents('extension/lhctelegram/doc/telegram/incoming-webhook.json'); 43 | $content = json_decode($incomingWebhookContent,true); 44 | 45 | if (!$incomingWebhook) { 46 | $incomingWebhook = new \erLhcoreClassModelChatIncomingWebhook(); 47 | $incomingWebhook->setState($content); 48 | $incomingWebhook->dep_id = 1; 49 | $incomingWebhook->name = 'TelegramIntegration'; 50 | $incomingWebhook->identifier = \erLhcoreClassModelForgotPassword::randomPassword(20); 51 | } else { 52 | $dep_id = $incomingWebhook->dep_id; 53 | $identifier = $incomingWebhook->identifier; 54 | $incomingWebhook->setState($content); 55 | $incomingWebhook->dep_id = $dep_id; 56 | $incomingWebhook->identifier = $identifier; 57 | $incomingWebhook->name = 'TelegramIntegration'; 58 | } 59 | $incomingWebhook->saveThis(); 60 | 61 | // RestAPI 62 | $restAPI = \erLhcoreClassModelGenericBotRestAPI::findOne(['filter' => ['name' => 'TelegramIntegration']]); 63 | $content = json_decode(file_get_contents('extension/lhctelegram/doc/telegram/rest-api.json'),true); 64 | 65 | if (!$restAPI) { 66 | $restAPI = new \erLhcoreClassModelGenericBotRestAPI(); 67 | } 68 | 69 | $restAPI->setState($content); 70 | $restAPI->name = 'TelegramIntegration'; 71 | $restAPI->saveThis(); 72 | 73 | if ($botPrevious = \erLhcoreClassModelGenericBotBot::findOne(['filter' => ['name' => 'TelegramIntegration']])) { 74 | $botPrevious->removeThis(); 75 | } 76 | 77 | $botData = \erLhcoreClassGenericBotValidator::importBot(json_decode(file_get_contents('extension/lhctelegram/doc/telegram/bot-data.json'),true)); 78 | $botData['bot']->name = 'TelegramIntegration'; 79 | $botData['bot']->updateThis(['update' => ['name']]); 80 | 81 | $trigger = $botData['triggers'][0]; 82 | $actions = $trigger->actions_front; 83 | $actions[0]['content']['rest_api'] = $restAPI->id; 84 | $trigger->actions_front = $actions; 85 | $trigger->actions = json_encode($actions); 86 | $trigger->updateThis(['update' => ['actions']]); 87 | 88 | if ($botPrevious && $event = \erLhcoreClassModelChatWebhook::findOne(['filter' => ['event' => ['chat.desktop_client_admin_msg', 'bot_id' => $botPrevious->id]]])) { 89 | $event->removeThis(); 90 | } 91 | $event = new \erLhcoreClassModelChatWebhook(); 92 | $event->setState(json_decode(file_get_contents('extension/lhctelegram/doc/telegram/chat.desktop_client_admin_msg.json'),true)); 93 | $event->bot_id = $botData['bot']->id; 94 | $event->trigger_id = $trigger->id; 95 | $event->saveThis(); 96 | 97 | if ($botPrevious && $event = \erLhcoreClassModelChatWebhook::findOne(['filter' => ['event' => ['chat.workflow.canned_message_before_save', 'bot_id' => $botPrevious->id]]])) { 98 | $event->removeThis(); 99 | } 100 | $event = new \erLhcoreClassModelChatWebhook(); 101 | $event->setState(json_decode(file_get_contents('extension/lhctelegram/doc/telegram/chat.workflow.canned_message_before_save.json'),true)); 102 | $event->bot_id = $botData['bot']->id; 103 | $event->trigger_id = $trigger->id; 104 | $event->saveThis(); 105 | 106 | if ($botPrevious && $event = \erLhcoreClassModelChatWebhook::findOne(['filter' => ['event' => ['chat.web_add_msg_admin', 'bot_id' => $botPrevious->id]]])) { 107 | $event->removeThis(); 108 | } 109 | $event = new \erLhcoreClassModelChatWebhook(); 110 | $event->setState(json_decode(file_get_contents('extension/lhctelegram/doc/telegram/chat.web_add_msg_admin.json'),true)); 111 | $event->bot_id = $botData['bot']->id; 112 | $event->trigger_id = $trigger->id; 113 | $event->saveThis(); 114 | 115 | if ($botPrevious && $event = \erLhcoreClassModelChatWebhook::findOne(['filter' => ['event' => ['chat.before_auto_responder_msg_saved', 'bot_id' => $botPrevious->id]]])) { 116 | $event->removeThis(); 117 | } 118 | $event = new \erLhcoreClassModelChatWebhook(); 119 | $event->setState(json_decode(file_get_contents('extension/lhctelegram/doc/telegram/chat.before_auto_responder_msg_saved.json'),true)); 120 | $event->bot_id = $botData['bot']->id; 121 | $event->trigger_id = $trigger->id; 122 | $event->saveThis(); 123 | } 124 | } 125 | 126 | ?> -------------------------------------------------------------------------------- /settings/settings.ini.default.php: -------------------------------------------------------------------------------- 1 | false, 5 | 'convert_to' => 'wav', 6 | 'convert_command' => 'avconv -i {file_orig} {file_dest}', 7 | 'elastic_search' => array( 8 | 'search_attr' => 'attr_int_1' 9 | ) 10 | ); 11 | 12 | ?> --------------------------------------------------------------------------------