Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export type CapturedChannelAttributes = {
environment: string;
helplineCode: string;
botLanguage: string;
botLanguageV1: string;
botSuffix: string;
controlTaskSid: string;
releaseType: ReleaseTypes;
Expand Down Expand Up @@ -96,6 +97,7 @@ const updateChannelWithCapture = async (
environment,
helplineCode,
botLanguage,
botLanguageV1,
botSuffix,
controlTaskSid,
chatbotCallbackWebhookSid,
Expand Down Expand Up @@ -127,6 +129,7 @@ const updateChannelWithCapture = async (
environment,
helplineCode,
botLanguage,
botLanguageV1,
botSuffix,
controlTaskSid,
chatbotCallbackWebhookSid,
Expand All @@ -152,6 +155,7 @@ type CaptureChannelOptions = {
environment: string;
helplineCode: string;
botLanguage: string;
botLanguageV1: string;
botSuffix: string;
inputText: string;
userId: string;
Expand Down Expand Up @@ -186,6 +190,7 @@ const triggerWithUserMessage = async (
helplineCode,
botSuffix,
botLanguage,
botLanguageV1,
inputText,
controlTaskSid,
releaseType,
Expand All @@ -202,6 +207,7 @@ const triggerWithUserMessage = async (
enableLexV2,
postTextParams: {
botLanguage,
botLanguageV1,
botSuffix,
environment,
helplineCode,
Expand Down Expand Up @@ -233,6 +239,7 @@ const triggerWithUserMessage = async (
environment,
helplineCode,
botLanguage,
botLanguageV1,
botSuffix,
controlTaskSid,
releaseType,
Expand Down Expand Up @@ -296,6 +303,7 @@ const triggerWithNextMessage = async (
environment,
helplineCode,
botLanguage,
botLanguageV1,
botSuffix,
inputText,
controlTaskSid,
Expand Down Expand Up @@ -344,6 +352,7 @@ const triggerWithNextMessage = async (
environment,
helplineCode,
botLanguage,
botLanguageV1,
botSuffix,
controlTaskSid,
releaseType,
Expand Down Expand Up @@ -572,6 +581,7 @@ export const handleChannelCapture = async (
helplineCode: helplineCode.toLowerCase(),
botSuffix,
botLanguage: languageSanitized.toLowerCase(),
botLanguageV1: languageSanitized,
releaseType,
studioFlowSid,
memoryAttribute,
Expand Down
12 changes: 10 additions & 2 deletions lambdas/account-scoped/src/channelCapture/chatbotCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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),
Expand Down
47 changes: 14 additions & 33 deletions lambdas/account-scoped/src/channelCapture/lexClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@ export type LexMemory = { [q: string]: string | number };
type PostTextParams = {
environment: string;
helplineCode: string;
botLanguage: string;
botSuffix: string;
sessionId: string;
inputText: string;
};
type DeleteSessionParams = {
environment: string;
helplineCode: string;
botLanguage: string;
botSuffix: string;
sessionId: string;
};
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -193,7 +191,7 @@ const postTextV2 = async ({
helplineCode,
inputText,
sessionId,
}: PostTextParams) => {
}: PostTextParams & { botLanguage: string }) => {
try {
const result = await getBotNameV2({
botLanguage,
Expand Down Expand Up @@ -237,7 +235,7 @@ const deleteSessionV2 = async ({
environment,
helplineCode,
sessionId,
}: DeleteSessionParams) => {
}: DeleteSessionParams & { botLanguage: string }) => {
try {
const result = await getBotNameV2({
botLanguage,
Expand Down Expand Up @@ -302,7 +300,7 @@ const postText = async ({
postTextParams,
}: {
enableLexV2: boolean;
postTextParams: PostTextParams;
postTextParams: PostTextParams & { botLanguage: string; botLanguageV1: string };
}) => {
try {
if (enableLexV2) {
Expand All @@ -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),
Expand Down
Loading