https://discord.gg/botpress logo
Trigger different workflows based on website page ...
# 🤝help
a
Objective I want my Botpress webchat bot to send a different opening message depending on which page of my website the user is on, without the user having to type anything. For example: - /faq → bot says "Do you have any questions?" - /contact → bot says "Hey, you can ask your questions to me or I can connect you with someone." - /listings → bot says "Looking for a house?" - / (home) → bot follows its normal default flow Issue I am not sure what the correct and recommended approach is to link a page URL to a specific workflow in Botpress Studio, and how to catch the trigger reliably in a condition expression. What I have tried Approach 1 — sendEvent Sending a custom event from the website on page load:
Copy code
window.addEventListener('load', () => {
  if (window.botpress) {
    window.botpress.sendEvent({
      type: 'trigger',
      payload: { action: 'listings_page' }
    });
  }
});
Then trying to catch it in a condition node with event.payload.action === "listings_page". However I could not confirm whether this is the correct path to access the payload in a workflow condition. Approach 2 — sendMessage Sending a silent trigger message based on the current page path:
Copy code
window.addEventListener('load', () => {
  if (window.botpress) {
    const path = window.location.pathname;
    if (path === '/faq') window.botpress.sendMessage('faq_page');
    else if (path === '/contact') window.botpress.sendMessage('contact_page');
    else if (path === '/listings') window.botpress.sendMessage('listings_page');
  }
});
Then routing it in the Router workflow using event.payload.text === "faq_page". Not yet fully tested and unsure if this is best practice or if the trigger message is visible to the user. Context Using Botpress Webchat Do you have any advice/right approach on this problem? Feel free to answer. Thanks in advance!
l
Hey @astonishing-waitress-91471 I confirmed with one of the egineers that the correct approach would be via Custom Event!
Try that out and let me know how it goes please 😄