Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions classes/Commands/GenericmessageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,29 @@ private function processVoice($fileId, $chat, $tBot) {
}
}

private function appendCaptionToFileEmbed($message, $fileEmbed)
{
$caption = '';

if (method_exists($message, 'getProperty')) {
$caption = trim((string)$message->getProperty('caption', ''));
}

if ($caption === '' && isset($message->raw_data) && is_array($message->raw_data) && isset($message->raw_data['caption'])) {
$caption = trim((string)$message->raw_data['caption']);
}

if ($caption === '') {
$caption = trim((string)$message->getCaption());
}

if ($caption !== '' && trim((string)$fileEmbed) !== '') {
return $caption . ' ' . $fileEmbed;
}

return $fileEmbed;
}

/**
* Command execute method
*
Expand Down Expand Up @@ -210,19 +233,19 @@ public function execute(): ServerResponse
if ($chat instanceof \erLhcoreClassModelChat) {

if ($type === 'photo') {
$text = $this->processPhoto($chat, $message, $tBot);
$text = $this->appendCaptionToFileEmbed($message, $this->processPhoto($chat, $message, $tBot));
} elseif ($type === 'document') {
$text = $this->processObject($message->getDocument()->getFileId(), $chat, $tBot);
$text = $this->appendCaptionToFileEmbed($message, $this->processObject($message->getDocument()->getFileId(), $chat, $tBot));
} elseif ($type === 'video') {
$text = $this->processObject($message->getVideo()->getFileId(), $chat, $tBot, array('ext' => 'mp4'));
$text = $this->appendCaptionToFileEmbed($message, $this->processObject($message->getVideo()->getFileId(), $chat, $tBot, array('ext' => 'mp4')));
} elseif ($message->getVideoNote()) {
$text = $this->processObject($message->getVideoNote()->getFileId(), $chat, $tBot, array('ext' => 'mp4'));
} elseif ($type === 'voice') {
$text = $this->processVoice($message->getVoice()->getFileId(), $chat, $tBot);
$text = $this->appendCaptionToFileEmbed($message, $this->processVoice($message->getVoice()->getFileId(), $chat, $tBot));
} elseif ($type === 'sticker') {
$text = $this->processObject($message->getSticker()->getFileId(), $chat, $tBot, array('ext' => 'webp'));
} elseif ($type === 'audio') {
$text = $this->processObject($message->getAudio()->getFileId(), $chat, $tBot);
$text = $this->appendCaptionToFileEmbed($message, $this->processObject($message->getAudio()->getFileId(), $chat, $tBot));
}

$ignoreMessage = false;
Expand Down
2 changes: 1 addition & 1 deletion doc/telegram/rest-api.json
Original file line number Diff line number Diff line change
@@ -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}\",\"check_not_empty\":\"{{msg_html_nobr}}\",\"suburl_file_convert\":\"tgs,file_api,mp3_m4a,ogg\"}]}"}
{"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\"}]}"}