🐛 (whatsapp) Fix WA preview not starting and accept audio and documents messages
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
const urlRegex =
|
||||
/^(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})$/
|
||||
|
||||
export const validateUrl = (url: string) => urlRegex.test(url)
|
||||
export const validateUrl = (url: string) => {
|
||||
try {
|
||||
new URL(url)
|
||||
return true
|
||||
} catch (_) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -445,7 +445,9 @@ const parseReply =
|
||||
return block.options?.isRequired ?? defaultFileInputOptions.isRequired
|
||||
? { status: 'fail' }
|
||||
: { status: 'skip' }
|
||||
return { status: 'success', reply: inputValue }
|
||||
const urls = inputValue.split(', ')
|
||||
const status = urls.some((url) => validateUrl(url)) ? 'success' : 'fail'
|
||||
return { status, reply: inputValue }
|
||||
}
|
||||
case InputBlockType.PAYMENT: {
|
||||
if (!inputValue) return { status: 'fail' }
|
||||
|
||||
@@ -140,11 +140,15 @@ const getIncomingMessageContent = async ({
|
||||
}
|
||||
case 'document':
|
||||
case 'audio':
|
||||
return
|
||||
case 'video':
|
||||
case 'image':
|
||||
if (!typebotId) return
|
||||
const mediaId = 'video' in message ? message.video.id : message.image.id
|
||||
let mediaId: string | undefined
|
||||
if (message.type === 'video') mediaId = message.video.id
|
||||
if (message.type === 'image') mediaId = message.image.id
|
||||
if (message.type === 'audio') mediaId = message.audio.id
|
||||
if (message.type === 'document') mediaId = message.document.id
|
||||
if (!mediaId) return
|
||||
return (
|
||||
env.NEXTAUTH_URL +
|
||||
`/api/typebots/${typebotId}/whatsapp/media/${mediaId}`
|
||||
|
||||
Reference in New Issue
Block a user