🚸 (typebotLink) Make sure variables from child bots are merged if necessary
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { byId } from '@typebot.io/lib'
|
import { byId, isNotDefined } from '@typebot.io/lib'
|
||||||
import { Group, SessionState } from '@typebot.io/schemas'
|
import { Group, SessionState, VariableWithValue } from '@typebot.io/schemas'
|
||||||
import { upsertResult } from '../queries/upsertResult'
|
import { upsertResult } from '../queries/upsertResult'
|
||||||
|
import { isDefined } from '@udecode/plate-common'
|
||||||
|
|
||||||
export type NextGroup = {
|
export type NextGroup = {
|
||||||
group?: Group
|
group?: Group
|
||||||
@@ -31,15 +32,25 @@ export const getNextGroup =
|
|||||||
typebot: isMergingWithParent
|
typebot: isMergingWithParent
|
||||||
? {
|
? {
|
||||||
...state.typebotsQueue[1].typebot,
|
...state.typebotsQueue[1].typebot,
|
||||||
variables: state.typebotsQueue[1].typebot.variables.map(
|
variables: state.typebotsQueue[1].typebot.variables
|
||||||
(variable) => ({
|
.map((variable) => ({
|
||||||
...variable,
|
...variable,
|
||||||
value:
|
value:
|
||||||
state.typebotsQueue[0].answers.find(
|
state.typebotsQueue[0].answers.find(
|
||||||
(answer) => answer.key === variable.name
|
(answer) => answer.key === variable.name
|
||||||
)?.value ?? variable.value,
|
)?.value ?? variable.value,
|
||||||
})
|
}))
|
||||||
),
|
.concat(
|
||||||
|
state.typebotsQueue[0].typebot.variables.filter(
|
||||||
|
(variable) =>
|
||||||
|
isDefined(variable.value) &&
|
||||||
|
isNotDefined(
|
||||||
|
state.typebotsQueue[1].typebot.variables.find(
|
||||||
|
(v) => v.name === variable.name
|
||||||
|
)
|
||||||
|
)
|
||||||
|
) as VariableWithValue[]
|
||||||
|
),
|
||||||
}
|
}
|
||||||
: state.typebotsQueue[1].typebot,
|
: state.typebotsQueue[1].typebot,
|
||||||
answers: isMergingWithParent
|
answers: isMergingWithParent
|
||||||
|
|||||||
Reference in New Issue
Block a user