fix(engine): 🐛 Nested typebots webhhok exec
This commit is contained in:
@ -115,6 +115,7 @@ export const ChatBlock = ({
|
||||
createEdge,
|
||||
setCurrentTypebotId,
|
||||
pushEdgeIdInLinkedTypebotQueue,
|
||||
currentTypebotId,
|
||||
})
|
||||
nextEdgeId ? onBlockEnd(nextEdgeId, linkedTypebot) : displayNextStep()
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ export const ConversationContainer = ({
|
||||
const {
|
||||
typebot,
|
||||
updateVariableValue,
|
||||
linkedBotEdgeIdsQueue,
|
||||
linkedBotQueue,
|
||||
popEdgeIdFromLinkedTypebotQueue,
|
||||
} = useTypebot()
|
||||
const { document: frameDocument } = useFrame()
|
||||
@ -42,8 +42,8 @@ export const ConversationContainer = ({
|
||||
const currentTypebot = updatedTypebot ?? typebot
|
||||
const nextEdge = currentTypebot.edges.find(byId(edgeId))
|
||||
if (!nextEdge) {
|
||||
if (linkedBotEdgeIdsQueue.length > 0) {
|
||||
const nextEdgeId = linkedBotEdgeIdsQueue[0]
|
||||
if (linkedBotQueue.length > 0) {
|
||||
const nextEdgeId = linkedBotQueue[0].edgeId
|
||||
popEdgeIdFromLinkedTypebotQueue()
|
||||
displayNextBlock(nextEdgeId)
|
||||
}
|
||||
|
@ -12,19 +12,28 @@ export type LinkedTypebot = Pick<
|
||||
PublicTypebot | Typebot,
|
||||
'id' | 'blocks' | 'variables' | 'edges'
|
||||
>
|
||||
|
||||
export type LinkedTypebotQueue = {
|
||||
typebotId: string
|
||||
edgeId: string
|
||||
}[]
|
||||
|
||||
const typebotContext = createContext<{
|
||||
currentTypebotId: string
|
||||
typebot: PublicTypebot
|
||||
linkedTypebots: LinkedTypebot[]
|
||||
apiHost: string
|
||||
isPreview: boolean
|
||||
linkedBotEdgeIdsQueue: string[]
|
||||
linkedBotQueue: LinkedTypebotQueue
|
||||
setCurrentTypebotId: (id: string) => void
|
||||
updateVariableValue: (variableId: string, value: string) => void
|
||||
createEdge: (edge: Edge) => void
|
||||
injectLinkedTypebot: (typebot: Typebot | PublicTypebot) => LinkedTypebot
|
||||
popEdgeIdFromLinkedTypebotQueue: () => void
|
||||
pushEdgeIdInLinkedTypebotQueue: (edgeId: string) => void
|
||||
pushEdgeIdInLinkedTypebotQueue: (bot: {
|
||||
typebotId: string
|
||||
edgeId: string
|
||||
}) => void
|
||||
onNewLog: (log: Omit<Log, 'id' | 'createdAt' | 'resultId'>) => void
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
//@ts-ignore
|
||||
@ -46,9 +55,7 @@ export const TypebotContext = ({
|
||||
const [localTypebot, setLocalTypebot] = useState<PublicTypebot>(typebot)
|
||||
const [linkedTypebots, setLinkedTypebots] = useState<LinkedTypebot[]>([])
|
||||
const [currentTypebotId, setCurrentTypebotId] = useState(typebot.typebotId)
|
||||
const [linkedBotEdgeIdsQueue, setLinkedBotEdgeIdsQueue] = useState<string[]>(
|
||||
[]
|
||||
)
|
||||
const [linkedBotQueue, setLinkedBotQueue] = useState<LinkedTypebotQueue>([])
|
||||
|
||||
useEffect(() => {
|
||||
setLocalTypebot((localTypebot) => ({
|
||||
@ -93,11 +100,15 @@ export const TypebotContext = ({
|
||||
return typebotToInject
|
||||
}
|
||||
|
||||
const pushEdgeIdInLinkedTypebotQueue = (edgeId: string) =>
|
||||
setLinkedBotEdgeIdsQueue((queue) => [...queue, edgeId])
|
||||
const pushEdgeIdInLinkedTypebotQueue = (bot: {
|
||||
typebotId: string
|
||||
edgeId: string
|
||||
}) => setLinkedBotQueue((queue) => [...queue, bot])
|
||||
|
||||
const popEdgeIdFromLinkedTypebotQueue = () =>
|
||||
setLinkedBotEdgeIdsQueue((queue) => queue.slice(1))
|
||||
const popEdgeIdFromLinkedTypebotQueue = () => {
|
||||
setLinkedBotQueue((queue) => queue.slice(1))
|
||||
const typebot = setCurrentTypebotId(linkedBotQueue[0].typebotId)
|
||||
}
|
||||
|
||||
return (
|
||||
<typebotContext.Provider
|
||||
@ -110,7 +121,7 @@ export const TypebotContext = ({
|
||||
createEdge,
|
||||
injectLinkedTypebot,
|
||||
onNewLog,
|
||||
linkedBotEdgeIdsQueue,
|
||||
linkedBotQueue,
|
||||
pushEdgeIdInLinkedTypebotQueue,
|
||||
popEdgeIdFromLinkedTypebotQueue,
|
||||
currentTypebotId,
|
||||
|
@ -28,7 +28,11 @@ type LogicContext = {
|
||||
apiHost: string
|
||||
typebot: PublicTypebot
|
||||
linkedTypebots: LinkedTypebot[]
|
||||
pushEdgeIdInLinkedTypebotQueue: (edgeId: EdgeId) => void
|
||||
currentTypebotId: string
|
||||
pushEdgeIdInLinkedTypebotQueue: (bot: {
|
||||
edgeId: string
|
||||
typebotId: string
|
||||
}) => void
|
||||
setCurrentTypebotId: (id: string) => void
|
||||
updateVariableValue: (variableId: string, value: string) => void
|
||||
updateVariables: (variables: VariableWithValue[]) => void
|
||||
@ -157,6 +161,7 @@ const executeTypebotLink = async (
|
||||
createEdge,
|
||||
setCurrentTypebotId,
|
||||
pushEdgeIdInLinkedTypebotQueue,
|
||||
currentTypebotId,
|
||||
} = context
|
||||
const linkedTypebot = (
|
||||
step.options.typebotId === 'current'
|
||||
@ -172,7 +177,11 @@ const executeTypebotLink = async (
|
||||
})
|
||||
return { nextEdgeId: step.outgoingEdgeId }
|
||||
}
|
||||
if (step.outgoingEdgeId) pushEdgeIdInLinkedTypebotQueue(step.outgoingEdgeId)
|
||||
if (step.outgoingEdgeId)
|
||||
pushEdgeIdInLinkedTypebotQueue({
|
||||
edgeId: step.outgoingEdgeId,
|
||||
typebotId: currentTypebotId,
|
||||
})
|
||||
setCurrentTypebotId(
|
||||
'typebotId' in linkedTypebot ? linkedTypebot.typebotId : linkedTypebot.id
|
||||
)
|
||||
|
Reference in New Issue
Block a user