diff --git a/app/javascript/dashboard/routes/dashboard/settings/inbox/FinishSetup.vue b/app/javascript/dashboard/routes/dashboard/settings/inbox/FinishSetup.vue index f1d214ad2..2f9ad8269 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/inbox/FinishSetup.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/inbox/FinishSetup.vue @@ -29,13 +29,13 @@ const currentInbox = computed(() => // Use useInbox composable with the inbox ID const { isAWhatsAppCloudChannel, + isAWhatsAppChannel, isATwilioChannel, isASmsInbox, isALineChannel, isAnEmailChannel, isAFacebookInbox, isATelegramChannel, - isATwilioWhatsAppChannel, isATwilioSMSChannel, } = useInbox(route.params.inbox_id); @@ -66,17 +66,16 @@ const isTwilioSmsInbox = computed(() => { ); }); -const isTwilioWhatsAppChannel = computed(() => { - const phoneNumber = currentInbox.value?.phone_number; +const whatsappPhoneNumber = computed(() => { + return (currentInbox.value?.phone_number || '').replace('whatsapp:', ''); +}); - return ( - isATwilioWhatsAppChannel.value || - (isATwilioChannel.value && (phoneNumber || '').startsWith('whatsapp:')) - ); +const shouldShowWhatsAppQr = computed(() => { + return isAWhatsAppChannel.value && Boolean(whatsappPhoneNumber.value); }); const message = computed(() => { - if (isTwilioWhatsAppChannel.value) { + if (shouldShowWhatsAppQr.value) { return `${t('INBOX_MGMT.FINISH.MESSAGE')}. ${t( 'INBOX_MGMT.FINISH.WHATSAPP_QR_INSTRUCTION' )}`; @@ -144,14 +143,8 @@ async function generateQRCodes() { if (!currentInbox.value) return; // 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 - const phoneNumber = currentInbox.value.phone_number.replace( - 'whatsapp:', - '' - ); - await generateQRCode('whatsapp', phoneNumber); + if (shouldShowWhatsAppQr.value) { + await generateQRCode('whatsapp', whatsappPhoneNumber.value); } if (isTwilioSmsInbox.value && currentInbox.value.phone_number) { @@ -267,7 +260,7 @@ onMounted(() => { :inbox-id="$route.params.inbox_id" />
diff --git a/spec/controllers/api/v1/accounts/channels/twilio_channels_controller_spec.rb b/spec/controllers/api/v1/accounts/channels/twilio_channels_controller_spec.rb index 502687379..e7c5f3930 100644 --- a/spec/controllers/api/v1/accounts/channels/twilio_channels_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/channels/twilio_channels_controller_spec.rb @@ -55,6 +55,8 @@ RSpec.describe '/api/v1/accounts/{account.id}/channels/twilio_channel', type: :r end it 'creates inbox with blank phone number and returns inbox object' do + expect(Twilio::WebhookSetupService).to receive(:new).and_return(twilio_webhook_setup_service) + expect(twilio_webhook_setup_service).to receive(:perform) params = { twilio_channel: { account_sid: 'sid-1', diff --git a/spec/services/twilio/webhook_setup_service_spec.rb b/spec/services/twilio/webhook_setup_service_spec.rb index 257a225c0..0f3618a57 100644 --- a/spec/services/twilio/webhook_setup_service_spec.rb +++ b/spec/services/twilio/webhook_setup_service_spec.rb @@ -43,7 +43,7 @@ describe Twilio::WebhookSetupService do end context 'with a messaging service sid' do - let(:channel_twilio_sms) { create(:channel_twilio_sms) } + let(:channel_twilio_sms) { create(:channel_twilio_sms, :whatsapp) } let(:messaging) { instance_double(Twilio::REST::Messaging) } let(:services) { instance_double(Twilio::REST::Messaging::V1::ServiceContext) } @@ -52,12 +52,14 @@ describe Twilio::WebhookSetupService do 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) + allow(twilio_client).to receive(:incoming_phone_numbers) end - it 'updates the messaging service' do + it 'updates the messaging service webhook and skips phone number lookup' do described_class.new(inbox: channel_twilio_sms.inbox).perform expect(services).to have_received(:update) + expect(twilio_client).not_to have_received(:incoming_phone_numbers) end end