WebSockets (Socket.IO)
🔔 Connect your scenarios and web-app in real-time
Last updated
Was this helpful?
🔔 Connect your scenarios and web-app in real-time
Last updated
Was this helpful?
What is WebSocket
The WebSocket API, built on technology, is an advanced feature that makes it possible to open a two-way interactive communication session between a user's browser and a server. Through this API, you can send messages to the server and receive event-driven responses, all without the need to continuously poll the server for replies.
1) Select the app you want to add a WebSocket to
2) Go to the Plugins section and install the Socket.io plugin.
Alert users with Toast notifications
Receive signals about changes in systems and refresh data instantly
Build interactive messengers 💬
Build scenarios with messages for specific users (alerts, notifications and etc.).
Create a scenario that calls socket plugin (send PUSH-message step)
Set "Event name" to alert
Configure your message.
There are two options for configuring the message: simple and complex.
Simple notification:
Complex notification (with notification settings like page to display on, position, duration, etc.)
Example of a message:
Message in the app:
Create a scenario that calls socket plugin (send PUSH-message step)
Add a refresher to the page (if needed)
The Refresher web-plugin (indicate the event_name
):
Scenario with the same event_name
:
Message: no need here (although you can combine refresher and user notifications)
Event name: the same event_name
UserID: set *
if you want to broadcast the message. set user's ID if you want to send a message to a certain user.
Here is how it works:
Go to WebSocket Page
Create a scenario, add Send PUSH-message step (it is a part of Socket.io plugin):
Configuring the step:
UserID: set *
if you want to broadcast the message. set user's ID if you want to send a message to a certain user (in our case — testUser)
Event name: the first parameter of socket event (eventName
)
Message: the second parameter of socket event (args
)
Here is how it works (we send objects to the scenario, the web-page is refreshed without reload):
You can use any WebSocket API (Socket.IO) client in any app.
Directual offers a standard endpoint for connection to WebSockets: https://api.directual.com
You can see how to connect and receive messages from the Platform in the code below:
If you use :
Refresh the page (e.g. update the content after submitting the form — that is an alternative to )
If you use external front-end (e.g., ):
Notifications are based on . Find the full list of parameters
You can find an example template with Socket.IO support in section.
(for example, the user's ID is testUser
)
Have a look at the boilerplate, :