2
0

♻️ Introduce typebot v6 with events (#1013)

Closes #885
This commit is contained in:
Baptiste Arnaud
2023-11-08 15:34:16 +01:00
committed by GitHub
parent 68e4fc71fb
commit 35300eaf34
634 changed files with 58971 additions and 31449 deletions

View File

@@ -76,7 +76,7 @@ const evaluateSetVariableExpression =
const getExpressionToEvaluate =
(state: SessionState) =>
(options: SetVariableBlock['options']): string | null => {
switch (options.type) {
switch (options?.type) {
case 'Contact name':
return state.whatsApp?.contact.name ?? null
case 'Phone number': {
@@ -102,6 +102,12 @@ const getExpressionToEvaluate =
return `const itemIndex = ${options.mapListItemParams?.baseListVariableId}.indexOf(${options.mapListItemParams?.baseItemVariableId})
return ${options.mapListItemParams?.targetListVariableId}.at(itemIndex)`
}
case 'Append value(s)': {
return `if(!${options.item}) return ${options.variableId};
if(!${options.variableId}) return [${options.item}];
if(!Array.isArray(${options.variableId})) return [${options.variableId}, ${options.item}];
return (${options.variableId}).concat(${options.item});`
}
case 'Empty': {
return null
}
@@ -117,7 +123,7 @@ const getExpressionToEvaluate =
}
case 'Custom':
case undefined: {
return options.expressionToEvaluate ?? null
return options?.expressionToEvaluate ?? null
}
}
}