You can send custom events from Webchat to your website. This is useful if you want your website to perform an action when your user reaches a certain point in its conversation with your bot.

You will need:

  • A website with an embedded bot
  • Familiarity with JavaScript
1

Add a Send Custom Event Card

  1. In Botpress Studio, add a Send Custom Event Card to any Node:

  1. Set the Conversation ID to {{ event.conversationId }}
  2. Add anything you want to the Event field.

The Event field contents must be in JSON format.

2

Listen for the event on your website

Now, you can listen for the event in your website’s source code:

index.js
window.botpress.on('customEvent', (event) => {
    console.log('Custom event triggered: ', event);
    // Insert your code here
});

Now your website can respond to your custom event!