feat(channel): add support for Telegram Business bots (#10181) (#11663)

Added support for Telegram Business bots. Telegram webhooks from such bots include the business_message field, which we transform into a standard message for Chatwoot. This PR also modifies how we handle replies, attachments, and image uploads when working with Telegram Business bots.

demo: https://drive.google.com/file/d/1Yz82wXBVRtb-mxjXogkUju4hlJbt3qyh/view?usp=sharing&t=4

Fixes #10181
This commit is contained in:
ruslan
2025-06-17 06:35:23 +03:00
committed by GitHub
parent 149dab239a
commit b87b7972c1
10 changed files with 203 additions and 11 deletions

View File

@@ -40,6 +40,22 @@ RSpec.describe Telegram::SendAttachmentsService do
end
end
context 'when this is business chat' do
before { allow(channel).to receive(:business_connection_id).and_return('eooW3KF5WB5HxTD7T826') }
it 'sends all types of attachments in seperate groups and returns the last successful message ID from the batch' do
attach_files(message)
service.perform
expect(a_request(:post, "#{telegram_api_url}/sendMediaGroup")
.with { |req| req.body =~ /business_connection_id.+eooW3KF5WB5HxTD7T826/m })
.to have_been_made.times(2)
expect(a_request(:post, "#{telegram_api_url}/sendDocument")
.with { |req| req.body =~ /business_connection_id.+eooW3KF5WB5HxTD7T826/m })
.to have_been_made.once
end
end
context 'when all attachments are photo and video' do
before do
2.times { attach_file_to_message(message, 'image', 'sample.png', 'image/png') }