fix(engine): 🐛 Webhook call on linked typebot
This commit is contained in:
@ -42,6 +42,7 @@ export const ChatBlock = ({
|
|||||||
onBlockEnd,
|
onBlockEnd,
|
||||||
}: ChatBlockProps) => {
|
}: ChatBlockProps) => {
|
||||||
const {
|
const {
|
||||||
|
currentTypebotId,
|
||||||
typebot,
|
typebot,
|
||||||
updateVariableValue,
|
updateVariableValue,
|
||||||
createEdge,
|
createEdge,
|
||||||
@ -50,6 +51,7 @@ export const ChatBlock = ({
|
|||||||
onNewLog,
|
onNewLog,
|
||||||
injectLinkedTypebot,
|
injectLinkedTypebot,
|
||||||
linkedTypebots,
|
linkedTypebots,
|
||||||
|
setCurrentTypebotId,
|
||||||
} = useTypebot()
|
} = useTypebot()
|
||||||
const { resultValues, updateVariables } = useAnswers()
|
const { resultValues, updateVariables } = useAnswers()
|
||||||
const [processedSteps, setProcessedSteps] = useState<Step[]>([])
|
const [processedSteps, setProcessedSteps] = useState<Step[]>([])
|
||||||
@ -110,6 +112,7 @@ export const ChatBlock = ({
|
|||||||
injectLinkedTypebot,
|
injectLinkedTypebot,
|
||||||
onNewLog,
|
onNewLog,
|
||||||
createEdge,
|
createEdge,
|
||||||
|
setCurrentTypebotId,
|
||||||
})
|
})
|
||||||
nextEdgeId ? onBlockEnd(nextEdgeId, linkedTypebot) : displayNextStep()
|
nextEdgeId ? onBlockEnd(nextEdgeId, linkedTypebot) : displayNextStep()
|
||||||
}
|
}
|
||||||
@ -118,7 +121,7 @@ export const ChatBlock = ({
|
|||||||
step: currentStep,
|
step: currentStep,
|
||||||
context: {
|
context: {
|
||||||
apiHost,
|
apiHost,
|
||||||
typebotId: typebot.typebotId,
|
typebotId: currentTypebotId,
|
||||||
blockId: currentStep.blockId,
|
blockId: currentStep.blockId,
|
||||||
stepId: currentStep.id,
|
stepId: currentStep.id,
|
||||||
variables: typebot.variables,
|
variables: typebot.variables,
|
||||||
|
@ -13,10 +13,12 @@ export type LinkedTypebot = Pick<
|
|||||||
'id' | 'blocks' | 'variables' | 'edges'
|
'id' | 'blocks' | 'variables' | 'edges'
|
||||||
>
|
>
|
||||||
const typebotContext = createContext<{
|
const typebotContext = createContext<{
|
||||||
|
currentTypebotId: string
|
||||||
typebot: PublicTypebot
|
typebot: PublicTypebot
|
||||||
linkedTypebots: LinkedTypebot[]
|
linkedTypebots: LinkedTypebot[]
|
||||||
apiHost: string
|
apiHost: string
|
||||||
isPreview: boolean
|
isPreview: boolean
|
||||||
|
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
|
||||||
@ -40,6 +42,7 @@ 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.id)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setLocalTypebot((localTypebot) => ({
|
setLocalTypebot((localTypebot) => ({
|
||||||
@ -95,6 +98,8 @@ export const TypebotContext = ({
|
|||||||
createEdge,
|
createEdge,
|
||||||
injectLinkedTypebot,
|
injectLinkedTypebot,
|
||||||
onNewLog,
|
onNewLog,
|
||||||
|
currentTypebotId,
|
||||||
|
setCurrentTypebotId,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
@ -28,6 +28,7 @@ type LogicContext = {
|
|||||||
apiHost: string
|
apiHost: string
|
||||||
typebot: PublicTypebot
|
typebot: PublicTypebot
|
||||||
linkedTypebots: LinkedTypebot[]
|
linkedTypebots: LinkedTypebot[]
|
||||||
|
setCurrentTypebotId: (id: string) => void
|
||||||
updateVariableValue: (variableId: string, value: string) => void
|
updateVariableValue: (variableId: string, value: string) => void
|
||||||
updateVariables: (variables: VariableWithValue[]) => void
|
updateVariables: (variables: VariableWithValue[]) => void
|
||||||
injectLinkedTypebot: (typebot: Typebot | PublicTypebot) => LinkedTypebot
|
injectLinkedTypebot: (typebot: Typebot | PublicTypebot) => LinkedTypebot
|
||||||
@ -142,7 +143,8 @@ const executeTypebotLink = async (
|
|||||||
nextEdgeId?: EdgeId
|
nextEdgeId?: EdgeId
|
||||||
linkedTypebot?: PublicTypebot | LinkedTypebot
|
linkedTypebot?: PublicTypebot | LinkedTypebot
|
||||||
}> => {
|
}> => {
|
||||||
const { typebot, linkedTypebots, onNewLog, createEdge } = context
|
const { typebot, linkedTypebots, onNewLog, createEdge, setCurrentTypebotId } =
|
||||||
|
context
|
||||||
const linkedTypebot =
|
const linkedTypebot =
|
||||||
step.options.typebotId === 'current'
|
step.options.typebotId === 'current'
|
||||||
? typebot
|
? typebot
|
||||||
@ -156,6 +158,7 @@ const executeTypebotLink = async (
|
|||||||
})
|
})
|
||||||
return { nextEdgeId: step.outgoingEdgeId }
|
return { nextEdgeId: step.outgoingEdgeId }
|
||||||
}
|
}
|
||||||
|
setCurrentTypebotId(linkedTypebot.id)
|
||||||
const nextBlockId =
|
const nextBlockId =
|
||||||
step.options.blockId ??
|
step.options.blockId ??
|
||||||
linkedTypebot.blocks.find((b) => b.steps.some((s) => s.type === 'start'))
|
linkedTypebot.blocks.find((b) => b.steps.some((s) => s.type === 'start'))
|
||||||
|
Reference in New Issue
Block a user