2
0
Files
bot/packages/variables/prefillVariables.ts
Baptiste Arnaud 9b656214d1 🐛 (chat) Enable prefilledVariables in preview mode
Also make list values compatible
2024-02-28 14:49:04 +01:00

18 lines
594 B
TypeScript

import { safeStringify } from '@typebot.io/lib/safeStringify'
import { StartChatInput, Variable } from '@typebot.io/schemas'
export const prefillVariables = (
variables: Variable[],
prefilledVariables: NonNullable<StartChatInput['prefilledVariables']>
): Variable[] =>
variables.map((variable) => {
const prefilledVariable = prefilledVariables[variable.name]
if (!prefilledVariable) return variable
return {
...variable,
value: Array.isArray(prefilledVariable)
? prefilledVariable.map(safeStringify)
: safeStringify(prefilledVariable),
}
})