You can programmatically send a message to your bot on the user’s behalf using JavaScript.
You will need:
  • A website with an embedded bot
  • Familiarity with JavaScript

Send a message on the user’s behalf

To send a message on a user’s behalf, use the sendMessage method wrapped in an event listener:
window.botpress.on('webchat:ready', () => {
  const message = "Hi there!"; // Replace with your own message
  window.botpress.sendMessage(message);
});
This snippet:
  1. Waits until Webchat is open and ready to receive messages
  2. Sends the message on behalf of the user
The message won’t send until the user has voluntarily opened the Webchat window.

Start the conversation on the user’s behalf

To proactively open Webchat and start a conversation on the user’s behalf when they visit your website:
window.botpress.on('webchat:initialized', (event) => {
    window.botpress.open()
})

window.botpress.on('webchat:ready', () => {
    const message = "Hi there!"; // Replace with your own message
    window.botpress.sendMessage(message);
});
This snippet:
  1. Waits until Webchat is initialized
  2. Opens Webchat
  3. Waits until Webchat is ready to receive messages
  4. Sends the message on behalf on the user’s behalf