🚑 (fileUpload) Fix web bot file upload input skip option
This commit is contained in:
@@ -89,15 +89,16 @@ export const continueBotFlow =
|
|||||||
let formattedReply: string | undefined
|
let formattedReply: string | undefined
|
||||||
|
|
||||||
if (isInputBlock(block)) {
|
if (isInputBlock(block)) {
|
||||||
const parseResult = parseReply(newSessionState)(reply, block)
|
const parsedReplyResult = parseReply(newSessionState)(reply, block)
|
||||||
|
|
||||||
if (parseResult.status === 'fail')
|
if (parsedReplyResult.status === 'fail')
|
||||||
return {
|
return {
|
||||||
...(await parseRetryMessage(newSessionState)(block)),
|
...(await parseRetryMessage(newSessionState)(block)),
|
||||||
newSessionState,
|
newSessionState,
|
||||||
}
|
}
|
||||||
|
|
||||||
formattedReply = 'reply' in parseResult ? parseResult.reply : undefined
|
formattedReply =
|
||||||
|
'reply' in parsedReplyResult ? parsedReplyResult.reply : undefined
|
||||||
const nextEdgeId = getOutgoingEdgeId(newSessionState)(
|
const nextEdgeId = getOutgoingEdgeId(newSessionState)(
|
||||||
block,
|
block,
|
||||||
formattedReply
|
formattedReply
|
||||||
@@ -310,14 +311,15 @@ const getOutgoingEdgeId =
|
|||||||
const parseReply =
|
const parseReply =
|
||||||
(state: SessionState) =>
|
(state: SessionState) =>
|
||||||
(inputValue: string | undefined, block: InputBlock): ParsedReply => {
|
(inputValue: string | undefined, block: InputBlock): ParsedReply => {
|
||||||
if (!inputValue) return { status: 'fail' }
|
|
||||||
switch (block.type) {
|
switch (block.type) {
|
||||||
case InputBlockType.EMAIL: {
|
case InputBlockType.EMAIL: {
|
||||||
|
if (!inputValue) return { status: 'fail' }
|
||||||
const isValid = validateEmail(inputValue)
|
const isValid = validateEmail(inputValue)
|
||||||
if (!isValid) return { status: 'fail' }
|
if (!isValid) return { status: 'fail' }
|
||||||
return { status: 'success', reply: inputValue }
|
return { status: 'success', reply: inputValue }
|
||||||
}
|
}
|
||||||
case InputBlockType.PHONE: {
|
case InputBlockType.PHONE: {
|
||||||
|
if (!inputValue) return { status: 'fail' }
|
||||||
const formattedPhone = formatPhoneNumber(
|
const formattedPhone = formatPhoneNumber(
|
||||||
inputValue,
|
inputValue,
|
||||||
block.options.defaultCountryCode
|
block.options.defaultCountryCode
|
||||||
@@ -326,38 +328,49 @@ const parseReply =
|
|||||||
return { status: 'success', reply: formattedPhone }
|
return { status: 'success', reply: formattedPhone }
|
||||||
}
|
}
|
||||||
case InputBlockType.URL: {
|
case InputBlockType.URL: {
|
||||||
|
if (!inputValue) return { status: 'fail' }
|
||||||
const isValid = validateUrl(inputValue)
|
const isValid = validateUrl(inputValue)
|
||||||
if (!isValid) return { status: 'fail' }
|
if (!isValid) return { status: 'fail' }
|
||||||
return { status: 'success', reply: inputValue }
|
return { status: 'success', reply: inputValue }
|
||||||
}
|
}
|
||||||
case InputBlockType.CHOICE: {
|
case InputBlockType.CHOICE: {
|
||||||
|
if (!inputValue) return { status: 'fail' }
|
||||||
return parseButtonsReply(state)(inputValue, block)
|
return parseButtonsReply(state)(inputValue, block)
|
||||||
}
|
}
|
||||||
case InputBlockType.NUMBER: {
|
case InputBlockType.NUMBER: {
|
||||||
|
if (!inputValue) return { status: 'fail' }
|
||||||
const isValid = validateNumber(inputValue)
|
const isValid = validateNumber(inputValue)
|
||||||
if (!isValid) return { status: 'fail' }
|
if (!isValid) return { status: 'fail' }
|
||||||
return { status: 'success', reply: inputValue }
|
return { status: 'success', reply: inputValue }
|
||||||
}
|
}
|
||||||
case InputBlockType.DATE: {
|
case InputBlockType.DATE: {
|
||||||
|
if (!inputValue) return { status: 'fail' }
|
||||||
return parseDateReply(inputValue, block)
|
return parseDateReply(inputValue, block)
|
||||||
}
|
}
|
||||||
case InputBlockType.FILE: {
|
case InputBlockType.FILE: {
|
||||||
if (!inputValue) return { status: 'skip' }
|
if (!inputValue)
|
||||||
|
return block.options.isRequired
|
||||||
|
? { status: 'fail' }
|
||||||
|
: { status: 'skip' }
|
||||||
return { status: 'success', reply: inputValue }
|
return { status: 'success', reply: inputValue }
|
||||||
}
|
}
|
||||||
case InputBlockType.PAYMENT: {
|
case InputBlockType.PAYMENT: {
|
||||||
|
if (!inputValue) return { status: 'fail' }
|
||||||
if (inputValue === 'fail') return { status: 'fail' }
|
if (inputValue === 'fail') return { status: 'fail' }
|
||||||
return { status: 'success', reply: inputValue }
|
return { status: 'success', reply: inputValue }
|
||||||
}
|
}
|
||||||
case InputBlockType.RATING: {
|
case InputBlockType.RATING: {
|
||||||
|
if (!inputValue) return { status: 'fail' }
|
||||||
const isValid = validateRatingReply(inputValue, block)
|
const isValid = validateRatingReply(inputValue, block)
|
||||||
if (!isValid) return { status: 'fail' }
|
if (!isValid) return { status: 'fail' }
|
||||||
return { status: 'success', reply: inputValue }
|
return { status: 'success', reply: inputValue }
|
||||||
}
|
}
|
||||||
case InputBlockType.PICTURE_CHOICE: {
|
case InputBlockType.PICTURE_CHOICE: {
|
||||||
|
if (!inputValue) return { status: 'fail' }
|
||||||
return parsePictureChoicesReply(state)(inputValue, block)
|
return parsePictureChoicesReply(state)(inputValue, block)
|
||||||
}
|
}
|
||||||
case InputBlockType.TEXT: {
|
case InputBlockType.TEXT: {
|
||||||
|
if (!inputValue) return { status: 'fail' }
|
||||||
return { status: 'success', reply: inputValue }
|
return { status: 'success', reply: inputValue }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ const getIncomingMessageContent = async ({
|
|||||||
message: WhatsAppIncomingMessage
|
message: WhatsAppIncomingMessage
|
||||||
systemUserToken: string | undefined
|
systemUserToken: string | undefined
|
||||||
downloadPath?: string
|
downloadPath?: string
|
||||||
}): Promise<string> => {
|
}): Promise<string | undefined> => {
|
||||||
switch (message.type) {
|
switch (message.type) {
|
||||||
case 'text':
|
case 'text':
|
||||||
return message.text.body
|
return message.text.body
|
||||||
@@ -144,7 +144,7 @@ const getIncomingMessageContent = async ({
|
|||||||
}
|
}
|
||||||
case 'document':
|
case 'document':
|
||||||
case 'audio':
|
case 'audio':
|
||||||
return ''
|
return
|
||||||
case 'video':
|
case 'video':
|
||||||
case 'image':
|
case 'image':
|
||||||
if (!systemUserToken || !downloadPath) return ''
|
if (!systemUserToken || !downloadPath) return ''
|
||||||
|
|||||||
Reference in New Issue
Block a user