Platform
Getting Started
So, what we can do with the Platform?
Platform Introduction
General organization's settings
Platform's Glossary
Channels
Channels Introduction
Adding a Telegram channel
Adding a Web channel
Creating a Script to use the Web Channel
Adding Viber channel
Adding a Facebook Channel
Adding a Twitter channel
How a SMS Integration Works
WebSocket Connection
Contacts and Messages
Contacts Introduction
Contact's messages
Select a Message to Schedule for Later
Adding Media to the message
Contact Fields
Static and Dynamic Groups
Importing Contacts
Flows
Flows introduction
Flows Creation
Flow editor and tools
Action cards
Decision cards
Call Webhook: Making requests to external services
Split by Intent: Using Classifiers
Import and export flows
Expressions and Variables
Triggers and Campaigns
Adding a trigger
Triggers Types
Tell a flow to ignore triggers and keywords
Campaign introduction
How to create a Campaign
Editing events
Bothub
- All Categories
- Platform
- Channels
- WebSocket Connection
WebSocket Connection
Updated
by Paulo Bernardo
The WebSocket Server uses socketCluster on version 9
Establishing the connection to the WebSocket Server
To start a socket connection you will need to do the following:const socket = socketCluster.connect(options);
Whereoptions
is an object with the following structure:const options = {
After that, the WebSocket Server will be listening to future events, such as
hostname: <hostName>, // Socket Server URL
query:{
channelUUID: <channelUuid>, // Push ChannelUuid
hostApi:<hostApi> // Push hostApi URL
}
}registerUser
andsendMessageToChannel
that will be emitted from the declaredsocket
variable.Registering the user
Before exchanging messages, the user must be registered, user registration should be the first thing to be done after establishing the connection.
For that, an eventregisterUser
should be emitted, without arguments, and with a callback function. The callback function will handle the following response from the WebSocket Server.
Example:socket.emit('registerUser', {}, (_response) => {
Response Example:
const res = JSON.parse(_response);
console.log(res.urn);
});{
The
urn: "xxxxxxxxxxx-xxxxxxxx"
}urn
field, represents the current Socket Session Id.Receiving Messages from the WebSocket Server
After user registration, the current Socket Instance must be subscribed to handle messages from the WebSocket Server. Example on how to subscribe:socket.subscribe(sessionUrn, (data) => {
Where
if(data.to === sessionUrn) {//check msg destination
console.log(data);
}
});data
is the response that our platform sent.Sending Messages to the WebSocket Server
To send a message to the WebSocket Server, thesendMessageToChannel
must be emitted, with the following arguments:
Example:text
: The user message text.userUrn
: The sessionurn
received when registering the user.socket.emit("sendMessageToChannel", {
text: "Hello",
userUrn: sessionUrn
})