diff --git a/bootstrap/bootstrap.php b/bootstrap/bootstrap.php index a8194ad..70a0be8 100644 --- a/bootstrap/bootstrap.php +++ b/bootstrap/bootstrap.php @@ -441,7 +441,67 @@ private function isMeaningfulTelegramUploadName($file) return true; } - private function sendTelegramChatFile($tchat, $fileData, $caption, $disableNotification = false) + public function saveTopicMsgId($msg, $topicMsgId) + { + if (!($msg instanceof erLhcoreClassModelmsg) || !(int)$topicMsgId || $msg->id <= 0) { + return; + } + + $meta = is_array($msg->meta_msg_array) ? $msg->meta_msg_array : []; + $meta['tg_topic_msg_id'] = (int)$topicMsgId; + $msg->meta_msg_array = $meta; + $msg->meta_msg = json_encode($meta); + + $stmt = ezcDbInstance::get()->prepare("UPDATE lh_msg SET meta_msg = :meta_msg WHERE id = :id"); + $stmt->bindValue(':meta_msg', $msg->meta_msg); + $stmt->bindValue(':id', (int)$msg->id, PDO::PARAM_INT); + $stmt->execute(); + } + + public function getTopicReplyId($msg, $chatId) + { + if (!($msg instanceof erLhcoreClassModelmsg)) { + return null; + } + + $meta = $msg->meta_msg_array; + + if (isset($meta['content']['reply_to']['db_msg_id']) && (int)$meta['content']['reply_to']['db_msg_id'] > 0) { + $targetMsg = erLhcoreClassModelmsg::fetch((int)$meta['content']['reply_to']['db_msg_id']); + if ($targetMsg instanceof erLhcoreClassModelmsg && isset($targetMsg->meta_msg_array['tg_topic_msg_id']) && (int)$targetMsg->meta_msg_array['tg_topic_msg_id'] > 0) { + return (int)$targetMsg->meta_msg_array['tg_topic_msg_id']; + } + } + + if (isset($meta['content']['reply_to']['iwh_msg_id']) && $meta['content']['reply_to']['iwh_msg_id'] != '') { + $iwhId = (string)$meta['content']['reply_to']['iwh_msg_id']; + $targetMsg = erLhcoreClassModelmsg::findOne([ + 'filter' => ['chat_id' => $chatId], + 'customfilter' => ['`meta_msg` != \'\' AND JSON_VALID(`meta_msg`) AND (JSON_UNQUOTE(JSON_EXTRACT(meta_msg,\'$.iwh_msg_id\')) = ' . ezcDbInstance::get()->quote($iwhId) . ' OR JSON_EXTRACT(meta_msg,\'$.iwh_msg_id\') = ' . (is_numeric($iwhId) ? (int)$iwhId : ezcDbInstance::get()->quote($iwhId)) . ')'] + ]); + if ($targetMsg instanceof erLhcoreClassModelmsg && isset($targetMsg->meta_msg_array['tg_topic_msg_id']) && (int)$targetMsg->meta_msg_array['tg_topic_msg_id'] > 0) { + return (int)$targetMsg->meta_msg_array['tg_topic_msg_id']; + } + } + + if (isset($meta['content']['quote']['id']) && (int)$meta['content']['quote']['id'] > 0) { + $targetMsg = erLhcoreClassModelmsg::fetch((int)$meta['content']['quote']['id']); + if ($targetMsg instanceof erLhcoreClassModelmsg && isset($targetMsg->meta_msg_array['tg_topic_msg_id']) && (int)$targetMsg->meta_msg_array['tg_topic_msg_id'] > 0) { + return (int)$targetMsg->meta_msg_array['tg_topic_msg_id']; + } + } + + if (preg_match('#\[quote="?([0-9]+)"?\]#is', (string)$msg->msg, $m)) { + $targetMsg = erLhcoreClassModelmsg::fetch((int)$m[1]); + if ($targetMsg instanceof erLhcoreClassModelmsg && isset($targetMsg->meta_msg_array['tg_topic_msg_id']) && (int)$targetMsg->meta_msg_array['tg_topic_msg_id'] > 0) { + return (int)$targetMsg->meta_msg_array['tg_topic_msg_id']; + } + } + + return null; + } + + private function sendTelegramChatFile($tchat, $fileData, $caption, $disableNotification = false, $params = array()) { $file = $fileData['file']; @@ -475,6 +535,10 @@ private function sendTelegramChatFile($tchat, $fileData, $caption, $disableNotif $field => $this->getTelegramChatFileUrl($file) ); + if (isset($params['reply_to_message_id']) && $params['reply_to_message_id'] > 0) { + $data['reply_to_message_id'] = $params['reply_to_message_id']; + } + if ($caption !== '') { $data['caption'] = $caption; } @@ -515,7 +579,7 @@ private function sendTelegramChatFile($tchat, $fileData, $caption, $disableNotif return false; } - return true; + return $sendData->getResult()->getMessageId(); } private function getTelegramChatFileUrl($file) @@ -580,8 +644,17 @@ public function messageAdded($params) $data['disable_notification'] = true; } + $replyTopicMsgId = $this->getTopicReplyId($params['msg'], $chat->id); + if ($replyTopicMsgId > 0) { + $data['reply_to_message_id'] = $replyTopicMsgId; + } + $sendData = Longman\TelegramBot\Request::sendMessage($data); + if ($sendData->isOk()) { + $this->saveTopicMsgId($params['msg'], $sendData->getResult()->getMessageId()); + } + if (!$sendData->isOk() && $sendData->getErrorCode() == 400 && str_contains( $sendData->getDescription(), 'TOPIC_DELETED') === true) { // Reset telegram chat $tchat->tchat_id = 0; @@ -610,9 +683,13 @@ public function messageAdded($params) $failedEmbedCodes = array(); $fileIndex = 0; + $replyTopicMsgId = $this->getTopicReplyId($params['msg'], $chat->id); foreach ($telegramFiles as $telegramFile) { - if ($this->sendTelegramChatFile($tchat, $telegramFile, $this->getTelegramFileCaption($params['msg'], $chat, $telegramFile['file'], $fileIndex === 0 ? $messageText : ''), $chat->status == erLhcoreClassModelChat::STATUS_BOT_CHAT) === false) { + $sentFileMsgId = $this->sendTelegramChatFile($tchat, $telegramFile, $this->getTelegramFileCaption($params['msg'], $chat, $telegramFile['file'], $fileIndex === 0 ? $messageText : ''), $chat->status == erLhcoreClassModelChat::STATUS_BOT_CHAT, ['reply_to_message_id' => $replyTopicMsgId]); + if ($sentFileMsgId === false) { $failedEmbedCodes[] = $telegramFile['embed']; + } else { + $this->saveTopicMsgId($params['msg'], $sentFileMsgId); } $fileIndex++; } @@ -671,7 +748,9 @@ public function messageAdded($params) } $sendData = Longman\TelegramBot\Request::sendMessage($data); - if (!$sendData->isOk()) { + if ($sendData->isOk()) { + $this->saveTopicMsgId($botMessage, $sendData->getResult()->getMessageId()); + } else { erLhcoreClassLog::write('SendMessage BOT ['.$sendData->getErrorCode().']'. $sendData->getDescription(), ezcLog::SUCCESS_AUDIT, array( @@ -690,8 +769,11 @@ public function messageAdded($params) $fileIndex = 0; foreach ($telegramFiles as $telegramFile) { - if ($this->sendTelegramChatFile($tchat, $telegramFile, $this->getTelegramFileCaption($botMessage, $chat, $telegramFile['file'], $fileIndex === 0 ? $messageText : ''), $chat->status == erLhcoreClassModelChat::STATUS_BOT_CHAT) === false) { + $sentFileMsgId = $this->sendTelegramChatFile($tchat, $telegramFile, $this->getTelegramFileCaption($botMessage, $chat, $telegramFile['file'], $fileIndex === 0 ? $messageText : ''), $chat->status == erLhcoreClassModelChat::STATUS_BOT_CHAT); + if ($sentFileMsgId === false) { $failedEmbedCodes[] = $telegramFile['embed']; + } else { + $this->saveTopicMsgId($botMessage, $sentFileMsgId); } $fileIndex++; } @@ -767,7 +849,9 @@ public function triggerClicked($params) } $sendData = Longman\TelegramBot\Request::sendMessage($data); - if (!$sendData->isOk()) { + if ($sendData->isOk()) { + $this->saveTopicMsgId($botMessage, $sendData->getResult()->getMessageId()); + } else { erLhcoreClassLog::write('['.$sendData->getErrorCode().']'. $sendData->getDescription(), ezcLog::SUCCESS_AUDIT, array( @@ -786,8 +870,11 @@ public function triggerClicked($params) $fileIndex = 0; foreach ($telegramFiles as $telegramFile) { - if ($this->sendTelegramChatFile($tchat, $telegramFile, $this->getTelegramFileCaption($botMessage, $chat, $telegramFile['file'], $fileIndex === 0 ? $messageText : ''), $chat->status == erLhcoreClassModelChat::STATUS_BOT_CHAT) === false) { + $sentFileMsgId = $this->sendTelegramChatFile($tchat, $telegramFile, $this->getTelegramFileCaption($botMessage, $chat, $telegramFile['file'], $fileIndex === 0 ? $messageText : ''), $chat->status == erLhcoreClassModelChat::STATUS_BOT_CHAT); + if ($sentFileMsgId === false) { $failedEmbedCodes[] = $telegramFile['embed']; + } else { + $this->saveTopicMsgId($botMessage, $sentFileMsgId); } $fileIndex++; } @@ -926,7 +1013,17 @@ public function chatStarted($params) $sendData = Longman\TelegramBot\Request::sendMessage($data); - if (!$sendData->isOk()) { + if ($sendData->isOk()) { + $firstVisitorMsg = erLhcoreClassModelmsg::findOne(['filter' => ['chat_id' => $params['chat']->id, 'user_id' => 0], 'sort' => 'id ASC']); + if ($firstVisitorMsg instanceof erLhcoreClassModelmsg) { + $this->saveTopicMsgId($firstVisitorMsg, $sendData->getResult()->getMessageId()); + } else { + $firstMsg = erLhcoreClassModelmsg::findOne(['filter' => ['chat_id' => $params['chat']->id], 'sort' => 'id ASC']); + if ($firstMsg instanceof erLhcoreClassModelmsg) { + $this->saveTopicMsgId($firstMsg, $sendData->getResult()->getMessageId()); + } + } + } else { // Try first time to create a topic if old one is gone if ($sendData->getErrorCode() == 400 && (str_contains($sendData->getDescription(), 'message thread not found') || str_contains($sendData->getDescription(), 'TOPIC_DELETED'))) { @@ -946,7 +1043,17 @@ public function chatStarted($params) $data['message_thread_id'] = $tChat->tchat_id; $sendData = Longman\TelegramBot\Request::sendMessage($data); - if (!$sendData->isOk()) { + if ($sendData->isOk()) { + $firstVisitorMsg = erLhcoreClassModelmsg::findOne(['filter' => ['chat_id' => $params['chat']->id, 'user_id' => 0], 'sort' => 'id ASC']); + if ($firstVisitorMsg instanceof erLhcoreClassModelmsg) { + $this->saveTopicMsgId($firstVisitorMsg, $sendData->getResult()->getMessageId()); + } else { + $firstMsg = erLhcoreClassModelmsg::findOne(['filter' => ['chat_id' => $params['chat']->id], 'sort' => 'id ASC']); + if ($firstMsg instanceof erLhcoreClassModelmsg) { + $this->saveTopicMsgId($firstMsg, $sendData->getResult()->getMessageId()); + } + } + } else { erLhcoreClassLog::write('['.$sendData->getErrorCode().']'. $sendData->getDescription(), ezcLog::SUCCESS_AUDIT, array( @@ -964,8 +1071,11 @@ public function chatStarted($params) $failedEmbedCodes = array(); foreach ($initialTelegramFiles as $initialTelegramFile) { - if ($this->sendTelegramChatFile($tChat, $initialTelegramFile['file'], $this->getTelegramFileCaption($initialTelegramFile['msg'], $params['chat'], $initialTelegramFile['file']['file'], $initialTelegramFile['text']), $params['chat']->status == erLhcoreClassModelChat::STATUS_BOT_CHAT) === false) { + $sentFileMsgId = $this->sendTelegramChatFile($tChat, $initialTelegramFile['file'], $this->getTelegramFileCaption($initialTelegramFile['msg'], $params['chat'], $initialTelegramFile['file']['file'], $initialTelegramFile['text']), $params['chat']->status == erLhcoreClassModelChat::STATUS_BOT_CHAT); + if ($sentFileMsgId === false) { $failedEmbedCodes[] = $initialTelegramFile['file']['embed']; + } else if (isset($initialTelegramFile['msg']) && $initialTelegramFile['msg'] instanceof erLhcoreClassModelmsg) { + $this->saveTopicMsgId($initialTelegramFile['msg'], $sentFileMsgId); } } diff --git a/classes/Commands/GenericmessageCommand.php b/classes/Commands/GenericmessageCommand.php index c80c493..d303a19 100644 --- a/classes/Commands/GenericmessageCommand.php +++ b/classes/Commands/GenericmessageCommand.php @@ -341,7 +341,50 @@ public function execute(): ServerResponse if ($ignoreMessage == false) { $msg = new \erLhcoreClassModelmsg(); - $msg->msg = $text; + $msgText = $text; + $metaMsg = []; + + $replyTo = $message->getReplyToMessage(); + $isExplicitReply = ($replyTo && (int)$replyTo->getMessageId() !== (int)$message->getMessageThreadId() && !$replyTo->getForumTopicCreated()); + + if ($isExplicitReply) { + $replyTopicMsgId = (int)$replyTo->getMessageId(); + $metaMsg['tg_topic_msg_id'] = (int)$message->getMessageId(); + + $replyMsg = \erLhcoreClassModelmsg::findOne([ + 'filter' => ['chat_id' => $chat->id], + 'customfilter' => ['`meta_msg` != \'\' AND JSON_VALID(`meta_msg`) AND JSON_EXTRACT(meta_msg, \'$.tg_topic_msg_id\') = ' . $replyTopicMsgId] + ]); + + if ($replyMsg instanceof \erLhcoreClassModelmsg) { + $quoteText = $message->getQuote() ? trim($message->getQuote()->getText()) : $replyMsg->msg; + $replyNick = $replyMsg->name_support != '' ? $replyMsg->name_support : $chat->nick; + $msgText = '[quote=' . $replyMsg->id . ']' . $quoteText . '[/quote]' . $msgText; + + $metaMsg['content'] = [ + 'quote' => [ + 'id' => $replyMsg->id, + 'text' => $quoteText, + 'nick' => $replyNick + ], + 'reply_to' => [ + 'db_msg_id' => $replyMsg->id + ] + ]; + + if (isset($replyMsg->meta_msg_array['iwh_msg_id']) && $replyMsg->meta_msg_array['iwh_msg_id'] != '') { + $metaMsg['content']['reply_to']['iwh_msg_id'] = $replyMsg->meta_msg_array['iwh_msg_id']; + } + } + } else { + $metaMsg['tg_topic_msg_id'] = (int)$message->getMessageId(); + } + + $msg->msg = $msgText; + if (!empty($metaMsg)) { + $msg->meta_msg = json_encode($metaMsg); + $msg->meta_msg_array = $metaMsg; + } $msg->chat_id = $chat->id; $msg->user_id = $messageUserId; $msg->time = time(); diff --git a/doc/telegram/incoming-webhook.json b/doc/telegram/incoming-webhook.json index 9399c29..91df02f 100644 --- a/doc/telegram/incoming-webhook.json +++ b/doc/telegram/incoming-webhook.json @@ -1 +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} \ No newline at end of file +{"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\", \"message_id_reply\": \"message.reply_to_message.message_id\"}", "icon": "social/telegram-ico.png", "icon_color": "", "log_incoming": 0, "log_failed_parse": 0} \ No newline at end of file diff --git a/doc/telegram/rest-api.json b/doc/telegram/rest-api.json index b03eaaf..898ed3e 100644 --- a/doc/telegram/rest-api.json +++ b/doc/telegram/rest-api.json @@ -1 +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{api_by_ext__ogg},\\\"caption\\\":{{msg_clean}}{/api_by_ext}{api_by_ext__mp3_m4a},\\\"caption\\\":{{msg_clean}}{/api_by_ext}{api_by_ext__mp4},\\\"caption\\\":{{msg_clean}}{/api_by_ext}{file_api},\\\"caption\\\":{{msg_clean}}{/file_api}{image_api},\\\"caption\\\":{{msg_clean}}{/image_api}\\n}\",\"check_not_empty\":\"{{msg_html_nobr}}\",\"suburl_file_convert\":\"tgs,file_api,mp3_m4a,ogg\",\"suburl_file_skip_ext\":\"tgs\"},{\"method\":\"POST\",\"authorization\":\"\",\"api_key_location\":\"header\",\"query\":[],\"header\":[],\"conditions\":[],\"postparams\":[],\"userparams\":[],\"output\":[{\"key\":\"\",\"value\":\"\",\"id\":\"telegram_typing_success\",\"success_name\":\"Success\",\"success_header\":\"200\"}],\"id\":\"telegram_send_typing\",\"name\":\"Send typing\",\"suburl\":\"/bot{{args.chat.incoming_chat.incoming_dynamic_array.access_token}}/sendChatAction\",\"body_request_type\":\"raw\",\"body_request_type_content\":\"json\",\"body_raw\":\"{\\n \\\"chat_id\\\": {{args.chat.incoming_chat.chat_external_id}},\\n \\\"action\\\": \\\"typing\\\"\\n}\",\"check_not_empty\":\"{{args.chat.incoming_chat.chat_external_id}}\"}]}"} \ No newline at end of file +{"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{reply_to},\\\"reply_parameters\\\":{\\\"message_id\\\":raw_{{iwh_msg_id}}}{/reply_to}\\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{reply_to},\\\"reply_parameters\\\":\\\"{\\\\\\\"message_id\\\\\\\":raw_{{iwh_msg_id}}}\\\"{/reply_to}\\n{api_by_ext__ogg},\\\"caption\\\":{{msg_clean}}{/api_by_ext}{api_by_ext__mp3_m4a},\\\"caption\\\":{{msg_clean}}{/api_by_ext}{api_by_ext__mp4},\\\"caption\\\":{{msg_clean}}{/api_by_ext}{file_api},\\\"caption\\\":{{msg_clean}}{/file_api}{image_api},\\\"caption\\\":{{msg_clean}}{/image_api}\\n}\", \"check_not_empty\": \"{{msg_html_nobr}}\", \"suburl_file_convert\": \"tgs,file_api,mp3_m4a,ogg\", \"suburl_file_skip_ext\": \"tgs\"}, {\"method\": \"POST\", \"authorization\": \"\", \"api_key_location\": \"header\", \"query\": [], \"header\": [], \"conditions\": [], \"postparams\": [], \"userparams\": [], \"output\": [{\"key\": \"\", \"value\": \"\", \"id\": \"telegram_typing_success\", \"success_name\": \"Success\", \"success_header\": \"200\"}], \"id\": \"telegram_send_typing\", \"name\": \"Send typing\", \"suburl\": \"/bot{{args.chat.incoming_chat.incoming_dynamic_array.access_token}}/sendChatAction\", \"body_request_type\": \"raw\", \"body_request_type_content\": \"json\", \"body_raw\": \"{\\n \\\"chat_id\\\": {{args.chat.incoming_chat.chat_external_id}},\\n \\\"action\\\": \\\"typing\\\"\\n}\", \"check_not_empty\": \"{{args.chat.incoming_chat.chat_external_id}}\"}]}"} \ No newline at end of file