fix(inboxes): allow telegram edits for disabled inboxes
This commit is contained in:
@@ -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}"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user