From 9b8298b1315506a7bd9233d120b6135725d1b122 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Fri, 17 May 2024 10:12:21 +0200 Subject: [PATCH] =?UTF-8?q?:children=5Fcrossing:=20(whatsapp)=20Enable=20e?= =?UTF-8?q?mbed=20video=20thumbnail=20previ=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../convertMessageToWhatsAppMessage.ts | 43 ++++++++++++++----- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/packages/bot-engine/whatsapp/convertMessageToWhatsAppMessage.ts b/packages/bot-engine/whatsapp/convertMessageToWhatsAppMessage.ts index 92a5a4f489..4ba7d28677 100644 --- a/packages/bot-engine/whatsapp/convertMessageToWhatsAppMessage.ts +++ b/packages/bot-engine/whatsapp/convertMessageToWhatsAppMessage.ts @@ -1,8 +1,15 @@ -import { ContinueChatResponse } from '@typebot.io/schemas' +import { + ContinueChatResponse, + EmbeddableVideoBubbleContentType, +} from '@typebot.io/schemas' import { WhatsAppSendingMessage } from '@typebot.io/schemas/features/whatsapp' import { isSvgSrc } from '@typebot.io/lib/utils' import { BubbleBlockType } from '@typebot.io/schemas/features/blocks/bubbles/constants' -import { VideoBubbleContentType } from '@typebot.io/schemas/features/blocks/bubbles/video/constants' +import { + VideoBubbleContentType, + embedBaseUrls, + embeddableVideoTypes, +} from '@typebot.io/schemas/features/blocks/bubbles/video/constants' import { convertRichTextToMarkdown } from '@typebot.io/lib/markdown/convertRichTextToMarkdown' export const convertMessageToWhatsAppMessage = ( @@ -41,17 +48,31 @@ export const convertMessageToWhatsAppMessage = ( } } case BubbleBlockType.VIDEO: { + if (!message.content.url) return null + if (message.content.type === VideoBubbleContentType.URL) + return { + type: 'video', + video: { + link: message.content.url, + }, + } if ( - !message.content.url || - message.content.type !== VideoBubbleContentType.URL + embeddableVideoTypes.includes( + message.content.type as EmbeddableVideoBubbleContentType + ) ) - return null - return { - type: 'video', - video: { - link: message.content.url, - }, - } + return { + type: 'text', + text: { + body: `${ + embedBaseUrls[ + message.content.type as EmbeddableVideoBubbleContentType + ] + }/${message.content.id}`, + }, + preview_url: true, + } + return null } case BubbleBlockType.EMBED: { if (!message.content.url) return null