Websocket Events
"Utilize WebSocket events for real-time updates in Bevatel, establishing a persistent connection to receive event-based information."
Use WebSocket events to get real-time updates
WebSockets creates a persistent connection between the client and the server allowing bi-directional communication. Bevatel supports a WebSocket connection to get real-time updates about the events happening on the platform. Any client can connect to the WebSocket URL in Bevatel and authorize themselves by providing the token and start receiving the updates. This guide will help you set up a WebSocket connection with Bevatel and integrate available events.
Note: This is an experimental feature. Documentation can change on every release, and there is no guarantee of backward compatibility. Please make sure that you are using the updated version of the implementation.
Why should I use a WebSocket connection?
Suppose you are building a client for Bevatel. For example, in An Android or iOS Client SDK, where you would need to listen to the latest messages to update the UI without a reload or An extension to the dashboard, if you want to improve an agent's productivity, you might need data in real-time.
Setup a WebSocket connection with Bevatel
To set up a WebSocket connection with Bevatel, you need to initiate a connection with the authentication pub-sub token provided by Bevatel. The URL for the connection is wss://<your-installation-url>/cable
. E.g.: wss://app.bevatel.com/cable
.
There are two types of pub-sub tokens available in Bevatel.
User PubSub Token: This token has the privileges of an agent/admin and would receive all of the events documented below. You can get the pub-sub token by calling the Profile API.
Contact PubSub Token: For every contact, Bevatel would generate a pub-sub token for every session they had. You can connect to the WebSocket using this token to get the updates of the current session. When you create a contact using the public APIs, you will receive
pubsub_token
the payload. This token only has access to the current session-related events, you would only receive the eventsconversation.created
,conversation.status_changed
,message.created
,message.updated
,conversation_typing_on
,conversation_typing_off
andpresence.update
.
Please refer to Client APIs to build real-time customer-facing integrations using Bevatel.
Note: This token may be rotated regularly based on your installation type, make sure that you are using the latest token.
Connect to Bevatel Websocket
You need to send a command "subscribe" to connect to Bevatel. It expects a pubSub token, accountId, and userId (if using a user token). Here is an example of how you can connect with Bevatel.
Publishing Presence to the WebSocket server
To keep your users online in Bevatel, you can send a presence update event to Bevatel every 30 seconds. This action would keep the status of the agent/contact online.
Update the presence of an agent/admin user
The payload that should be sent to the server for updating the presence of an agent/admin is as follows.
Update the presence of a contact
The payload that should be sent to the server for updating the presence of a contact is as follows.
Websocket Payload
Objects
An event can contain any of the following objects as a payload. Different types of objects supported in Bevatel are as follows.
Conversation
The following payload will be returned for a conversation.
Contact
The following payload will be returned for a contact.
User
The following payload will be returned for an agent/admin.
Message
Notification
The following payload will be returned for a notification.
Identifier
Each event will have an identifier
attribute which would be of the following format.
Message
Each event will have a message
attribute which we return the event name as well as the data associated with it. To see the list of events, see the documentation below.
Events
conversation.created
This event is sent when a new conversation is created. For contact pub sub token subscription, it sends only the events related to the session with which the pub-sub token is associated to.
Available to: agent/admin, contact
conversation.read
This event is sent to the agents/admins who access to the inbox when a message is read by a contact.
Available to: agent/admin
message.created
This event is sent to the agents, admins/contacts when a new message is created in a conversation they have access to.
Available to: agent/admin, contact
message.updated
This event is sent to the agents, admins/contacts when a message is updated in a conversation they have access to.
Available to: agent/admin, contact
conversation.status_changed
This event is sent to the agents, admins/contacts when a conversation status is updated.
Available to: agent/admin, contact
conversation.typing_on
This event is sent to the agents, admins/contact when a contact or an agent start typing a response.
Available to: agent/admin, contact
conversation.typing_off
This event is sent to the agents, admins/contacts when a contact or an agent ends up typing a response.
Available to: agent/admin, contact
assignee.changed
This event is sent to the agents/admins who have access to the inbox when the assigned is changed.
Available to: agent/admin
team.changed
This event is sent to the agents/admins who have access to the inbox when the team assignment is changed.
Available to: agent/admin
conversation.contact_changed
This event is sent to the agents/admins when a contact is merged. The conversation object will have the new contact reference.
Available to: agent/admin
contact.created
This event is sent to the agents/admins when a contact is created.
Available to: agent/admin
contact.updated
This event is sent to the agents/admins when a contact is updated.
Available to: agent/admin
presence.update
This event would be available for both agent and the contact, it returns the availability status of the users in the system. The presence event delivered to contacts won't have information about other contacts.
Available to: agent/admin
notification_created
Available to: agent/admin
Last updated