fix(inboxes): fix twilio webhook and finish setup edge cases

This commit is contained in:
Sojan Jose
2026-02-13 17:33:19 -08:00
parent 73420636bf
commit 537ea5a2a7
5 changed files with 46 additions and 17 deletions
@@ -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',
@@ -146,6 +146,7 @@ export const useInbox = (inboxId = null) => {
isASmsInbox,
isATelegramChannel,
isATwilioChannel,
isATwilioSMSChannel,
isAWebWidgetInbox,
isAWhatsAppChannel,
isAMicrosoftInbox,
@@ -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"
/>
<div
v-if="isAWhatsAppChannel && qrCodes.whatsapp"
v-if="isTwilioWhatsAppChannel && qrCodes.whatsapp"
class="flex flex-col gap-3 items-center mt-8"
>
<p class="mt-2 text-sm text-n-slate-9">
+9 -1
View File
@@ -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
@@ -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) }