diff --git a/apps/viewer/src/features/chat/helpers/continueBotFlow.ts b/apps/viewer/src/features/chat/helpers/continueBotFlow.ts index 53fd0df67..db5c3a19a 100644 --- a/apps/viewer/src/features/chat/helpers/continueBotFlow.ts +++ b/apps/viewer/src/features/chat/helpers/continueBotFlow.ts @@ -89,15 +89,16 @@ export const continueBotFlow = let formattedReply: string | undefined if (isInputBlock(block)) { - const parseResult = parseReply(newSessionState)(reply, block) + const parsedReplyResult = parseReply(newSessionState)(reply, block) - if (parseResult.status === 'fail') + if (parsedReplyResult.status === 'fail') return { ...(await parseRetryMessage(newSessionState)(block)), newSessionState, } - formattedReply = 'reply' in parseResult ? parseResult.reply : undefined + formattedReply = + 'reply' in parsedReplyResult ? parsedReplyResult.reply : undefined const nextEdgeId = getOutgoingEdgeId(newSessionState)( block, formattedReply @@ -310,14 +311,15 @@ const getOutgoingEdgeId = const parseReply = (state: SessionState) => (inputValue: string | undefined, block: InputBlock): ParsedReply => { - if (!inputValue) return { status: 'fail' } switch (block.type) { case InputBlockType.EMAIL: { + if (!inputValue) return { status: 'fail' } const isValid = validateEmail(inputValue) if (!isValid) return { status: 'fail' } return { status: 'success', reply: inputValue } } case InputBlockType.PHONE: { + if (!inputValue) return { status: 'fail' } const formattedPhone = formatPhoneNumber( inputValue, block.options.defaultCountryCode @@ -326,38 +328,49 @@ const parseReply = return { status: 'success', reply: formattedPhone } } case InputBlockType.URL: { + if (!inputValue) return { status: 'fail' } const isValid = validateUrl(inputValue) if (!isValid) return { status: 'fail' } return { status: 'success', reply: inputValue } } case InputBlockType.CHOICE: { + if (!inputValue) return { status: 'fail' } return parseButtonsReply(state)(inputValue, block) } case InputBlockType.NUMBER: { + if (!inputValue) return { status: 'fail' } const isValid = validateNumber(inputValue) if (!isValid) return { status: 'fail' } return { status: 'success', reply: inputValue } } case InputBlockType.DATE: { + if (!inputValue) return { status: 'fail' } return parseDateReply(inputValue, block) } case InputBlockType.FILE: { - if (!inputValue) return { status: 'skip' } + if (!inputValue) + return block.options.isRequired + ? { status: 'fail' } + : { status: 'skip' } return { status: 'success', reply: inputValue } } case InputBlockType.PAYMENT: { + if (!inputValue) return { status: 'fail' } if (inputValue === 'fail') return { status: 'fail' } return { status: 'success', reply: inputValue } } case InputBlockType.RATING: { + if (!inputValue) return { status: 'fail' } const isValid = validateRatingReply(inputValue, block) if (!isValid) return { status: 'fail' } return { status: 'success', reply: inputValue } } case InputBlockType.PICTURE_CHOICE: { + if (!inputValue) return { status: 'fail' } return parsePictureChoicesReply(state)(inputValue, block) } case InputBlockType.TEXT: { + if (!inputValue) return { status: 'fail' } return { status: 'success', reply: inputValue } } } diff --git a/apps/viewer/src/features/whatsApp/helpers/resumeWhatsAppFlow.ts b/apps/viewer/src/features/whatsApp/helpers/resumeWhatsAppFlow.ts index b304dd843..32fac7380 100644 --- a/apps/viewer/src/features/whatsApp/helpers/resumeWhatsAppFlow.ts +++ b/apps/viewer/src/features/whatsApp/helpers/resumeWhatsAppFlow.ts @@ -133,7 +133,7 @@ const getIncomingMessageContent = async ({ message: WhatsAppIncomingMessage systemUserToken: string | undefined downloadPath?: string -}): Promise => { +}): Promise => { switch (message.type) { case 'text': return message.text.body @@ -144,7 +144,7 @@ const getIncomingMessageContent = async ({ } case 'document': case 'audio': - return '' + return case 'video': case 'image': if (!systemUserToken || !downloadPath) return ''