2
0
Files
bot/packages/variables/prefillVariables.ts
2024-03-19 08:31:36 +01:00

18 lines
536 B
TypeScript

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