Skip to content

Commit

Permalink
馃悰 (typebotLink) Fix link to first group with start event
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Nov 9, 2023
1 parent 9eef166 commit 9bb5591
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions packages/bot-engine/blocks/logic/typebotLink/executeTypebotLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '@typebot.io/schemas'
import { ExecuteLogicResponse } from '../../../types'
import { createId } from '@paralleldrive/cuid2'
import { isNotDefined } from '@typebot.io/lib/utils'
import { isNotDefined, byId } from '@typebot.io/lib/utils'
import { createResultIfNotExist } from '../../../queries/createResultIfNotExist'
import prisma from '@typebot.io/lib/prisma'
import { defaultTypebotLinkOptions } from '@typebot.io/schemas/features/blocks/logic/typebotLink/constants'
Expand Down Expand Up @@ -47,11 +47,7 @@ export const executeTypebotLink = async (
return { outgoingEdgeId: block.outgoingEdgeId, logs }
}
newSessionState = await addLinkedTypebotToState(state, block, linkedTypebot)
nextGroupId =
block.options?.groupId ??
linkedTypebot.groups.find((group) =>
group.blocks.some((block) => block.type === 'start')
)?.id
nextGroupId = getNextGroupId(block.options?.groupId, linkedTypebot)
}

if (!nextGroupId) {
Expand Down Expand Up @@ -255,3 +251,17 @@ const fetchTypebot = async (state: SessionState, typebotId: string) => {
id: typebotId,
})
}

const getNextGroupId = (
groupId: string | undefined,
typebot: TypebotInSession
) => {
if (groupId) return groupId
if (typebot.version === '6') {
const startEdge = typebot.edges.find(byId(typebot.events[0].outgoingEdgeId))
return startEdge?.to.groupId
}
return typebot.groups.find((group) =>
group.blocks.some((block) => block.type === 'start')
)?.id
}

0 comments on commit 9bb5591

Please sign in to comment.