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', type: 'custom-embed',
content: { content: {
url: action.run.web.displayEmbedBubble.parseUrl({
options: parsedOptions,
}),
maxBubbleWidth: action.run.web.displayEmbedBubble.maxBubbleWidth, maxBubbleWidth: action.run.web.displayEmbedBubble.maxBubbleWidth,
initFunction: action.run.web.displayEmbedBubble.parseInitFunction({ initFunction: action.run.web.displayEmbedBubble.parseInitFunction({
options: parsedOptions, options: parsedOptions,

View File

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

View File

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

View File

@@ -70,6 +70,12 @@ export type ActionDefinition<
} }
web?: { web?: {
displayEmbedBubble?: { 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?: { waitForEvent?: {
getSaveVariableId?: ( getSaveVariableId?: (
options: z.infer<BaseOptions> & z.infer<Options> options: z.infer<BaseOptions> & z.infer<Options>

View File

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