From cf469fc7985dc44356198ae5964f48ad3b4fa89c Mon Sep 17 00:00:00 2001 From: Gianfranco Paoloni Date: Mon, 28 Apr 2025 16:09:29 -0300 Subject: [PATCH 1/4] chore: disable lex v2 on dev --- .../helplines/as/configs/service-configuration/development.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twilio-iac/helplines/as/configs/service-configuration/development.json b/twilio-iac/helplines/as/configs/service-configuration/development.json index bb04219416..d0f02869c6 100644 --- a/twilio-iac/helplines/as/configs/service-configuration/development.json +++ b/twilio-iac/helplines/as/configs/service-configuration/development.json @@ -23,7 +23,7 @@ "enable_voice_recordings": false, "enable_backend_hrm_contact_creation": true, "enable_lambda_post_survey_processing": true, - "enable_lex_v2": true + "enable_lex_v2": false }, "contact_save_frequency": "onTabChange", "multipleOfficeSupport": true, From 540db22764fa8990191ce02511bc49a4309f3a51 Mon Sep 17 00:00:00 2001 From: Gianfranco Paoloni Date: Mon, 28 Apr 2025 16:53:34 -0300 Subject: [PATCH 2/4] fix: handle lex v1 language formatting --- .../channelCapture/channelCaptureHandlers.ts | 8 ++++ .../src/channelCapture/chatbotCallback.ts | 12 ++++- .../channelCapture/chatbotCallbackCleanup.ts | 24 +++++++--- .../src/channelCapture/lexClient.ts | 47 ++++++------------- 4 files changed, 49 insertions(+), 42 deletions(-) diff --git a/lambdas/account-scoped/src/channelCapture/channelCaptureHandlers.ts b/lambdas/account-scoped/src/channelCapture/channelCaptureHandlers.ts index bb3c6763fd..65beb73d6e 100644 --- a/lambdas/account-scoped/src/channelCapture/channelCaptureHandlers.ts +++ b/lambdas/account-scoped/src/channelCapture/channelCaptureHandlers.ts @@ -38,6 +38,7 @@ export type CapturedChannelAttributes = { environment: string; helplineCode: string; botLanguage: string; + botLanguageV1: string; botSuffix: string; controlTaskSid: string; releaseType: ReleaseTypes; @@ -151,6 +152,7 @@ type CaptureChannelOptions = { environment: string; helplineCode: string; botLanguage: string; + botLanguageV1: string; botSuffix: string; inputText: string; userId: string; @@ -185,6 +187,7 @@ const triggerWithUserMessage = async ( helplineCode, botSuffix, botLanguage, + botLanguageV1, inputText, controlTaskSid, releaseType, @@ -201,6 +204,7 @@ const triggerWithUserMessage = async ( enableLexV2, postTextParams: { botLanguage, + botLanguageV1, botSuffix, environment, helplineCode, @@ -232,6 +236,7 @@ const triggerWithUserMessage = async ( environment, helplineCode, botLanguage, + botLanguageV1, botSuffix, controlTaskSid, releaseType, @@ -295,6 +300,7 @@ const triggerWithNextMessage = async ( environment, helplineCode, botLanguage, + botLanguageV1, botSuffix, inputText, controlTaskSid, @@ -343,6 +349,7 @@ const triggerWithNextMessage = async ( environment, helplineCode, botLanguage, + botLanguageV1, botSuffix, controlTaskSid, releaseType, @@ -571,6 +578,7 @@ export const handleChannelCapture = async ( helplineCode: helplineCode.toLowerCase(), botSuffix, botLanguage: languageSanitized.toLowerCase(), + botLanguageV1: languageSanitized, releaseType, studioFlowSid, memoryAttribute, diff --git a/lambdas/account-scoped/src/channelCapture/chatbotCallback.ts b/lambdas/account-scoped/src/channelCapture/chatbotCallback.ts index 46d6fb6a4f..e907cf8734 100644 --- a/lambdas/account-scoped/src/channelCapture/chatbotCallback.ts +++ b/lambdas/account-scoped/src/channelCapture/chatbotCallback.ts @@ -121,13 +121,21 @@ export const handleChatbotCallback: AccountScopedHandler = 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({ enableLexV2, postTextParams: { botLanguage, + botLanguageV1, botSuffix, environment, helplineCode, diff --git a/lambdas/account-scoped/src/channelCapture/chatbotCallbackCleanup.ts b/lambdas/account-scoped/src/channelCapture/chatbotCallbackCleanup.ts index e131a64566..b06c54c341 100644 --- a/lambdas/account-scoped/src/channelCapture/chatbotCallbackCleanup.ts +++ b/lambdas/account-scoped/src/channelCapture/chatbotCallbackCleanup.ts @@ -101,8 +101,15 @@ export const chatbotCallbackCleanup = async ({ } }; - const { botLanguage, botSuffix, enableLexV2, environment, helplineCode, userId } = - capturedChannelAttributes; + const { + botLanguage, + botLanguageV1, + botSuffix, + enableLexV2, + environment, + helplineCode, + userId, + } = capturedChannelAttributes; const shouldDeleteSession = botLanguage && botSuffix && environment && helplineCode && userId; @@ -111,12 +118,15 @@ export const chatbotCallbackCleanup = async ({ // Delete Lex session. This is not really needed as the session will expire, but that depends on the config of Lex. shouldDeleteSession && LexClient.deleteSession({ - botLanguage, - botSuffix, enableLexV2, - environment, - helplineCode, - sessionId: userId, + deleteSessionParams: { + botLanguage, + botLanguageV1, + botSuffix, + environment, + helplineCode, + sessionId: userId, + }, }), // Update channel attributes (remove channelCapturedByBot and add memory) updateChannelOrConversationAttributes(releasedChannelAttributes), diff --git a/lambdas/account-scoped/src/channelCapture/lexClient.ts b/lambdas/account-scoped/src/channelCapture/lexClient.ts index 7c6de21f72..2d8bb965f5 100644 --- a/lambdas/account-scoped/src/channelCapture/lexClient.ts +++ b/lambdas/account-scoped/src/channelCapture/lexClient.ts @@ -34,7 +34,6 @@ export type LexMemory = { [q: string]: string | number }; type PostTextParams = { environment: string; helplineCode: string; - botLanguage: string; botSuffix: string; sessionId: string; inputText: string; @@ -42,7 +41,6 @@ type PostTextParams = { type DeleteSessionParams = { environment: string; helplineCode: string; - botLanguage: string; botSuffix: string; sessionId: string; }; @@ -63,13 +61,13 @@ const getBotNameV1 = ({ }); const postTextV1 = async ({ - botLanguage, + botLanguageV1: botLanguage, botSuffix, environment, helplineCode, inputText, sessionId, -}: PostTextParams) => { +}: PostTextParams & { botLanguageV1: string }) => { try { const { botAlias, botName } = getBotNameV1({ botLanguage, @@ -102,12 +100,12 @@ const isEndOfDialogV1 = (dialogState: string | undefined) => dialogState === 'Fulfilled' || dialogState === 'Failed'; const deleteSessionV1 = async ({ - botLanguage, + botLanguageV1: botLanguage, botSuffix, environment, helplineCode, sessionId, -}: DeleteSessionParams) => { +}: DeleteSessionParams & { botLanguageV1: string }) => { try { const { botAlias, botName } = getBotNameV1({ botLanguage, @@ -193,7 +191,7 @@ const postTextV2 = async ({ helplineCode, inputText, sessionId, -}: PostTextParams) => { +}: PostTextParams & { botLanguage: string }) => { try { const result = await getBotNameV2({ botLanguage, @@ -237,7 +235,7 @@ const deleteSessionV2 = async ({ environment, helplineCode, sessionId, -}: DeleteSessionParams) => { +}: DeleteSessionParams & { botLanguage: string }) => { try { const result = await getBotNameV2({ botLanguage, @@ -302,7 +300,7 @@ const postText = async ({ postTextParams, }: { enableLexV2: boolean; - postTextParams: PostTextParams; + postTextParams: PostTextParams & { botLanguage: string; botLanguageV1: string }; }) => { try { if (enableLexV2) { @@ -321,38 +319,21 @@ const postText = async ({ }; const deleteSession = async ({ - botLanguage, - botSuffix, enableLexV2, - environment, - helplineCode, - sessionId, + deleteSessionParams, }: { enableLexV2: boolean; - environment: string; - helplineCode: string; - botLanguage: string; - botSuffix: string; - sessionId: string; + deleteSessionParams: DeleteSessionParams & { + botLanguage: string; + botLanguageV1: string; + }; }) => { try { if (enableLexV2) { - return await LexV2.deleteSession({ - botLanguage, - botSuffix, - environment, - helplineCode, - sessionId, - }); + return await LexV2.deleteSession(deleteSessionParams); } - return await LexV1.deleteSession({ - botLanguage, - botSuffix, - environment, - helplineCode, - sessionId, - }); + return await LexV1.deleteSession(deleteSessionParams); } catch (error) { return newErr({ message: error instanceof Error ? error.message : String(error), From 0addf2e4568b8d40f0cce5cd3c2621dcb190eab6 Mon Sep 17 00:00:00 2001 From: Gianfranco Paoloni Date: Mon, 28 Apr 2025 19:02:48 -0300 Subject: [PATCH 3/4] fix: save botLanguageV1 in channel attributes --- .../account-scoped/src/channelCapture/channelCaptureHandlers.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lambdas/account-scoped/src/channelCapture/channelCaptureHandlers.ts b/lambdas/account-scoped/src/channelCapture/channelCaptureHandlers.ts index 65beb73d6e..48c5176888 100644 --- a/lambdas/account-scoped/src/channelCapture/channelCaptureHandlers.ts +++ b/lambdas/account-scoped/src/channelCapture/channelCaptureHandlers.ts @@ -96,6 +96,7 @@ const updateChannelWithCapture = async ( environment, helplineCode, botLanguage, + botLanguageV1, botSuffix, controlTaskSid, chatbotCallbackWebhookSid, @@ -127,6 +128,7 @@ const updateChannelWithCapture = async ( environment, helplineCode, botLanguage, + botLanguageV1, botSuffix, controlTaskSid, chatbotCallbackWebhookSid, From c5d01790ca0ef1730ab0a73b816cb7f7cb39e7f0 Mon Sep 17 00:00:00 2001 From: Gianfranco Paoloni Date: Tue, 29 Apr 2025 11:24:58 -0300 Subject: [PATCH 4/4] Revert "chore: disable lex v2 on dev" This reverts commit cf469fc7985dc44356198ae5964f48ad3b4fa89c. --- .../helplines/as/configs/service-configuration/development.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twilio-iac/helplines/as/configs/service-configuration/development.json b/twilio-iac/helplines/as/configs/service-configuration/development.json index d0f02869c6..bb04219416 100644 --- a/twilio-iac/helplines/as/configs/service-configuration/development.json +++ b/twilio-iac/helplines/as/configs/service-configuration/development.json @@ -23,7 +23,7 @@ "enable_voice_recordings": false, "enable_backend_hrm_contact_creation": true, "enable_lambda_post_survey_processing": true, - "enable_lex_v2": false + "enable_lex_v2": true }, "contact_save_frequency": "onTabChange", "multipleOfficeSupport": true,