feat: Support for telegram incoming location message (#6158)

Support for incoming location messages in the telegram channel.

ref: #3398
This commit is contained in:
OMAR.A
2023-01-04 12:41:54 +02:00
committed by GitHub
parent c88ea257d5
commit 7b5f1e4876
2 changed files with 34 additions and 0 deletions

View File

@@ -20,6 +20,7 @@ class Telegram::IncomingMessageService
sender: @contact,
source_id: (params[:message][:message_id]).to_s
)
attach_location
attach_files
@message.save!
end
@@ -111,10 +112,25 @@ class Telegram::IncomingMessageService
)
end
def attach_location
return unless location
@message.attachments.new(
account_id: @message.account_id,
file_type: :location,
coordinates_lat: location['latitude'],
coordinates_long: location['longitude']
)
end
def file
@file ||= visual_media_params || params[:message][:voice].presence || params[:message][:audio].presence || params[:message][:document].presence
end
def location
@location ||= params[:message][:location].presence
end
def visual_media_params
params[:message][:photo].presence&.last || params.dig(:message, :sticker, :thumb).presence || params[:message][:video].presence
end

View File

@@ -214,5 +214,23 @@ describe Telegram::IncomingMessageService do
expect(telegram_channel.inbox.messages.first.attachments.first.file_type).to eq('file')
end
end
context 'when valid location message params' do
it 'creates appropriate conversations, message and contacts' do
params = {
'update_id' => 2_342_342_343_242,
'message' => {
'location': {
'latitude': 37.7893768,
'longitude': -122.3895553
}
}.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('location')
end
end
end
end