fix(logic): ⚡️ Make linked bot edge id work
This commit is contained in:
@@ -159,7 +159,7 @@ export const TypebotButton = ({
|
|||||||
>
|
>
|
||||||
{<TypebotIcon icon={typebot.icon} boxSize={'35px'} />}
|
{<TypebotIcon icon={typebot.icon} boxSize={'35px'} />}
|
||||||
</Flex>
|
</Flex>
|
||||||
<Text>{typebot.name}</Text>
|
<Text textAlign="center">{typebot.name}</Text>
|
||||||
</VStack>
|
</VStack>
|
||||||
{!isReadOnly && (
|
{!isReadOnly && (
|
||||||
<ConfirmModal
|
<ConfirmModal
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ export const ChatBlock = ({
|
|||||||
injectLinkedTypebot,
|
injectLinkedTypebot,
|
||||||
linkedTypebots,
|
linkedTypebots,
|
||||||
setCurrentTypebotId,
|
setCurrentTypebotId,
|
||||||
|
pushEdgeIdInLinkedTypebotQueue,
|
||||||
} = useTypebot()
|
} = useTypebot()
|
||||||
const { resultValues, updateVariables } = useAnswers()
|
const { resultValues, updateVariables } = useAnswers()
|
||||||
const [processedSteps, setProcessedSteps] = useState<Step[]>([])
|
const [processedSteps, setProcessedSteps] = useState<Step[]>([])
|
||||||
@@ -113,6 +114,7 @@ export const ChatBlock = ({
|
|||||||
onNewLog,
|
onNewLog,
|
||||||
createEdge,
|
createEdge,
|
||||||
setCurrentTypebotId,
|
setCurrentTypebotId,
|
||||||
|
pushEdgeIdInLinkedTypebotQueue,
|
||||||
})
|
})
|
||||||
nextEdgeId ? onBlockEnd(nextEdgeId, linkedTypebot) : displayNextStep()
|
nextEdgeId ? onBlockEnd(nextEdgeId, linkedTypebot) : displayNextStep()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,12 @@ export const ConversationContainer = ({
|
|||||||
onNewBlockVisible,
|
onNewBlockVisible,
|
||||||
onCompleted,
|
onCompleted,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const { typebot, updateVariableValue } = useTypebot()
|
const {
|
||||||
|
typebot,
|
||||||
|
updateVariableValue,
|
||||||
|
linkedBotEdgeIdsQueue,
|
||||||
|
popEdgeIdFromLinkedTypebotQueue,
|
||||||
|
} = useTypebot()
|
||||||
const { document: frameDocument } = useFrame()
|
const { document: frameDocument } = useFrame()
|
||||||
const [displayedBlocks, setDisplayedBlocks] = useState<
|
const [displayedBlocks, setDisplayedBlocks] = useState<
|
||||||
{ block: Block; startStepIndex: number }[]
|
{ block: Block; startStepIndex: number }[]
|
||||||
@@ -36,7 +41,14 @@ export const ConversationContainer = ({
|
|||||||
) => {
|
) => {
|
||||||
const currentTypebot = updatedTypebot ?? typebot
|
const currentTypebot = updatedTypebot ?? typebot
|
||||||
const nextEdge = currentTypebot.edges.find(byId(edgeId))
|
const nextEdge = currentTypebot.edges.find(byId(edgeId))
|
||||||
if (!nextEdge) return onCompleted()
|
if (!nextEdge) {
|
||||||
|
if (linkedBotEdgeIdsQueue.length > 0) {
|
||||||
|
const nextEdgeId = linkedBotEdgeIdsQueue[0]
|
||||||
|
popEdgeIdFromLinkedTypebotQueue()
|
||||||
|
displayNextBlock(nextEdgeId)
|
||||||
|
}
|
||||||
|
return onCompleted()
|
||||||
|
}
|
||||||
const nextBlock = currentTypebot.blocks.find(byId(nextEdge.to.blockId))
|
const nextBlock = currentTypebot.blocks.find(byId(nextEdge.to.blockId))
|
||||||
if (!nextBlock) return onCompleted()
|
if (!nextBlock) return onCompleted()
|
||||||
const startStepIndex = nextEdge.to.stepId
|
const startStepIndex = nextEdge.to.stepId
|
||||||
|
|||||||
@@ -18,10 +18,13 @@ const typebotContext = createContext<{
|
|||||||
linkedTypebots: LinkedTypebot[]
|
linkedTypebots: LinkedTypebot[]
|
||||||
apiHost: string
|
apiHost: string
|
||||||
isPreview: boolean
|
isPreview: boolean
|
||||||
|
linkedBotEdgeIdsQueue: string[]
|
||||||
setCurrentTypebotId: (id: string) => void
|
setCurrentTypebotId: (id: string) => void
|
||||||
updateVariableValue: (variableId: string, value: string) => void
|
updateVariableValue: (variableId: string, value: string) => void
|
||||||
createEdge: (edge: Edge) => void
|
createEdge: (edge: Edge) => void
|
||||||
injectLinkedTypebot: (typebot: Typebot | PublicTypebot) => LinkedTypebot
|
injectLinkedTypebot: (typebot: Typebot | PublicTypebot) => LinkedTypebot
|
||||||
|
popEdgeIdFromLinkedTypebotQueue: () => void
|
||||||
|
pushEdgeIdInLinkedTypebotQueue: (edgeId: string) => void
|
||||||
onNewLog: (log: Omit<Log, 'id' | 'createdAt' | 'resultId'>) => void
|
onNewLog: (log: Omit<Log, 'id' | 'createdAt' | 'resultId'>) => void
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
@@ -43,6 +46,9 @@ export const TypebotContext = ({
|
|||||||
const [localTypebot, setLocalTypebot] = useState<PublicTypebot>(typebot)
|
const [localTypebot, setLocalTypebot] = useState<PublicTypebot>(typebot)
|
||||||
const [linkedTypebots, setLinkedTypebots] = useState<LinkedTypebot[]>([])
|
const [linkedTypebots, setLinkedTypebots] = useState<LinkedTypebot[]>([])
|
||||||
const [currentTypebotId, setCurrentTypebotId] = useState(typebot.typebotId)
|
const [currentTypebotId, setCurrentTypebotId] = useState(typebot.typebotId)
|
||||||
|
const [linkedBotEdgeIdsQueue, setLinkedBotEdgeIdsQueue] = useState<string[]>(
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setLocalTypebot((localTypebot) => ({
|
setLocalTypebot((localTypebot) => ({
|
||||||
@@ -87,6 +93,12 @@ export const TypebotContext = ({
|
|||||||
return typebotToInject
|
return typebotToInject
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const pushEdgeIdInLinkedTypebotQueue = (edgeId: string) =>
|
||||||
|
setLinkedBotEdgeIdsQueue((queue) => [...queue, edgeId])
|
||||||
|
|
||||||
|
const popEdgeIdFromLinkedTypebotQueue = () =>
|
||||||
|
setLinkedBotEdgeIdsQueue((queue) => queue.slice(1))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<typebotContext.Provider
|
<typebotContext.Provider
|
||||||
value={{
|
value={{
|
||||||
@@ -98,6 +110,9 @@ export const TypebotContext = ({
|
|||||||
createEdge,
|
createEdge,
|
||||||
injectLinkedTypebot,
|
injectLinkedTypebot,
|
||||||
onNewLog,
|
onNewLog,
|
||||||
|
linkedBotEdgeIdsQueue,
|
||||||
|
pushEdgeIdInLinkedTypebotQueue,
|
||||||
|
popEdgeIdFromLinkedTypebotQueue,
|
||||||
currentTypebotId,
|
currentTypebotId,
|
||||||
setCurrentTypebotId,
|
setCurrentTypebotId,
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ type LogicContext = {
|
|||||||
apiHost: string
|
apiHost: string
|
||||||
typebot: PublicTypebot
|
typebot: PublicTypebot
|
||||||
linkedTypebots: LinkedTypebot[]
|
linkedTypebots: LinkedTypebot[]
|
||||||
|
pushEdgeIdInLinkedTypebotQueue: (edgeId: EdgeId) => void
|
||||||
setCurrentTypebotId: (id: string) => void
|
setCurrentTypebotId: (id: string) => void
|
||||||
updateVariableValue: (variableId: string, value: string) => void
|
updateVariableValue: (variableId: string, value: string) => void
|
||||||
updateVariables: (variables: VariableWithValue[]) => void
|
updateVariables: (variables: VariableWithValue[]) => void
|
||||||
@@ -149,8 +150,14 @@ const executeTypebotLink = async (
|
|||||||
nextEdgeId?: EdgeId
|
nextEdgeId?: EdgeId
|
||||||
linkedTypebot?: PublicTypebot | LinkedTypebot
|
linkedTypebot?: PublicTypebot | LinkedTypebot
|
||||||
}> => {
|
}> => {
|
||||||
const { typebot, linkedTypebots, onNewLog, createEdge, setCurrentTypebotId } =
|
const {
|
||||||
context
|
typebot,
|
||||||
|
linkedTypebots,
|
||||||
|
onNewLog,
|
||||||
|
createEdge,
|
||||||
|
setCurrentTypebotId,
|
||||||
|
pushEdgeIdInLinkedTypebotQueue,
|
||||||
|
} = context
|
||||||
const linkedTypebot = (
|
const linkedTypebot = (
|
||||||
step.options.typebotId === 'current'
|
step.options.typebotId === 'current'
|
||||||
? typebot
|
? typebot
|
||||||
@@ -165,6 +172,7 @@ const executeTypebotLink = async (
|
|||||||
})
|
})
|
||||||
return { nextEdgeId: step.outgoingEdgeId }
|
return { nextEdgeId: step.outgoingEdgeId }
|
||||||
}
|
}
|
||||||
|
if (step.outgoingEdgeId) pushEdgeIdInLinkedTypebotQueue(step.outgoingEdgeId)
|
||||||
setCurrentTypebotId(
|
setCurrentTypebotId(
|
||||||
'typebotId' in linkedTypebot ? linkedTypebot.typebotId : linkedTypebot.id
|
'typebotId' in linkedTypebot ? linkedTypebot.typebotId : linkedTypebot.id
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user