Spanish Total.js
English
Documentation For AI agents
Contents

WebSocket

Connect over WebSocket to receive messages, and send messages to a channel.

.md GitHub
On this page

A WebSocket client both receives messages and can send them. All messages are JSON text.

Connect

wss://sync.example.com/?token=YOUR_TOKEN&app=Dashboard
Query argumentMeaning
tokenAn access token, or the setup token.
appOptional. The name shown on the Clients page.

Use ws:// when OpenSync runs without HTTPS, for example ws://localhost:8000/?token=YOUR_TOKEN.

Right after the connection opens, OpenSync sends an init message:

{"type":"init","name":"Demo sync","version":1,"id":"OpenSync"}

name is the instance name from the Setup page. OpenSync sends init again to every connected client when someone clicks APPLY on the Setup page.

Receive messages

Every request to a channel that the token can read arrives as one message:

{"id":"24nad002tl50d","type":"application/json","channel":"orders","method":"POST","headers":{"host":"sync.example.com","connection":"keep-alive","content-type":"application/json","accept":"*/*","accept-language":"*","sec-fetch-mode":"cors","user-agent":"node","accept-encoding":"gzip, deflate","content-length":"24"},"ua":"","query":{},"body":{"id":1002,"total":49.9},"ts":"2026-11-19T07:37:50.820Z","ip":"203.0.113.10","files":[]}

Tell init apart from the other messages by "type":"init".

Send a message

Send a notify message with the channel and your data in body:

{"type":"notify","channel":"chat","body":{"text":"Hello"}}

Every client that can read chat receives it, the sender included:

{"id":"24nad007tl51d","type":"application/json","channel":"chat","method":"SOCKET","headers":{},"ua":"","query":{},"body":{"text":"Hello"},"ts":"2026-11-19T07:37:52.847Z","ip":"203.0.113.10","files":[]}

method is SOCKET, and headers and query are empty. You can name the data field data instead of body. Messages without a channel, or that are not JSON, are ignored.

When the connection closes

Close codeReason
4001The token is wrong, was removed, or your IP address is locked after failed attempts. See Access problems.

OpenSync does not keep messages for clients that are offline. Reconnect after a close; see Listen from Node.js.

Made in Europe