fix: Render missing captions for telegram media attachments (#3257)

This commit is contained in:
Viraj Bahulkar
2021-10-25 15:52:06 +05:30
committed by GitHub
parent 84df9c807d
commit e5e73a08fe
2 changed files with 21 additions and 1 deletions

View File

@@ -13,7 +13,7 @@ class Telegram::IncomingMessageService
update_contact_avatar
set_conversation
@message = @conversation.messages.create(
content: params[:message][:text],
content: params[:message][:text].presence || params[:message][:caption],
account_id: @inbox.account_id,
inbox_id: @inbox.id,
message_type: :incoming,

View File

@@ -24,6 +24,26 @@ describe Telegram::IncomingMessageService do
end
end
context 'when valid caption params' do
it 'creates appropriate conversations, message and contacts' do
params = {
'update_id' => 2_342_342_343_242,
'message' => {
'message_id' => 1,
'from' => {
'id' => 23, 'is_bot' => false, 'first_name' => 'Sojan', 'last_name' => 'Jose', 'username' => 'sojan', 'language_code' => 'en'
},
'chat' => { 'id' => 23, 'first_name' => 'Sojan', 'last_name' => 'Jose', 'username' => 'sojan', 'type' => 'private' },
'date' => 1_631_132_077, 'caption' => 'test'
}
}.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.content).to eq('test')
end
end
context 'when group messages' do
it 'doesnot create conversations, message and contacts' do
params = {