diff --git a/app/javascript/dashboard/composables/spec/useInbox.spec.js b/app/javascript/dashboard/composables/spec/useInbox.spec.js index 71472a35b..be4c20ecf 100644 --- a/app/javascript/dashboard/composables/spec/useInbox.spec.js +++ b/app/javascript/dashboard/composables/spec/useInbox.spec.js @@ -129,6 +129,7 @@ describe('useInbox', () => { }); expect(wrapper.vm.isATwilioChannel).toBe(true); + expect(wrapper.vm.isATwilioSMSChannel).toBe(true); expect(wrapper.vm.isASmsInbox).toBe(true); expect(wrapper.vm.isAWhatsAppChannel).toBe(false); }); @@ -264,6 +265,7 @@ describe('useInbox', () => { 'isASmsInbox', 'isATelegramChannel', 'isATwilioChannel', + 'isATwilioSMSChannel', 'isAWebWidgetInbox', 'isAWhatsAppChannel', 'isAMicrosoftInbox', diff --git a/app/javascript/dashboard/composables/useInbox.js b/app/javascript/dashboard/composables/useInbox.js index 632d3556b..948aa69c5 100644 --- a/app/javascript/dashboard/composables/useInbox.js +++ b/app/javascript/dashboard/composables/useInbox.js @@ -146,6 +146,7 @@ export const useInbox = (inboxId = null) => { isASmsInbox, isATelegramChannel, isATwilioChannel, + isATwilioSMSChannel, isAWebWidgetInbox, isAWhatsAppChannel, isAMicrosoftInbox, diff --git a/app/javascript/dashboard/routes/dashboard/settings/inbox/FinishSetup.vue b/app/javascript/dashboard/routes/dashboard/settings/inbox/FinishSetup.vue index 9239949ca..f1d214ad2 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/inbox/FinishSetup.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/inbox/FinishSetup.vue @@ -33,7 +33,6 @@ const { isASmsInbox, isALineChannel, isAnEmailChannel, - isAWhatsAppChannel, isAFacebookInbox, isATelegramChannel, isATwilioWhatsAppChannel, @@ -57,13 +56,6 @@ const shouldShowWhatsAppWebhookDetails = computed(() => { ); }); -const isWhatsAppEmbeddedSignup = computed(() => { - return ( - isAWhatsAppCloudChannel.value && - currentInbox.value.provider_config?.source === 'embedded_signup' - ); -}); - const isTwilioSmsInbox = computed(() => { const phoneNumber = currentInbox.value?.phone_number; const callbackUrl = currentInbox.value?.callback_webhook_url; @@ -120,12 +112,6 @@ const message = computed(() => { return t('INBOX_MGMT.FINISH.WEBSITE_SUCCESS'); } - if (isWhatsAppEmbeddedSignup.value) { - return `${t('INBOX_MGMT.FINISH.MESSAGE')}. ${t( - 'INBOX_MGMT.FINISH.WHATSAPP_QR_INSTRUCTION' - )}`; - } - return t('INBOX_MGMT.FINISH.MESSAGE'); }); @@ -157,7 +143,7 @@ async function generateQRCode(platform, identifier) { async function generateQRCodes() { if (!currentInbox.value) return; - // WhatsApp (both Cloud and Twilio) + // WhatsApp if (currentInbox.value.phone_number && isTwilioWhatsAppChannel.value) { // For Twilio WhatsApp, phone_number format is "whatsapp:+1234567890" // Extract just the phone number part for QR code generation @@ -281,7 +267,7 @@ onMounted(() => { :inbox-id="$route.params.inbox_id" />
diff --git a/app/services/twilio/webhook_setup_service.rb b/app/services/twilio/webhook_setup_service.rb index 49b0c866f..1b2b24d65 100644 --- a/app/services/twilio/webhook_setup_service.rb +++ b/app/services/twilio/webhook_setup_service.rb @@ -50,6 +50,14 @@ class Twilio::WebhookSetupService end def twilio_client - @twilio_client ||= ::Twilio::REST::Client.new(channel.account_sid, channel.auth_token) + @twilio_client ||= if channel.api_key_sid.present? + ::Twilio::REST::Client.new( + channel.api_key_sid, + channel.auth_token, + channel.account_sid + ) + else + ::Twilio::REST::Client.new(channel.account_sid, channel.auth_token) + end end end diff --git a/spec/services/twilio/webhook_setup_service_spec.rb b/spec/services/twilio/webhook_setup_service_spec.rb index e10bca5cd..257a225c0 100644 --- a/spec/services/twilio/webhook_setup_service_spec.rb +++ b/spec/services/twilio/webhook_setup_service_spec.rb @@ -10,6 +10,38 @@ describe Twilio::WebhookSetupService do end describe '#perform' do + context 'with api key authentication' do + let(:channel_twilio_sms) do + create( + :channel_twilio_sms, + api_key_sid: 'SK1234567890abcdef', + account_sid: 'AC1234567890abcdef', + auth_token: 'api-key-token', + messaging_service_sid: 'MG1234567890abcdef' + ) + end + + let(:messaging) { instance_double(Twilio::REST::Messaging) } + let(:services) { instance_double(Twilio::REST::Messaging::V1::ServiceContext) } + + before do + allow(Twilio::REST::Client).to receive(:new).with( + 'SK1234567890abcdef', + 'api-key-token', + 'AC1234567890abcdef' + ).and_return(twilio_client) + allow(twilio_client).to receive(:messaging).and_return(messaging) + allow(messaging).to receive(:services).with(channel_twilio_sms.messaging_service_sid).and_return(services) + allow(services).to receive(:update) + end + + it 'uses API key credentials to initialize twilio client' do + described_class.new(inbox: channel_twilio_sms.inbox).perform + + expect(services).to have_received(:update) + end + end + context 'with a messaging service sid' do let(:channel_twilio_sms) { create(:channel_twilio_sms) }