feat: add support for telegram circular video messages (#11504)

This PR adds support for handling Telegram's video_note messages (circular video messages), which are commonly used for short voice-style video replies in messaging.

Fixes: #11503

Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
Uchkun Rakhimov
2025-06-11 02:31:28 +05:00
committed by GitHub
parent 4303007786
commit c0d9533b3a
2 changed files with 48 additions and 4 deletions

View File

@@ -94,13 +94,25 @@ class Telegram::IncomingMessageService
end end
def file_content_type def file_content_type
return :image if params[:message][:photo].present? || params.dig(:message, :sticker, :thumb).present? return :image if image_message?
return :audio if params[:message][:voice].present? || params[:message][:audio].present? return :audio if audio_message?
return :video if params[:message][:video].present? return :video if video_message?
file_type(params[:message][:document][:mime_type]) file_type(params[:message][:document][:mime_type])
end end
def image_message?
params[:message][:photo].present? || params.dig(:message, :sticker, :thumb).present?
end
def audio_message?
params[:message][:voice].present? || params[:message][:audio].present?
end
def video_message?
params[:message][:video].present? || params[:message][:video_note].present?
end
def attach_files def attach_files
return unless file return unless file
@@ -174,6 +186,9 @@ class Telegram::IncomingMessageService
end end
def visual_media_params def visual_media_params
params[:message][:photo].presence&.last || params.dig(:message, :sticker, :thumb).presence || params[:message][:video].presence params[:message][:photo].presence&.last ||
params.dig(:message, :sticker, :thumb).presence ||
params[:message][:video].presence ||
params[:message][:video_note].presence
end end
end end

View File

@@ -179,6 +179,35 @@ describe Telegram::IncomingMessageService do
end end
end end
context 'when valid video_note messages params' do
it 'creates appropriate conversations, message and contacts' do
allow(telegram_channel.inbox.channel).to receive(:get_telegram_file_path).and_return('https://chatwoot-assets.local/sample.mov')
params = {
'update_id' => 2_342_342_343_242,
'message' => {
'video_note' => {
'duration' => 3,
'length' => 240,
'thumb' => {
'file_id' => 'AAMCBQADGQEAA4ZhXd78Xz6_c6gCzbdIkgGiXJcwwwACqwMAAp3x8Fbhf3EWamgCWAEAB20AAyEE',
'file_unique_id' => 'AQADqwMAAp3x8FZy',
'file_size' => 11_462,
'width' => 240,
'height' => 240
},
'file_id' => 'DQACAgUAAxkBAAIBY2FdJlhf8PC2E3IalXSvXWO5m8GBAALJAwACwqHgVhb0truM0uhwIQQ',
'file_unique_id' => 'AgADyQMAAsKh4FY',
'file_size' => 132_446
}
}.merge(message_params)
}.with_indifferent_access
described_class.new(inbox: telegram_channel.inbox, params: params).perform
expect(telegram_channel.inbox.conversations.count).not_to eq(0)
expect(Contact.all.first.name).to eq('Sojan Jose')
expect(telegram_channel.inbox.messages.first.attachments.first.file_type).to eq('video')
end
end
context 'when valid voice attachment params' do context 'when valid voice attachment params' do
it 'creates appropriate conversations, message and contacts' do it 'creates appropriate conversations, message and contacts' do
allow(telegram_channel.inbox.channel).to receive(:get_telegram_file_path).and_return('https://chatwoot-assets.local/sample.ogg') allow(telegram_channel.inbox.channel).to receive(:get_telegram_file_path).and_return('https://chatwoot-assets.local/sample.ogg')