From ded82b85da4ea3f19ec6356d7b29ae1b9108b086 Mon Sep 17 00:00:00 2001 From: Stephen Hand Date: Fri, 18 Oct 2024 14:10:19 +0100 Subject: [PATCH] Look up useTestApi flag in correct place --- .../customChannels/flexToCustomChannel.private.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/functions/helpers/customChannels/flexToCustomChannel.private.ts b/functions/helpers/customChannels/flexToCustomChannel.private.ts index 8ff50361..114e0d6d 100644 --- a/functions/helpers/customChannels/flexToCustomChannel.private.ts +++ b/functions/helpers/customChannels/flexToCustomChannel.private.ts @@ -95,16 +95,10 @@ export const redirectConversationMessageToExternalChat = async ( ): Promise => { const { Body, ConversationSid, EventType, ParticipantSid, Source, Author } = event; let shouldSend = false; - let useTestApi = false; + const client = context.getTwilioClient(); if (Source === 'SDK') { shouldSend = true; } else if (Source === 'API' && EventType === 'onMessageAdded') { - const client = context.getTwilioClient(); - useTestApi = - JSON.parse( - (await client.conversations.v1.conversations.get(ConversationSid).fetch())?.attributes ?? - {}, - ).useTestApi ?? useTestApi; const participants = await client.conversations.v1.conversations .get(ConversationSid) .participants.list(); @@ -118,6 +112,11 @@ export const redirectConversationMessageToExternalChat = async ( Boolean(firstParticipantSid) && ![Author, ParticipantSid].includes(firstParticipantSid); } if (shouldSend) { + const useTestApi = + JSON.parse( + (await client.conversations.v1.conversations.get(ConversationSid).fetch())?.attributes ?? + {}, + ).useTestApi ?? false; const response = await sendExternalMessage(recipientId, Body, useTestApi); if (response.ok) { return { status: 'sent', response };