Restructure omni services and add Chatwoot research snapshot

This commit is contained in:
Ruslan Bakiev
2026-02-21 11:11:27 +07:00
parent edea7a0034
commit b73babbbf6
7732 changed files with 978203 additions and 32 deletions

View File

@@ -0,0 +1,44 @@
class Webhooks::TelegramEventsJob < ApplicationJob
queue_as :default
def perform(params = {})
return unless params[:bot_token]
channel = Channel::Telegram.find_by(bot_token: params[:bot_token])
if channel_is_inactive?(channel)
log_inactive_channel(channel, params)
return
end
process_event_params(channel, params)
end
private
def channel_is_inactive?(channel)
return true if channel.blank?
return true unless channel.account.active?
false
end
def log_inactive_channel(channel, params)
message = if channel&.id
"Account #{channel.account.id} is not active for channel #{channel.id}"
else
"Channel not found for bot_token: #{params[:bot_token]}"
end
Rails.logger.warn("Telegram event discarded: #{message}")
end
def process_event_params(channel, params)
return unless params[:telegram]
if params.dig(:telegram, :edited_message).present? || params.dig(:telegram, :edited_business_message).present?
Telegram::UpdateMessageService.new(inbox: channel.inbox, params: params['telegram'].with_indifferent_access).perform
else
Telegram::IncomingMessageService.new(inbox: channel.inbox, params: params['telegram'].with_indifferent_access).perform
end
end
end