diff --git a/lambdas/account-scoped/src/channelCapture/channelCaptureHandlers.ts b/lambdas/account-scoped/src/channelCapture/channelCaptureHandlers.ts index e3dc42a9ef..e10f9ac05e 100644 --- a/lambdas/account-scoped/src/channelCapture/channelCaptureHandlers.ts +++ b/lambdas/account-scoped/src/channelCapture/channelCaptureHandlers.ts @@ -39,6 +39,7 @@ export type CapturedChannelAttributes = { environment: string; helplineCode: string; botLanguage: string; + botLanguageV1: string; botSuffix: string; controlTaskSid: string; releaseType: ReleaseTypes; @@ -96,6 +97,7 @@ const updateChannelWithCapture = async ( environment, helplineCode, botLanguage, + botLanguageV1, botSuffix, controlTaskSid, chatbotCallbackWebhookSid, @@ -127,6 +129,7 @@ const updateChannelWithCapture = async ( environment, helplineCode, botLanguage, + botLanguageV1, botSuffix, controlTaskSid, chatbotCallbackWebhookSid, @@ -152,6 +155,7 @@ type CaptureChannelOptions = { environment: string; helplineCode: string; botLanguage: string; + botLanguageV1: string; botSuffix: string; inputText: string; userId: string; @@ -186,6 +190,7 @@ const triggerWithUserMessage = async ( helplineCode, botSuffix, botLanguage, + botLanguageV1, inputText, controlTaskSid, releaseType, @@ -202,6 +207,7 @@ const triggerWithUserMessage = async ( enableLexV2, postTextParams: { botLanguage, + botLanguageV1, botSuffix, environment, helplineCode, @@ -233,6 +239,7 @@ const triggerWithUserMessage = async ( environment, helplineCode, botLanguage, + botLanguageV1, botSuffix, controlTaskSid, releaseType, @@ -296,6 +303,7 @@ const triggerWithNextMessage = async ( environment, helplineCode, botLanguage, + botLanguageV1, botSuffix, inputText, controlTaskSid, @@ -344,6 +352,7 @@ const triggerWithNextMessage = async ( environment, helplineCode, botLanguage, + botLanguageV1, botSuffix, controlTaskSid, releaseType, @@ -572,6 +581,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 8bd5a1206f..6b42a83588 100644 --- a/lambdas/account-scoped/src/channelCapture/chatbotCallbackCleanup.ts +++ b/lambdas/account-scoped/src/channelCapture/chatbotCallbackCleanup.ts @@ -102,8 +102,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; @@ -112,12 +119,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),