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

@@ -13,6 +13,17 @@ module Telegram::ParamHelpers
{}
end
def business_message?
telegram_params_business_connection_id.present?
end
# In business bot mode we will receive messages from our telegram.
# This is our messages posted via telegram client.
# Such messages should be outgoing (from us to client)
def business_message_outgoing?
business_message? && telegram_params_base_object[:chat][:id] != telegram_params_base_object[:from][:id]
end
def message_params?
params[:message].present?
end
@@ -29,24 +40,34 @@ module Telegram::ParamHelpers
end
end
def contact_params
if business_message_outgoing?
telegram_params_base_object[:chat]
else
telegram_params_base_object[:from]
end
end
def telegram_params_from_id
return telegram_params_base_object[:chat][:id] if business_message?
telegram_params_base_object[:from][:id]
end
def telegram_params_first_name
telegram_params_base_object[:from][:first_name]
contact_params[:first_name]
end
def telegram_params_last_name
telegram_params_base_object[:from][:last_name]
contact_params[:last_name]
end
def telegram_params_username
telegram_params_base_object[:from][:username]
contact_params[:username]
end
def telegram_params_language_code
telegram_params_base_object[:from][:language_code]
contact_params[:language_code]
end
def telegram_params_chat_id
@@ -57,6 +78,14 @@ module Telegram::ParamHelpers
end
end
def telegram_params_business_connection_id
if callback_query_params?
params[:callback_query][:message][:business_connection_id]
else
telegram_params_base_object[:business_connection_id]
end
end
def telegram_params_message_content
if callback_query_params?
params[:callback_query][:data]