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:
Sivin Varghese
2025-02-06 14:23:08 +05:30
committed by GitHub
parent 2a365bf19e
commit dc728faafb
3 changed files with 35 additions and 0 deletions

View File

@@ -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