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

  • Ensure your bot is Installed across the pages of the site where you require 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);
});

Messenger Notifications

Messenger sends a limited set of events to the host page which can be used to determine user interaction during a conversation session. Current supported events are listed below.

Setup

Your host page can be configured as follows to respond to Messenger Notifications

const ServisbotApi = ServisBot.init({ ...your config params });
// Setup event listener to handle Messenger events
ServisbotApi.on('Messenger', (event) => {
    /*
    *   Each Messenger event has a type and a value
    *   the type is related to the specific interaction type
    *   of the event
    */
    console.log(`Type: ${event.type}, Value: ${event.value}`);
});

ROUNDEL events

Event fired when the user opens the Messenger Roundel

{
  "type": "ROUNDEL",
  "value": "Opened"
}

Event fired when the user closes the Messenger Roudel

{
  "type": "ROUNDEL",
  "value": "Closed"
}

CONVERSATION events

Event fired when the user interacts with the conversation for the first time during their session.

{
  "type": "CONVERSATION",
  "value": "First User Interaction"
}

Event fired when Messenger has loaded a conversation, and is ready to receive messages

{
  "type": "CONVERSATION",
  "value": "Ready"
}

Private Host Notifications

Private Host Notifications are notifications that do not get emitted to the Messenger host webpage. Private Host Notifications are captured by Messenger and handled internally.

There are currently two supported Private Host Notifications.

  1. SB:::UserInputDisabled - Will disable user input via the Text Input field at the bottom of the Messenger application.
  2. SB:::UserInputEnabled - Will enable user input via the Text Input field at the bottom of the Messenger application.

These can be configured as part of your flow using the hostNotification node and entering either value into the Notification Message field.

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