From 184bdfced61353e41b63721b21acfd032fe8da52 Mon Sep 17 00:00:00 2001 From: Gianfranco Paoloni Date: Wed, 23 Apr 2025 18:42:27 -0300 Subject: [PATCH 1/3] chore: disable post survey listener --- functions/taskrouterListeners/postSurveyListener.private.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/functions/taskrouterListeners/postSurveyListener.private.ts b/functions/taskrouterListeners/postSurveyListener.private.ts index 461141b7..78927c53 100644 --- a/functions/taskrouterListeners/postSurveyListener.private.ts +++ b/functions/taskrouterListeners/postSurveyListener.private.ts @@ -78,7 +78,8 @@ const isTriggerPostSurvey = ( * Checks the event type to determine if the listener should handle the event or not. * If it returns true, the taskrouter will invoke this listener. */ -export const shouldHandle = (event: EventFields) => eventTypes.includes(event.EventType); +export const shouldHandle = () => false; +// export const shouldHandle = (event: EventFields) => eventTypes.includes(event.EventType); export const handleEvent = async (context: Context, event: EventFields) => { const { From 8b3f6af0ce8e2d2a1ff0277cffcb4acb55ed3db1 Mon Sep 17 00:00:00 2001 From: Gianfranco Paoloni Date: Thu, 24 Apr 2025 15:13:23 -0300 Subject: [PATCH 2/3] chore: bypass post survey handler if flag is set --- .../taskrouterListeners/postSurveyListener.private.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/functions/taskrouterListeners/postSurveyListener.private.ts b/functions/taskrouterListeners/postSurveyListener.private.ts index 78927c53..b7366f15 100644 --- a/functions/taskrouterListeners/postSurveyListener.private.ts +++ b/functions/taskrouterListeners/postSurveyListener.private.ts @@ -100,6 +100,13 @@ export const handleEvent = async (context: Context, event: EventFields) const serviceConfig = await client.flexApi.configuration.get().fetch(); const { feature_flags: featureFlags, helplineLanguage } = serviceConfig.attributes; + if (featureFlags.enable_lambda_post_survey_processing) { + console.debug( + 'enable_lambda_post_survey_processing is set, the post survey handler will be process in twilio lambda.', + ); + return; + } + if (featureFlags.enable_post_survey) { const { channelSid, conversationSid, channelType, customChannelType } = taskAttributes; From a14c4c56cd49ec493ec580578844bd23a3ed832b Mon Sep 17 00:00:00 2001 From: Gianfranco Paoloni Date: Tue, 29 Apr 2025 11:42:57 -0300 Subject: [PATCH 3/3] fix: handle lex v1 language formatting --- .../channelCaptureHandlers.private.ts | 10 ++++++++++ .../channelCapture/chatbotCallback.protected.ts | 12 ++++++++++-- .../chatbotCallbackCleanup.protected.ts | 3 ++- functions/channelCapture/lexClient.private.ts | 14 +++++++++----- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/functions/channelCapture/channelCaptureHandlers.private.ts b/functions/channelCapture/channelCaptureHandlers.private.ts index e8387bb5..20b3eaf3 100644 --- a/functions/channelCapture/channelCaptureHandlers.private.ts +++ b/functions/channelCapture/channelCaptureHandlers.private.ts @@ -61,6 +61,7 @@ export type CapturedChannelAttributes = { environment: string; helplineCode: string; botLanguage: string; + botLanguageV1: string; botSuffix: string; controlTaskSid: string; releaseType: ReleaseTypes; @@ -114,6 +115,7 @@ const updateChannelWithCapture = async ( environment, helplineCode, botLanguage, + botLanguageV1, botSuffix, controlTaskSid, chatbotCallbackWebhookSid, @@ -145,6 +147,7 @@ const updateChannelWithCapture = async ( environment, helplineCode, botLanguage, + botLanguageV1, botSuffix, controlTaskSid, chatbotCallbackWebhookSid, @@ -171,6 +174,7 @@ type CaptureChannelOptions = { environment: string; helplineCode: string; botLanguage: string; + botLanguageV1: string; botSuffix: string; inputText: string; userId: string; @@ -196,6 +200,7 @@ const triggerWithUserMessage = async ( helplineCode, botSuffix, botLanguage, + botLanguageV1, inputText, controlTaskSid, releaseType, @@ -212,6 +217,7 @@ const triggerWithUserMessage = async ( // trigger Lex first, in order to reduce the time between the creating the webhook and sending the message const lexResult = await lexClient.postText(context, { botLanguage, + botLanguageV1, botSuffix, enableLexV2, environment, @@ -253,6 +259,7 @@ const triggerWithUserMessage = async ( environment, helplineCode, botLanguage, + botLanguageV1, botSuffix, controlTaskSid, releaseType, @@ -312,6 +319,7 @@ const triggerWithNextMessage = async ( environment, helplineCode, botLanguage, + botLanguageV1, botSuffix, inputText, controlTaskSid, @@ -369,6 +377,7 @@ const triggerWithNextMessage = async ( environment, helplineCode, botLanguage, + botLanguageV1, botSuffix, controlTaskSid, releaseType, @@ -552,6 +561,7 @@ export const handleChannelCapture = async ( helplineCode: HELPLINE_CODE.toLowerCase(), botSuffix, botLanguage: languageSanitized.toLowerCase(), + botLanguageV1: languageSanitized, releaseType, studioFlowSid, memoryAttribute, diff --git a/functions/channelCapture/chatbotCallback.protected.ts b/functions/channelCapture/chatbotCallback.protected.ts index d6b6e323..c6b89620 100644 --- a/functions/channelCapture/chatbotCallback.protected.ts +++ b/functions/channelCapture/chatbotCallback.protected.ts @@ -129,11 +129,19 @@ export const handler = async ( const capturedChannelAttributes = channelAttributes.capturedChannelAttributes as CapturedChannelAttributes; - const { botLanguage, botSuffix, enableLexV2, environment, helplineCode, userId } = - capturedChannelAttributes; + const { + botLanguage, + botLanguageV1, + botSuffix, + enableLexV2, + environment, + helplineCode, + userId, + } = capturedChannelAttributes; const lexResult = await lexClient.postText(context, { botLanguage, + botLanguageV1, botSuffix, enableLexV2, environment, diff --git a/functions/channelCapture/chatbotCallbackCleanup.protected.ts b/functions/channelCapture/chatbotCallbackCleanup.protected.ts index 55cbd1d5..ca00fe03 100644 --- a/functions/channelCapture/chatbotCallbackCleanup.protected.ts +++ b/functions/channelCapture/chatbotCallbackCleanup.protected.ts @@ -118,7 +118,7 @@ export const chatbotCallbackCleanup = async ({ } }; - const { botLanguage, botSuffix, enableLexV2, environment, helplineCode, userId } = + const { botLanguage, botLanguageV1, botSuffix, enableLexV2, environment, helplineCode, userId } = capturedChannelAttributes; const shouldDeleteSession = botLanguage && botSuffix && environment && helplineCode && userId; @@ -128,6 +128,7 @@ export const chatbotCallbackCleanup = async ({ shouldDeleteSession && lexClient.deleteSession(context, { botLanguage, + botLanguageV1, botSuffix, enableLexV2, environment, diff --git a/functions/channelCapture/lexClient.private.ts b/functions/channelCapture/lexClient.private.ts index e5e1e540..9026e0c3 100644 --- a/functions/channelCapture/lexClient.private.ts +++ b/functions/channelCapture/lexClient.private.ts @@ -102,16 +102,16 @@ const deleteSessionV1 = async ( }; const getBotNameV1 = ({ - botLanguage, + botLanguageV1, botSuffix, environment, helplineCode, }: { environment: string; helplineCode: string; - botLanguage: string; + botLanguageV1: string; botSuffix: string; -}) => `${environment}_${helplineCode}_${botLanguage}_${botSuffix}`; +}) => `${environment}_${helplineCode}_${botLanguageV1}_${botSuffix}`; export const LexV1 = { postText: postTextV1, @@ -289,6 +289,7 @@ export const postText = async ( credentials: AWSCredentials, { botLanguage, + botLanguageV1, botSuffix, enableLexV2, environment, @@ -300,6 +301,7 @@ export const postText = async ( environment: string; helplineCode: string; botLanguage: string; + botLanguageV1: string; botSuffix: string; inputText: string; userId: string; @@ -330,7 +332,7 @@ export const postText = async ( return res; } - const botName = LexV1.getBotName({ botLanguage, botSuffix, environment, helplineCode }); + const botName = LexV1.getBotName({ botLanguageV1, botSuffix, environment, helplineCode }); const botAlias = 'latest'; // Assume we always use the latest published version const res = await LexV1.postText(credentials, { botAlias, botName, inputText, userId }); @@ -347,6 +349,7 @@ export const deleteSession = async ( credentials: AWSCredentials, { botLanguage, + botLanguageV1, botSuffix, enableLexV2, environment, @@ -357,6 +360,7 @@ export const deleteSession = async ( environment: string; helplineCode: string; botLanguage: string; + botLanguageV1: string; botSuffix: string; userId: string; }, @@ -384,7 +388,7 @@ export const deleteSession = async ( }); } - const botName = LexV1.getBotName({ botLanguage, botSuffix, environment, helplineCode }); + const botName = LexV1.getBotName({ botLanguageV1, botSuffix, environment, helplineCode }); const botAlias = 'latest'; // Assume we always use the latest published version return await LexV1.deleteSession(credentials, { botAlias, botName, userId });