WebSocket
Guides, route-group overviews, and live schema entry points for the Plexichat backend.
WebSocket gateway
The Plexichat gateway delivers real-time events and accepts client signaling for heartbeats, identification, presence, typing, voice, encryption ratchets, and collaborative fabric updates.
Use this page for the overall lifecycle. See Connection, Events, Intents, Opcodes, and Close codes for details.
Gateway URL
Connect to wss://api.plexichat.com/gateway with a WebSocket client. The URL includes the
API version and any gateway parameters that your server deployment requires.
Lifecycle
You follow these steps for every session:
- Open a WebSocket connection to the gateway URL.
- Receive
HELLO(op: 10) with the heartbeat interval. - Send
IDENTIFY(op: 2) with your session or bot token and desired intents. - Receive
READY(op: 0,t: READY) with yoursession_idandresume_gateway_url. - Send
HEARTBEAT(op: 1) on the interval fromHELLOand handleHEARTBEAT_ACK(op: 11). - Consume
DISPATCH(op: 0) events for the intents you requested. - Resume with
RESUME(op: 6) or reconnect when the connection drops.
For payload details and timings, see Gateway connection flow.
Payload shape
Every gateway frame uses the same envelope:
{"op": 0, "d": {}, "s": 1, "t": "EVENT_NAME"}
| Field | Description |
|---|---|
op |
Opcode that identifies the action. See Gateway opcodes. |
d |
Event or command data. Schema varies by opcode and event. |
s |
Sequence number. Set only on dispatch payloads (op: 0). Save it for resume. |
t |
Dispatch event type when op is DISPATCH. For example, MESSAGE_CREATE. |
You use sequence numbers to detect gaps. If you disconnect, you pass the last
s you received in RESUME.
Opcode families
The gateway defines its opcodes in src/api/websocket/opcodes.py. You use
these families:
- Core lifecycle —
HELLO(10),IDENTIFY(2),HEARTBEAT(1),HEARTBEAT_ACK(11),RESUME(6),RECONNECT(7),INVALID_SESSION(9),REQUEST_GUILD_MEMBERS(8), andDISPATCH(0). - Presence and members —
PRESENCE_UPDATE(3) andVOICE_STATE_UPDATE(4). - Server status —
SERVER_STATUS(12) andVERSION_CHECK(13). - Voice signaling —
VOICE_CONNECT(20) throughVOICE_QUALITY(26). - Interactions —
INTERACTION_CREATE(30) andINTERACTION_RESPONSE(31). - Typing —
TYPING_START(40) andTYPING_STOP(41). - Encryption ratchet —
RATCHET_UPDATE(50) for channel-level key rotations. - Real-time fabric — Artifact opcodes
ARTIFACT_SUBSCRIBE(60),ARTIFACT_UNSUBSCRIBE(61),ARTIFACT_OP(62),ARTIFACT_SYNC(63),ARTIFACT_OP_REJECTED(68) and PlexiSum workbook opcodesSUM_SUBSCRIBE(64),SUM_UNSUBSCRIBE(65),SUM_OP(66),SUM_SYNC(67).
All values, directions, and purposes are listed in Gateway opcodes.
Events and intents
- You receive application data through dispatch events (
op: 0,tset). The full catalog is in Gateway events. It includes session events, message and reaction events, channel and guild events, presence and typing, voice, invites and threads, relationships, notifications, ratchet updates, and artifact and workbook events. - You declare which event families you want with the
intentsbitmask inIDENTIFY. If you omit an intent, the gateway withholds matching events. The bitmask, default set, and privileged intents are in Gateway intents. Artifacts needARTIFACTS(1<<20); PlexiSum workbooks needSUMS(1<<21).
Next steps
- Follow Gateway connection flow to implement identify, heartbeat, and resume.
- Handle dispatch payloads from Gateway events and filter by Gateway intents.
- Send and receive signaling frames from Gateway opcodes.
- Handle disconnects from Gateway close codes.