2
0

🚑 Fix webhook sample result parsing

This commit is contained in:
Baptiste Arnaud
2024-06-04 15:41:18 +02:00
parent 45aa4c6da5
commit a936bc206a

View File

@ -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)
)
) )
) )
} }