feat: Added the backend support for twilio content templates (#12272)

Added comprehensive Twilio WhatsApp content template support (Phase 1)
enabling text, media, and quick reply templates with proper parameter
conversion, sync capabilities.

 **Template Types Supported**
  - Basic Text Templates: Simple text with variables ({{1}}, {{2}})
  - Media Templates: Image/Video/Document templates with text variables
  - Quick Reply Templates: Interactive button templates
  
 Front end changes is available via #12277

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
This commit is contained in:
Muhsin Keloth
2025-08-24 10:05:15 +05:30
committed by GitHub
parent 655db56be9
commit 7d6a43fc72
13 changed files with 1293 additions and 19 deletions

View File

@@ -0,0 +1,50 @@
require 'rails_helper'
RSpec.describe Channels::Twilio::TemplatesSyncJob do
let!(:account) { create(:account) }
let!(:twilio_channel) { create(:channel_twilio_sms, medium: :whatsapp, account: account) }
it 'enqueues the job' do
expect { described_class.perform_later(twilio_channel) }.to have_enqueued_job(described_class)
.on_queue('low')
.with(twilio_channel)
end
describe '#perform' do
let(:template_sync_service) { instance_double(Twilio::TemplateSyncService) }
context 'with successful template sync' do
it 'creates and calls the template sync service' do
expect(Twilio::TemplateSyncService).to receive(:new).with(channel: twilio_channel).and_return(template_sync_service)
expect(template_sync_service).to receive(:call).and_return(true)
described_class.perform_now(twilio_channel)
end
end
context 'with template sync exception' do
let(:error_message) { 'Twilio API error' }
before do
allow(Twilio::TemplateSyncService).to receive(:new).with(channel: twilio_channel).and_return(template_sync_service)
allow(template_sync_service).to receive(:call).and_raise(StandardError, error_message)
end
it 'does not suppress the exception' do
expect { described_class.perform_now(twilio_channel) }.to raise_error(StandardError, error_message)
end
end
context 'with nil channel' do
it 'handles nil channel gracefully' do
expect { described_class.perform_now(nil) }.to raise_error(NoMethodError)
end
end
end
describe 'job configuration' do
it 'is configured to run on low priority queue' do
expect(described_class.queue_name).to eq('low')
end
end
end