Notifications

Our messenger supports more interactions than just user messages. It is possible for our bots send and receive commands straight from the host page where our messenger is configured.

Pre-Prerequisites

  • Make sure that your bot is Installed across the pages of the site where you want our messenger to appear, and configured appropriately.
  • Also make sure that the domain where you have your bot displayed is whitelisted in your endpoint

Host Notifications

The host webpage of our ServisBOT Messenger can receive notifications from our server (internally known as HostNotification) HostNotifications can be sent by as a Botnet Action or Node and are emitted to the host webpage by our messenger. To listen out for these notifications you can do the following.

const ServisBotApi = ServisBot.init({ ... }); //Initial configuration of our messenger
ServisBotApi.on('notification', function(message) {
    //  At the moment the message is just a simple string notification
    console.log(message);
});

Page Events

Sending a Notification from Host Page to Bot can be done using page events. You use the following command to send the page event

const context =  {
    "alias":"my-alias",
    "body":{
        "some": {
            "data": {
                "stored":"here"
            }
        }
    }
 }
ServisBotApi.pageEvent(context);

data provided in the body of the event data will be available at payload.user.context.

A string is also supported for sending the alias only without the body

ServisBotApi.pageEvent('my-alias');

For setting up the worker look here