chore: Support telegram edited_message events (#6785)

- Add support for telegram edited_message events: Update the user message back in the Chatwoot dashboard when updated by the contact on telegram
This commit is contained in:
Sojan Jose
2023-03-29 18:48:16 +05:30
committed by GitHub
parent d1b65b6c9e
commit a4c9a2b2f2
5 changed files with 112 additions and 3 deletions

View File

@@ -30,7 +30,21 @@ RSpec.describe Webhooks::TelegramEventsJob, type: :job do
expect(Telegram::IncomingMessageService).to receive(:new).with(inbox: telegram_channel.inbox,
params: params['telegram'].with_indifferent_access)
expect(process_service).to receive(:perform)
described_class.perform_now(params)
described_class.perform_now(params.with_indifferent_access)
end
end
context 'when update message params' do
let!(:params) { { :bot_token => telegram_channel.bot_token, 'telegram' => { edited_message: 'test' } } }
it 'calls Telegram::UpdateMessageService' do
process_service = double
allow(Telegram::UpdateMessageService).to receive(:new).and_return(process_service)
allow(process_service).to receive(:perform)
expect(Telegram::UpdateMessageService).to receive(:new).with(inbox: telegram_channel.inbox,
params: params['telegram'].with_indifferent_access)
expect(process_service).to receive(:perform)
described_class.perform_now(params.with_indifferent_access)
end
end
end

View File

@@ -233,7 +233,7 @@ describe Telegram::IncomingMessageService do
end
end
context 'when valid callbac_query params' do
context 'when valid callback_query params' do
it 'creates appropriate conversations, message and contacts' do
params = {
'update_id' => 2_342_342_343_242,

View File

@@ -0,0 +1,50 @@
require 'rails_helper'
describe Telegram::UpdateMessageService do
let!(:telegram_channel) { create(:channel_telegram) }
let!(:update_params) do
{
'update_id': 2_323_484,
'edited_message': {
'message_id': 48,
'from': {
'id': 512_313_123_171_248,
'is_bot': false,
'first_name': 'Sojan',
'last_name': 'Jose',
'username': 'sojan'
},
'chat': {
'id': 517_123_213_211_248,
'first_name': 'Sojan',
'last_name': 'Jose',
'username': 'sojan',
'type': 'private'
},
'date': 1_680_088_034,
'edit_date': 1_680_088_056,
'text': 'updated message'
}
}
end
describe '#perform' do
context 'when valid update message params' do
it 'updates the appropriate message' do
contact_inbox = create(:contact_inbox, inbox: telegram_channel.inbox, source_id: update_params[:edited_message][:chat][:id])
conversation = create(:conversation, contact_inbox: contact_inbox)
message = create(:message, conversation: conversation, source_id: update_params[:edited_message][:message_id])
described_class.new(inbox: telegram_channel.inbox, params: update_params.with_indifferent_access).perform
expect(message.reload.content).to eq('updated message')
end
end
context 'when invalid update message params' do
it 'will not raise errors' do
expect do
described_class.new(inbox: telegram_channel.inbox, params: {}).perform
end.not_to raise_error
end
end
end
end