Skip to content

Commit

Permalink
馃殤 Fix webhook sample result parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Jun 4, 2024
1 parent 45aa4c6 commit a936bc2
Showing 1 changed file with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,35 +181,38 @@ const getGroupIdsLinkedToGroup =
(
typebot: Pick<Typebot | PublicTypebot, 'groups' | 'variables' | 'edges'>,
direction: 'backward' | 'forward',
existingGroupIds: string[] = []
visitedGroupIds: string[] = []
) =>
(groupId: string): string[] => {
if (existingGroupIds.includes(groupId)) return existingGroupIds
const groups = typebot.edges.reduce<string[]>((groupIds, edge) => {
const linkedGroupIds = typebot.edges.reduce<string[]>((groupIds, edge) => {
const fromGroupId = typebot.groups.find((g) =>
g.blocks.some(
(b) => 'blockId' in edge.from && b.id === edge.from.blockId
)
)?.id
if (!fromGroupId) return groupIds
if (direction === 'forward')
return (!existingGroupIds ||
!existingGroupIds?.includes(edge.to.groupId)) &&
if (direction === 'forward') {
if (
(!visitedGroupIds || !visitedGroupIds?.includes(edge.to.groupId)) &&
fromGroupId === groupId
? groupIds.concat(edge.to.groupId)
: groupIds
return (!existingGroupIds || !existingGroupIds.includes(fromGroupId)) &&
) {
visitedGroupIds.push(edge.to.groupId)
return groupIds.concat(edge.to.groupId)
}
return groupIds
}
if (
!visitedGroupIds.includes(fromGroupId) &&
edge.to.groupId === groupId
? groupIds.concat(fromGroupId)
: groupIds
) {
visitedGroupIds.push(fromGroupId)
return groupIds.concat(fromGroupId)
}
return groupIds
}, [])
return groups.concat(
groups.flatMap(
getGroupIdsLinkedToGroup(
typebot,
direction,
existingGroupIds.concat(groups)
)
return linkedGroupIds.concat(
linkedGroupIds.flatMap(
getGroupIdsLinkedToGroup(typebot, direction, visitedGroupIds)
)
)
}
Expand Down

0 comments on commit a936bc2

Please sign in to comment.