Skip to content

Commit

Permalink
Look up useTestApi flag in correct place
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenhand committed Oct 18, 2024
1 parent 390d9a2 commit ded82b8
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions functions/helpers/customChannels/flexToCustomChannel.private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,10 @@ export const redirectConversationMessageToExternalChat = async (
): Promise<RedirectResult> => {
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();
Expand All @@ -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 };
Expand Down

0 comments on commit ded82b8

Please sign in to comment.