2
0

🐛 (whatsapp) Enable custom embed blocks

This commit is contained in:
Baptiste Arnaud
2024-04-18 13:46:49 +02:00
parent 5aad10e937
commit af014394da
5 changed files with 27 additions and 6 deletions

View File

@ -148,6 +148,9 @@ export const executeForgedBlock = async (
? {
type: 'custom-embed',
content: {
url: action.run.web.displayEmbedBubble.parseUrl({
options: parsedOptions,
}),
maxBubbleWidth: action.run.web.displayEmbedBubble.maxBubbleWidth,
initFunction: action.run.web.displayEmbedBubble.parseInitFunction({
options: parsedOptions,

View File

@ -7,11 +7,11 @@ import { convertRichTextToMarkdown } from '@typebot.io/lib/markdown/convertRichT
export const convertMessageToWhatsAppMessage = (
message: ContinueChatResponse['messages'][number]
): WhatsAppSendingMessage | undefined => {
): WhatsAppSendingMessage | null => {
switch (message.type) {
case BubbleBlockType.TEXT: {
if (!message.content.richText || message.content.richText.length === 0)
return
return null
return {
type: 'text',
text: {
@ -23,7 +23,7 @@ export const convertMessageToWhatsAppMessage = (
}
case BubbleBlockType.IMAGE: {
if (!message.content.url || isImageUrlNotCompatible(message.content.url))
return
return null
return {
type: 'image',
image: {
@ -32,7 +32,7 @@ export const convertMessageToWhatsAppMessage = (
}
}
case BubbleBlockType.AUDIO: {
if (!message.content.url) return
if (!message.content.url) return null
return {
type: 'audio',
audio: {
@ -45,7 +45,7 @@ export const convertMessageToWhatsAppMessage = (
!message.content.url ||
message.content.type !== VideoBubbleContentType.URL
)
return
return null
return {
type: 'video',
video: {
@ -54,7 +54,17 @@ export const convertMessageToWhatsAppMessage = (
}
}
case BubbleBlockType.EMBED: {
if (!message.content.url) return
if (!message.content.url) return null
return {
type: 'text',
text: {
body: message.content.url,
},
preview_url: true,
}
}
case 'custom-embed': {
if (!message.content.url) return null
return {
type: 'text',
text: {

View File

@ -42,6 +42,7 @@ export const bookEvent = createAction({
run: {
web: {
displayEmbedBubble: {
parseUrl: ({ options }) => options.link,
maxBubbleWidth: 780,
waitForEvent: {
getSaveVariableId: ({ saveBookedDateInVariableId }) =>

View File

@ -70,6 +70,12 @@ export type ActionDefinition<
}
web?: {
displayEmbedBubble?: {
/**
* Used to determine the URL to be displayed as a text bubble in runtimes where the code can't be executed. (i.e. WhatsApp)
*/
parseUrl: (params: {
options: z.infer<BaseOptions> & z.infer<Options>
}) => string | undefined
waitForEvent?: {
getSaveVariableId?: (
options: z.infer<BaseOptions> & z.infer<Options>

View File

@ -99,6 +99,7 @@ const embedMessageSchema = z
})
const displayEmbedBubbleSchema = z.object({
url: z.string().optional(),
maxBubbleWidth: z.number().optional(),
waitForEventFunction: z
.object({