Skip to content

Commit

Permalink
fix(engine): 🐛 Webhook call on linked typebot
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Mar 31, 2022
1 parent 7f5d2f4 commit 86117d6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/bot-engine/src/components/ChatBlock/ChatBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const ChatBlock = ({
onBlockEnd,
}: ChatBlockProps) => {
const {
currentTypebotId,
typebot,
updateVariableValue,
createEdge,
Expand All @@ -50,6 +51,7 @@ export const ChatBlock = ({
onNewLog,
injectLinkedTypebot,
linkedTypebots,
setCurrentTypebotId,
} = useTypebot()
const { resultValues, updateVariables } = useAnswers()
const [processedSteps, setProcessedSteps] = useState<Step[]>([])
Expand Down Expand Up @@ -110,6 +112,7 @@ export const ChatBlock = ({
injectLinkedTypebot,
onNewLog,
createEdge,
setCurrentTypebotId,
})
nextEdgeId ? onBlockEnd(nextEdgeId, linkedTypebot) : displayNextStep()
}
Expand All @@ -118,7 +121,7 @@ export const ChatBlock = ({
step: currentStep,
context: {
apiHost,
typebotId: typebot.typebotId,
typebotId: currentTypebotId,
blockId: currentStep.blockId,
stepId: currentStep.id,
variables: typebot.variables,
Expand Down
5 changes: 5 additions & 0 deletions packages/bot-engine/src/contexts/TypebotContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ export type LinkedTypebot = Pick<
'id' | 'blocks' | 'variables' | 'edges'
>
const typebotContext = createContext<{
currentTypebotId: string
typebot: PublicTypebot
linkedTypebots: LinkedTypebot[]
apiHost: string
isPreview: boolean
setCurrentTypebotId: (id: string) => void
updateVariableValue: (variableId: string, value: string) => void
createEdge: (edge: Edge) => void
injectLinkedTypebot: (typebot: Typebot | PublicTypebot) => LinkedTypebot
Expand All @@ -40,6 +42,7 @@ export const TypebotContext = ({
}) => {
const [localTypebot, setLocalTypebot] = useState<PublicTypebot>(typebot)
const [linkedTypebots, setLinkedTypebots] = useState<LinkedTypebot[]>([])
const [currentTypebotId, setCurrentTypebotId] = useState(typebot.id)

useEffect(() => {
setLocalTypebot((localTypebot) => ({
Expand Down Expand Up @@ -95,6 +98,8 @@ export const TypebotContext = ({
createEdge,
injectLinkedTypebot,
onNewLog,
currentTypebotId,
setCurrentTypebotId,
}}
>
{children}
Expand Down
5 changes: 4 additions & 1 deletion packages/bot-engine/src/services/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type LogicContext = {
apiHost: string
typebot: PublicTypebot
linkedTypebots: LinkedTypebot[]
setCurrentTypebotId: (id: string) => void
updateVariableValue: (variableId: string, value: string) => void
updateVariables: (variables: VariableWithValue[]) => void
injectLinkedTypebot: (typebot: Typebot | PublicTypebot) => LinkedTypebot
Expand Down Expand Up @@ -142,7 +143,8 @@ const executeTypebotLink = async (
nextEdgeId?: EdgeId
linkedTypebot?: PublicTypebot | LinkedTypebot
}> => {
const { typebot, linkedTypebots, onNewLog, createEdge } = context
const { typebot, linkedTypebots, onNewLog, createEdge, setCurrentTypebotId } =
context
const linkedTypebot =
step.options.typebotId === 'current'
? typebot
Expand All @@ -156,6 +158,7 @@ const executeTypebotLink = async (
})
return { nextEdgeId: step.outgoingEdgeId }
}
setCurrentTypebotId(linkedTypebot.id)
const nextBlockId =
step.options.blockId ??
linkedTypebot.blocks.find((b) => b.steps.some((s) => s.type === 'start'))
Expand Down

3 comments on commit 86117d6

@vercel
Copy link

@vercel vercel bot commented on 86117d6 Mar 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 86117d6 Mar 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 86117d6 Mar 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-typebot-io.vercel.app
builder-v2-git-main-typebot-io.vercel.app
app.typebot.io

Please sign in to comment.