🚑 Fix webhook sample result parsing
This commit is contained in:
@ -181,35 +181,38 @@ const getGroupIdsLinkedToGroup =
|
|||||||
(
|
(
|
||||||
typebot: Pick<Typebot | PublicTypebot, 'groups' | 'variables' | 'edges'>,
|
typebot: Pick<Typebot | PublicTypebot, 'groups' | 'variables' | 'edges'>,
|
||||||
direction: 'backward' | 'forward',
|
direction: 'backward' | 'forward',
|
||||||
existingGroupIds: string[] = []
|
visitedGroupIds: string[] = []
|
||||||
) =>
|
) =>
|
||||||
(groupId: string): string[] => {
|
(groupId: string): string[] => {
|
||||||
if (existingGroupIds.includes(groupId)) return existingGroupIds
|
const linkedGroupIds = typebot.edges.reduce<string[]>((groupIds, edge) => {
|
||||||
const groups = typebot.edges.reduce<string[]>((groupIds, edge) => {
|
|
||||||
const fromGroupId = typebot.groups.find((g) =>
|
const fromGroupId = typebot.groups.find((g) =>
|
||||||
g.blocks.some(
|
g.blocks.some(
|
||||||
(b) => 'blockId' in edge.from && b.id === edge.from.blockId
|
(b) => 'blockId' in edge.from && b.id === edge.from.blockId
|
||||||
)
|
)
|
||||||
)?.id
|
)?.id
|
||||||
if (!fromGroupId) return groupIds
|
if (!fromGroupId) return groupIds
|
||||||
if (direction === 'forward')
|
if (direction === 'forward') {
|
||||||
return (!existingGroupIds ||
|
if (
|
||||||
!existingGroupIds?.includes(edge.to.groupId)) &&
|
(!visitedGroupIds || !visitedGroupIds?.includes(edge.to.groupId)) &&
|
||||||
fromGroupId === groupId
|
fromGroupId === groupId
|
||||||
? groupIds.concat(edge.to.groupId)
|
) {
|
||||||
: groupIds
|
visitedGroupIds.push(edge.to.groupId)
|
||||||
return (!existingGroupIds || !existingGroupIds.includes(fromGroupId)) &&
|
return groupIds.concat(edge.to.groupId)
|
||||||
|
}
|
||||||
|
return groupIds
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
!visitedGroupIds.includes(fromGroupId) &&
|
||||||
edge.to.groupId === groupId
|
edge.to.groupId === groupId
|
||||||
? groupIds.concat(fromGroupId)
|
) {
|
||||||
: groupIds
|
visitedGroupIds.push(fromGroupId)
|
||||||
|
return groupIds.concat(fromGroupId)
|
||||||
|
}
|
||||||
|
return groupIds
|
||||||
}, [])
|
}, [])
|
||||||
return groups.concat(
|
return linkedGroupIds.concat(
|
||||||
groups.flatMap(
|
linkedGroupIds.flatMap(
|
||||||
getGroupIdsLinkedToGroup(
|
getGroupIdsLinkedToGroup(typebot, direction, visitedGroupIds)
|
||||||
typebot,
|
|
||||||
direction,
|
|
||||||
existingGroupIds.concat(groups)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user