Skip to content

Commit

Permalink
🚸 (whatsapp) Enable embed video thumbnail previ…
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed May 17, 2024
1 parent 8151d7f commit 9b8298b
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions packages/bot-engine/whatsapp/convertMessageToWhatsAppMessage.ts
Original file line number Diff line number Diff line change
@@ -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 = (
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9b8298b

Please sign in to comment.