2
0

🐛 (whatsapp) Fix WA preview not starting and accept audio and documents messages

This commit is contained in:
Baptiste Arnaud
2023-12-20 10:35:34 +01:00
parent a6536461e5
commit 780b4dee18
28 changed files with 619 additions and 192 deletions

View File

@@ -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
}
}

View File

@@ -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' }

View File

@@ -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}`