feat: Adds support for telegram contact sharing (#10841)
# Pull Request Template ## Description This PR adds support for displaying shared contacts in a Telegram channel. **NB:** Tested with both old and new bubbles. Multiple numbers for a single contact are not supported at this time, but multiple contacts are supported. In the future, we can add support for displaying contact names as well. ## Type of change - [x] New feature (non-breaking change which adds functionality) ## How Has This Been Tested? **Loom video** https://www.loom.com/share/95efadace3194887bc0663c53e7c08bc?sid=a5c27176-3dd8-456c-80b9-c63dbb89dca1 ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [ ] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules
This commit is contained in:
@@ -99,6 +99,9 @@
|
||||
},
|
||||
"fallback": {
|
||||
"CONTENT": "has shared a url"
|
||||
},
|
||||
"contact": {
|
||||
"CONTENT": "Shared contact"
|
||||
}
|
||||
},
|
||||
"CHAT_SORT_BY_FILTER": {
|
||||
|
||||
@@ -43,6 +43,7 @@ class Telegram::IncomingMessageService
|
||||
def process_message_attachments
|
||||
attach_location
|
||||
attach_files
|
||||
attach_contact
|
||||
end
|
||||
|
||||
def update_contact_avatar
|
||||
@@ -136,6 +137,16 @@ class Telegram::IncomingMessageService
|
||||
)
|
||||
end
|
||||
|
||||
def attach_contact
|
||||
return unless contact_card
|
||||
|
||||
@message.attachments.new(
|
||||
account_id: @message.account_id,
|
||||
file_type: :contact,
|
||||
fallback_title: contact_card['phone_number'].to_s
|
||||
)
|
||||
end
|
||||
|
||||
def file
|
||||
@file ||= visual_media_params || params[:message][:voice].presence || params[:message][:audio].presence || params[:message][:document].presence
|
||||
end
|
||||
@@ -154,6 +165,10 @@ class Telegram::IncomingMessageService
|
||||
@location ||= params.dig(:message, :location).presence
|
||||
end
|
||||
|
||||
def contact_card
|
||||
@contact_card ||= params.dig(:message, :contact).presence
|
||||
end
|
||||
|
||||
def visual_media_params
|
||||
params[:message][:photo].presence&.last || params.dig(:message, :sticker, :thumb).presence || params[:message][:video].presence
|
||||
end
|
||||
|
||||
@@ -309,5 +309,22 @@ describe Telegram::IncomingMessageService do
|
||||
expect(telegram_channel.inbox.messages.first.content).to eq('Option 1')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when valid contact message params' do
|
||||
it 'creates appropriate conversations, message and contacts' do
|
||||
params = {
|
||||
'update_id' => 2_342_342_343_242,
|
||||
'message' => {
|
||||
'contact': {
|
||||
'phone_number': '+918660944581'
|
||||
}
|
||||
}.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('contact')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user