chore: Move Twilio event processing to background job (#11094)

- Twilio events were being processed synchronously, leading to slow API
responses.
- This change moves Twilio event processing to a background job to
improve performance and align with how other events (e.g., WhatsApp) are
handled.

---------

Co-authored-by: Pranav <pranav@chatwoot.com>
This commit is contained in:
Sojan Jose
2025-03-15 13:51:08 -07:00
committed by GitHub
parent 46ec92c86e
commit 586dc800bb
8 changed files with 108 additions and 20 deletions

View File

@@ -0,0 +1,26 @@
require 'rails_helper'
RSpec.describe Webhooks::TwilioDeliveryStatusJob do
subject(:job) { described_class.perform_later(params) }
let(:params) do
{
'MessageSid' => 'SM123',
'MessageStatus' => 'delivered',
'AccountSid' => 'AC123'
}
end
it 'queues the job' do
expect { job }.to have_enqueued_job(described_class)
.with(params)
.on_queue('low')
end
it 'calls the Twilio::DeliveryStatusService' do
service = double
expect(Twilio::DeliveryStatusService).to receive(:new).with(params: params).and_return(service)
expect(service).to receive(:perform)
described_class.new.perform(params)
end
end

View File

@@ -0,0 +1,28 @@
require 'rails_helper'
RSpec.describe Webhooks::TwilioEventsJob do
subject(:job) { described_class.perform_later(params) }
let(:params) do
{
'From' => '+1234567890',
'To' => '+0987654321',
'Body' => 'Test message',
'AccountSid' => 'AC123',
'SmsSid' => 'SM123'
}
end
it 'queues the job' do
expect { job }.to have_enqueued_job(described_class)
.with(params)
.on_queue('low')
end
it 'calls the Twilio::IncomingMessageService' do
service = double
expect(Twilio::IncomingMessageService).to receive(:new).with(params: params).and_return(service)
expect(service).to receive(:perform)
described_class.new.perform(params)
end
end