https://discord.gg/botpress logo
Issue with sendEvent from my website to Webchat
# 🤝help
m
My current workflow: 1. Start node will start the very first Standard node that actuall pull the context through api using Execute code card from the given client side input (some id to get the data from our api) send through sendMessage method from botpress react client 2. Once context is stored in conversation variable, it transitions based on the query 3. Moves to Autonomous node (which has access to Actions and perform multi turn conversation) Expected behaviour: 1. Bot is deployed on every pages on my website. As soon as user shifts to another page, the bot has to be updated with recent page context. 2. If user is in Article 1 page, starts the conversation (this will trigger start node.....rest of the flow). After few chats, he might move to another Article 2. Now I need botpress to get updated with the content of the Article 2 page without restarting the chat. Issue: 1. Frontend webchat is built using botpress react library. 2. In workflow canvas, I have the created the
Conversation (Advanced)
trigger node and connected to the same Standard node the Execute code for fetching context from api. 3. Issue1: When page event is sent to bot (using sendEvent()), this trigger node should kickstart the connected node. But it doesn't and conversation variables also not upgraded. 4. Issue2: After few chats, user might move to next page. During this time, the conversation is handled by Autonomous node. This node receives the event and sends message to webchat saying
It looks like the page or video has changed. If you'd like a summary, explanation, or have questions about the new content, just let me know!
this response is cool, but I want that Standard node to be triggered to fetch the recent data based on payload sent in sendEvent(payload).
Code snippet:
Copy code
ts
  const sendContextUpdateMessage = (articleId: number) => {
        if (client && conversationId) {
            const articleType = pathname.includes('/v/') ? 'video' : 'article';

            const contextUpdatePayload = {
                type: 'text',
                text: '', // Empty text as this is a system message
                conversationId,
                customData: {
                    articleId,
                    articleType,
                    isContextUpdate: true, // Flag to identify this as a context update
                    timestamp: Date.now(),
                },
            } as const;

            client.sendEvent(contextUpdatePayload);
        }
    };