Skip to content

Commit

Permalink
Fix findExistingConversation ref
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenhand committed Jun 25, 2024
1 parent c47e7f0 commit b8c4fee
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const findExistingConversation = async (
): Promise<ConversationSid | undefined> => {
const conversations = await context
.getTwilioClient()
.conversations.participantConversations.list({ identity });
.conversations.v1.participantConversations.list({ identity });
const existing = conversations.find((conversation) =>
['active', 'inactive'].includes(conversation.conversationState),
);
Expand Down Expand Up @@ -540,4 +540,5 @@ export type ChannelToFlex = {
retrieveChannelFromUserChannelMap: typeof retrieveChannelFromUserChannelMap;
AseloCustomChannels: typeof AseloCustomChannels;
isAseloCustomChannel: typeof isAseloCustomChannel;
findExistingConversation: typeof findExistingConversation;
};
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const redirectConversationMessageToExternalChat = async (
shouldSend = true;
} else if (Source === 'API' && EventType === 'onMessageAdded') {
const client = context.getTwilioClient();
const conversation = await client.conversations.conversations.get(ConversationSid).fetch();
const conversation = await client.conversations.v1.conversations.get(ConversationSid).fetch();
const { attributes } = conversation;
const { participantSid } = JSON.parse(attributes);

Expand Down
11 changes: 8 additions & 3 deletions functions/webhooks/instagram/InstagramToFlex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
ChannelToFlex,
ChatChannelSid,
ConversationSid,
findExistingConversation,
} from '../../helpers/customChannels/customChannelToFlex.private';

type EnvVars = {
Expand Down Expand Up @@ -199,7 +198,10 @@ export const handler = async (
if (useConversations) {
// Handle message deletion for active conversations
if (isMessageDeleted(message)) {
const conversationSid = await findExistingConversation(context, uniqueUserName);
const conversationSid = await channelToFlex.findExistingConversation(
context,
uniqueUserName,
);

if (conversationSid) {
// const unsentMessage =
Expand All @@ -222,7 +224,10 @@ export const handler = async (

// Handle story tags for active conversations
if (isStoryMention(message)) {
const conversationSid = await findExistingConversation(context, uniqueUserName);
const conversationSid = await channelToFlex.findExistingConversation(
context,
uniqueUserName,
);

if (conversationSid) {
messageText = getStoryMentionText(message);
Expand Down

0 comments on commit b8c4fee

Please sign in to comment.