From f2e3e5a83fb675efd3d0c4cfa13dda5b34d82cf6 Mon Sep 17 00:00:00 2001 From: Muhsin <12408980+muhsin-k@users.noreply.github.com> Date: Wed, 22 Jul 2026 15:11:21 +0400 Subject: [PATCH] fix(inboxes): allow telegram edits for disabled inboxes --- app/jobs/webhooks/telegram_events_job.rb | 10 +++++++--- .../jobs/webhooks/telegram_events_job_spec.rb | 20 +++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/app/jobs/webhooks/telegram_events_job.rb b/app/jobs/webhooks/telegram_events_job.rb index 437ffdbfd..e06bedaa3 100644 --- a/app/jobs/webhooks/telegram_events_job.rb +++ b/app/jobs/webhooks/telegram_events_job.rb @@ -6,7 +6,7 @@ class Webhooks::TelegramEventsJob < ApplicationJob channel = Channel::Telegram.find_by(bot_token: params[:bot_token]) - if channel_is_inactive?(channel) + if channel_is_inactive?(channel, params) log_inactive_channel(channel, params) return end @@ -16,14 +16,18 @@ class Webhooks::TelegramEventsJob < ApplicationJob private - def channel_is_inactive?(channel) + def channel_is_inactive?(channel, params) return true if channel.blank? return true unless channel.account.active? - return true unless channel.inbox.active? + return true unless channel.inbox.active? || update_message_event?(params) false end + def update_message_event?(params) + params.dig(:telegram, :edited_message).present? || params.dig(:telegram, :edited_business_message).present? + end + def log_inactive_channel(channel, params) message = if channel&.id "Account #{channel.account.id} is not active for channel #{channel.id}" diff --git a/spec/jobs/webhooks/telegram_events_job_spec.rb b/spec/jobs/webhooks/telegram_events_job_spec.rb index 119a3be41..1f84536c8 100644 --- a/spec/jobs/webhooks/telegram_events_job_spec.rb +++ b/spec/jobs/webhooks/telegram_events_job_spec.rb @@ -46,6 +46,14 @@ RSpec.describe Webhooks::TelegramEventsJob do expect(Telegram::IncomingMessageService).not_to receive(:new) described_class.perform_now(params.with_indifferent_access) end + + it 'does not process incoming message events when the inbox is disabled' do + telegram_channel.inbox.update!(active: false) + + expect(Telegram::IncomingMessageService).not_to receive(:new) + + described_class.perform_now(params.with_indifferent_access) + end end context 'when update message params' do @@ -60,5 +68,17 @@ RSpec.describe Webhooks::TelegramEventsJob do expect(process_service).to receive(:perform) described_class.perform_now(params.with_indifferent_access) end + + it 'calls Telegram::UpdateMessageService when the inbox is disabled' do + telegram_channel.inbox.update!(active: false) + + process_service = double + allow(Telegram::UpdateMessageService).to receive(:new).and_return(process_service) + allow(process_service).to receive(:perform) + expect(Telegram::UpdateMessageService).to receive(:new).with(inbox: telegram_channel.inbox, + params: params['telegram'].with_indifferent_access) + expect(process_service).to receive(:perform) + described_class.perform_now(params.with_indifferent_access) + end end end