Events
Your bot hears about changes over one long-lived HTTP connection (server-sent events). An event only says what changed, like "messages changed in this channel". Your bot then asks the API for the details.
Connecting
GET/events
GET /v1/events HTTP/1.1
Host: api.orbitapp.ir
Authorization: Bot 1234567890123456789.Qm9...
Accept: text/event-streamThe first event is always hello:
event: hello
data: {"stream":"7","ping_ms":25000}Every 25 seconds a : ping line keeps the connection alive. The server closes the stream after an hour, so just reconnect. If nothing arrives for a minute, assume the connection is dead and reconnect.
Event types
| Event | data | Meaning |
|---|---|---|
messages | {"channel_id": "…"} | Something changed in that channel: a new, edited, deleted, reacted or pinned message |
guild | {"guild_id": "…"} | A server's channels, roles, members or settings changed |
guilds | {} | Your bot joined or left a server |
interaction | {"interaction_id": "…"} | Someone used one of your bot's slash commands |
You only get messages for channels your bot can see. New event types may show up later, so skip the ones you don't know.
Getting new messages
messages doesn't say which message changed. Remember the last message ID you handled in each channel and ask for anything newer:
GET/channels/{channel_id}/messages?after={last_id}
On startup, fetch the latest message in each channel (?limit=1) and start from there, so your bot doesn't answer old messages. Do the same for new channels after a guild or guilds event.
Skip messages where author.bot is true, including your own. Otherwise two bots can end up talking to each other forever. Skip messages whose kind isn't default too: join messages are the lines that welcome new members.
Reconnecting
Events aren't replayed. After reconnecting, fetch everything after the last ID you saw in each channel. If reconnecting keeps failing, wait a bit longer each time: 1, 2, 4 seconds and so on, up to 30.