1. Webchat
  2. Webchat control channels

Webchat

Webchat control channels

Types of control channels

Page control event :

  • An event sent from the webpage to the stub
  • Sent via a customEvent

Server control event:

  • A custom payload sent from the stub to the webpage.
  • A predefined function will be executed and the custom payload will become its arguments
  • The name of this function is specified as a tag on_server_control_event="handle_server_control_event"

Page_control_hook:

  • A function that is executed when the user sends a message.
  • The function return will be sent to the stub along with the users message

Handling page control event

  • Setup and embed your webchat into a webpage
  • In the webpage create a custom event with type "stubber_webchat_page_control_event"
        const event = new CustomEvent("stubber_webchat_page_control_event", {
  detail: {
    data: {
      my_data: {
        some: "data",
      },
      my_action: "my_action",
    }
  }
});

      
  • Now dispatch your event
        window.dispatchEvent(event);

      
  • The object details.data will be present under stubpost.data._incoming_webchat_data.webchat_control_event

image

Handling server control events

  • In your webpage define a function in the window
        <head>
  <script>
    function handle_server_control_event(payload) {
      console.log('server control event', payload)
    }
  </script>
</head>

      
  • In the webchat tag specify the name of the function
          <stubber-webchat
    profile_uuid="your profileuuid"
    on_server_control_event="handle_server_control_event"
  />

      
  • In the notification object in your stub add webchat_control_event to platforms.webchat
        {
  "platforms": {
    "webchat": {
      "sessionuuid": "~~stub.data._incoming_webchat_data.sessionuuid",
      "webchat_control_event": {
        "some":"data"
      }
    }
  }
}

      
  • The Webchat will execute the function "handle_server_control_event" in the webpage and pass {"some":"data"} into the function

image