Skip to content

Gateway Overview

The Gateway is a persistent WebSocket connection to Floodilka. Clients receive events through it (new messages, member joins, voice state changes, etc.) and send control commands (heartbeat, presence updates, member list requests).

Use the REST API for actions (send a message, create a channel) and the Gateway for subscribing to what happens.

The primary endpoint:

wss://gateway.floodilka.com/

In production fetch the current URL from REST first — that way your client picks up infrastructure migrations automatically:

Окно терминала
curl https://floodilka.com/api/v1/gateway/bot \
-H "Authorization: Bot YOUR_BOT_TOKEN"

Response:

{
"url": "wss://gateway.floodilka.com",
"shards": 1,
"session_start_limit": {
"total": 1000,
"remaining": 999,
"reset_after": 14400000,
"max_concurrency": 1
}
}
  • url — connect here. Can change during infrastructure work
  • session_start_limit — how many fresh IDENTIFY calls you can make. The budget drains fast if you’re stuck in an IDENTIFY → INVALID_SESSION → IDENTIFY loop

Append to the URL as a query string:

ParameterValuesDescription
v1Required. Protocol version. Omitting it gives 4012 INVALID_API_VERSION
encodingjsonMessage format. Only json is supported today
compressnone (default), zstd-streamPer-message compression via zstd

A typical URL:

wss://gateway.floodilka.com/?v=1&encoding=json

With zstd compression (useful for bots on large servers):

wss://gateway.floodilka.com/?v=1&encoding=json&compress=zstd-stream

Every message is a JSON object with four fields:

{
"op": 0,
"d": { "content": "hello" },
"s": 42,
"t": "MESSAGE_CREATE"
}
FieldWhen presentMeaning
opAlwaysOpcode. See Opcodes
dAlmost alwaysPayload. Shape depends on op or t
sOnly when op: 0Sequence number in this session. Remember it for heartbeats and RESUME
tOnly when op: 0Event type. See Events
import {WebSocket} from 'ws';
const ws = new WebSocket('wss://gateway.floodilka.com/?v=1&encoding=json');
ws.on('message', (raw) => {
const msg = JSON.parse(raw.toString());
if (msg.op === 10) {
// HELLO — start heartbeats and send IDENTIFY
setInterval(() => ws.send(JSON.stringify({op: 1, d: null})), msg.d.heartbeat_interval);
ws.send(JSON.stringify({
op: 2,
d: {
token: process.env.FLOODILKA_BOT_TOKEN,
properties: {os: 'linux', browser: 'mybot', device: 'mybot'},
},
}));
}
if (msg.op === 0 && msg.t === 'READY') console.log('ready', msg.d.user.username);
if (msg.op === 0 && msg.t === 'MESSAGE_CREATE') console.log('msg', msg.d.content);
});