2
0
Files
bot/packages/bot-engine/variables/injectVariablesFromExistingResult.ts
2023-09-20 15:42:34 +02:00

18 lines
485 B
TypeScript

import { Result, Variable } from '@typebot.io/schemas'
export const injectVariablesFromExistingResult = (
variables: Variable[],
resultVariables: Result['variables']
): Variable[] =>
variables.map((variable) => {
const resultVariable = resultVariables.find(
(resultVariable) =>
resultVariable.name === variable.name && !variable.value
)
if (!resultVariable) return variable
return {
...variable,
value: resultVariable.value,
}
})