diff --git a/apps/viewer/src/features/chat/api/startChatPreview.ts b/apps/viewer/src/features/chat/api/startChatPreview.ts index 7b5a9b139..8d7f0ed5e 100644 --- a/apps/viewer/src/features/chat/api/startChatPreview.ts +++ b/apps/viewer/src/features/chat/api/startChatPreview.ts @@ -29,6 +29,7 @@ export const startChatPreview = publicProcedure startFrom, typebotId, typebot: startTypebot, + prefilledVariables, }, ctx: { user }, }) => { @@ -51,6 +52,7 @@ export const startChatPreview = publicProcedure typebotId, typebot: startTypebot, userId: user?.id, + prefilledVariables, }, message, }) diff --git a/packages/bot-engine/startSession.ts b/packages/bot-engine/startSession.ts index a8d346153..2218921c4 100644 --- a/packages/bot-engine/startSession.ts +++ b/packages/bot-engine/startSession.ts @@ -69,10 +69,9 @@ export const startSession = async ({ > => { const typebot = await getTypebot(startParams) - const prefilledVariables = - startParams.type === 'live' && startParams.prefilledVariables - ? prefillVariables(typebot.variables, startParams.prefilledVariables) - : typebot.variables + const prefilledVariables = startParams.prefilledVariables + ? prefillVariables(typebot.variables, startParams.prefilledVariables) + : typebot.variables const result = await getResult({ resultId: startParams.type === 'live' ? startParams.resultId : undefined, diff --git a/packages/embeds/js/src/queries/startChatQuery.ts b/packages/embeds/js/src/queries/startChatQuery.ts index d1b81c4de..7ad3923bf 100644 --- a/packages/embeds/js/src/queries/startChatQuery.ts +++ b/packages/embeds/js/src/queries/startChatQuery.ts @@ -82,6 +82,7 @@ export async function startChatQuery({ isStreamEnabled: true, startFrom, typebot, + prefilledVariables, } satisfies Omit, timeout: false, } diff --git a/packages/embeds/react/src/stories/assets/leadGenerationTypebot.ts b/packages/embeds/react/src/stories/assets/leadGenerationTypebot.ts index c20fe9883..aae302204 100644 --- a/packages/embeds/react/src/stories/assets/leadGenerationTypebot.ts +++ b/packages/embeds/react/src/stories/assets/leadGenerationTypebot.ts @@ -328,9 +328,11 @@ export const leadGenerationTypebot: StartTypebot = { id: 'clckrl870000y3b6sxyd24qwc', type: BubbleBlockType.TEXT, content: { - html: '
Hi {{Name}}!
', - richText: [{ type: 'p', children: [{ text: 'Hi {{Name}}!' }] }], - plainText: 'Hi {{Name}}!', + html: '
Hi {{={{Name}}[0]=}}!
', + richText: [ + { type: 'p', children: [{ text: 'Hi {{={{Name}}[0]=}}!' }] }, + ], + plainText: 'Hi {{={{Name}}[0]=}}!', }, outgoingEdgeId: 'clckrlwmd00163b6sjlass4p8', }, @@ -443,7 +445,7 @@ export const leadGenerationTypebot: StartTypebot = { }, }, settings: { - general: { isBrandingEnabled: true }, + general: { isBrandingEnabled: true, isInputPrefillEnabled: true }, metadata: { description: 'Build beautiful conversational forms and embed them directly in your applications without a line of code. Triple your response rate and collect answers that has more value compared to a traditional form.', diff --git a/packages/embeds/react/src/stories/bubble.stories.tsx b/packages/embeds/react/src/stories/bubble.stories.tsx index cd5821db2..efd70b8d9 100644 --- a/packages/embeds/react/src/stories/bubble.stories.tsx +++ b/packages/embeds/react/src/stories/bubble.stories.tsx @@ -39,7 +39,7 @@ export const Default = () => { typebot={leadGenerationTypebot} apiHost="http://localhost:3001" prefilledVariables={{ - Name: 'John', + Name: ['John'], }} previewMessage={{ avatarUrl: 'https://avatars.githubusercontent.com/u/16015833?v=4', diff --git a/packages/schemas/features/chat/schema.ts b/packages/schemas/features/chat/schema.ts index 09166dcf8..1794727de 100644 --- a/packages/schemas/features/chat/schema.ts +++ b/packages/schemas/features/chat/schema.ts @@ -238,6 +238,18 @@ export const startPreviewChatInputSchema = z.object({ 'If set, it will override the typebot that is used to start the chat.' ), startFrom: startFromSchema.optional(), + prefilledVariables: z + .record(z.unknown()) + .optional() + .describe( + '[More info about prefilled variables.](../../editor/variables#prefilled-variables)' + ) + .openapi({ + example: { + 'First name': 'John', + Email: 'john@gmail.com', + }, + }), }) export type StartPreviewChatInput = z.infer diff --git a/packages/variables/prefillVariables.ts b/packages/variables/prefillVariables.ts index d044f302b..3a3cd91fc 100644 --- a/packages/variables/prefillVariables.ts +++ b/packages/variables/prefillVariables.ts @@ -10,6 +10,8 @@ export const prefillVariables = ( if (!prefilledVariable) return variable return { ...variable, - value: safeStringify(prefilledVariable), + value: Array.isArray(prefilledVariable) + ? prefilledVariable.map(safeStringify) + : safeStringify(prefilledVariable), } })