2
0

fix(engine): 🐛 Current id bug when linking to current bot

This commit is contained in:
Baptiste Arnaud
2022-04-04 10:23:34 +02:00
parent 082270370b
commit da95cbd355

View File

@ -148,11 +148,12 @@ const executeTypebotLink = async (
}> => { }> => {
const { typebot, linkedTypebots, onNewLog, createEdge, setCurrentTypebotId } = const { typebot, linkedTypebots, onNewLog, createEdge, setCurrentTypebotId } =
context context
const linkedTypebot = const linkedTypebot = (
step.options.typebotId === 'current' step.options.typebotId === 'current'
? typebot ? typebot
: [typebot, ...linkedTypebots].find(byId(step.options.typebotId)) ?? : [typebot, ...linkedTypebots].find(byId(step.options.typebotId)) ??
(await fetchAndInjectTypebot(step, context)) (await fetchAndInjectTypebot(step, context))
) as PublicTypebot | LinkedTypebot | undefined
if (!linkedTypebot) { if (!linkedTypebot) {
onNewLog({ onNewLog({
status: 'error', status: 'error',
@ -161,7 +162,9 @@ const executeTypebotLink = async (
}) })
return { nextEdgeId: step.outgoingEdgeId } return { nextEdgeId: step.outgoingEdgeId }
} }
setCurrentTypebotId(linkedTypebot.id) setCurrentTypebotId(
'typebotId' in linkedTypebot ? linkedTypebot.typebotId : linkedTypebot.id
)
const nextBlockId = const nextBlockId =
step.options.blockId ?? step.options.blockId ??
linkedTypebot.blocks.find((b) => b.steps.some((s) => s.type === 'start')) linkedTypebot.blocks.find((b) => b.steps.some((s) => s.type === 'start'))