@ -19,15 +19,24 @@ export const continueChat = publicProcedure
|
||||
.describe(
|
||||
'The session ID you got from the [startChat](./start-chat) response.'
|
||||
),
|
||||
textBubbleContentFormat: z
|
||||
.enum(['richText', 'markdown'])
|
||||
.default('richText'),
|
||||
})
|
||||
)
|
||||
.output(continueChatResponseSchema)
|
||||
.mutation(async ({ input: { sessionId, message }, ctx: { origin, res } }) => {
|
||||
const { corsOrigin, ...response } = await continueChatFn({
|
||||
origin,
|
||||
sessionId,
|
||||
message,
|
||||
})
|
||||
if (corsOrigin) res.setHeader('Access-Control-Allow-Origin', corsOrigin)
|
||||
return response
|
||||
})
|
||||
.mutation(
|
||||
async ({
|
||||
input: { sessionId, message, textBubbleContentFormat },
|
||||
ctx: { origin, res },
|
||||
}) => {
|
||||
const { corsOrigin, ...response } = await continueChatFn({
|
||||
origin,
|
||||
sessionId,
|
||||
message,
|
||||
textBubbleContentFormat,
|
||||
})
|
||||
if (corsOrigin) res.setHeader('Access-Control-Allow-Origin', corsOrigin)
|
||||
return response
|
||||
}
|
||||
)
|
||||
|
@ -92,6 +92,7 @@ export const sendMessageV1 = publicProcedure
|
||||
: startParams.typebot,
|
||||
message,
|
||||
userId: user?.id,
|
||||
textBubbleContentFormat: 'richText',
|
||||
}
|
||||
: {
|
||||
type: 'live',
|
||||
@ -101,6 +102,7 @@ export const sendMessageV1 = publicProcedure
|
||||
prefilledVariables: startParams.prefilledVariables,
|
||||
resultId: startParams.resultId,
|
||||
message,
|
||||
textBubbleContentFormat: 'richText',
|
||||
},
|
||||
message,
|
||||
})
|
||||
@ -179,7 +181,11 @@ export const sendMessageV1 = publicProcedure
|
||||
lastMessageNewFormat,
|
||||
visitedEdges,
|
||||
setVariableHistory,
|
||||
} = await continueBotFlow(message, { version: 1, state: session.state })
|
||||
} = await continueBotFlow(message, {
|
||||
version: 1,
|
||||
state: session.state,
|
||||
textBubbleContentFormat: 'richText',
|
||||
})
|
||||
|
||||
const allLogs = clientLogs ? [...(logs ?? []), ...clientLogs] : logs
|
||||
|
||||
|
@ -92,6 +92,7 @@ export const sendMessageV2 = publicProcedure
|
||||
: startParams.typebot,
|
||||
message,
|
||||
userId: user?.id,
|
||||
textBubbleContentFormat: 'richText',
|
||||
}
|
||||
: {
|
||||
type: 'live',
|
||||
@ -101,6 +102,7 @@ export const sendMessageV2 = publicProcedure
|
||||
prefilledVariables: startParams.prefilledVariables,
|
||||
resultId: startParams.resultId,
|
||||
message,
|
||||
textBubbleContentFormat: 'richText',
|
||||
},
|
||||
message,
|
||||
})
|
||||
@ -178,7 +180,11 @@ export const sendMessageV2 = publicProcedure
|
||||
lastMessageNewFormat,
|
||||
visitedEdges,
|
||||
setVariableHistory,
|
||||
} = await continueBotFlow(message, { version: 2, state: session.state })
|
||||
} = await continueBotFlow(message, {
|
||||
version: 2,
|
||||
state: session.state,
|
||||
textBubbleContentFormat: 'richText',
|
||||
})
|
||||
|
||||
const allLogs = clientLogs ? [...(logs ?? []), ...clientLogs] : logs
|
||||
|
||||
|
@ -28,6 +28,7 @@ export const startChatPreview = publicProcedure
|
||||
typebot: startTypebot,
|
||||
prefilledVariables,
|
||||
sessionId,
|
||||
textBubbleContentFormat,
|
||||
},
|
||||
ctx: { user },
|
||||
}) =>
|
||||
@ -41,5 +42,6 @@ export const startChatPreview = publicProcedure
|
||||
userId: user?.id,
|
||||
prefilledVariables,
|
||||
sessionId,
|
||||
textBubbleContentFormat,
|
||||
})
|
||||
)
|
||||
|
@ -48,6 +48,7 @@ test('API chat execution should work on preview bot', async ({ request }) => {
|
||||
data: {
|
||||
isOnlyRegistering: false,
|
||||
isStreamEnabled: false,
|
||||
textBubbleContentFormat: 'richText',
|
||||
} satisfies Omit<StartPreviewChatInput, 'typebotId'>,
|
||||
})
|
||||
).json()
|
||||
@ -120,6 +121,7 @@ test('API chat execution should work on published bot', async ({ request }) => {
|
||||
data: {
|
||||
isOnlyRegistering: false,
|
||||
isStreamEnabled: false,
|
||||
textBubbleContentFormat: 'richText',
|
||||
} satisfies Omit<StartChatInput, 'publicId'>,
|
||||
})
|
||||
).json()
|
||||
@ -302,6 +304,7 @@ test('API chat execution should work on published bot', async ({ request }) => {
|
||||
message: 'Hey',
|
||||
isStreamEnabled: false,
|
||||
isOnlyRegistering: false,
|
||||
textBubbleContentFormat: 'richText',
|
||||
} satisfies Omit<StartChatInput, 'publicId'>,
|
||||
}
|
||||
)
|
||||
@ -317,4 +320,19 @@ test('API chat execution should work on published bot', async ({ request }) => {
|
||||
},
|
||||
])
|
||||
})
|
||||
await test.step('Markdown text bubble format should work', async () => {
|
||||
const { messages } = await (
|
||||
await request.post(`/api/v1/typebots/${typebotId}/preview/startChat`, {
|
||||
data: {
|
||||
isOnlyRegistering: false,
|
||||
isStreamEnabled: false,
|
||||
textBubbleContentFormat: 'markdown',
|
||||
} satisfies Omit<StartPreviewChatInput, 'typebotId'>,
|
||||
})
|
||||
).json()
|
||||
expect(messages[0].content.markdown).toStrictEqual('Hi there! 👋')
|
||||
expect(messages[1].content.markdown).toStrictEqual(
|
||||
'Welcome. What's your name?'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user