Getting Started
Create a Bot
Create a bot using any of these methods:
- Web UI: Server Settings → Bots → Create Bot
- CLI:
meepachat bots create --username mybot --server <serverID> - API:
POST /api/botswith a human user’s Bearer token
Add Bot to a Server
The bot is automatically added to the server specified during creation. To add it to additional servers:
- Web UI: Server Settings → Bots → Add Existing Bot
- CLI:
meepachat bots add-to-server <botID> --server <serverID> - API:
POST /api/servers/{serverID}/bots/{botID}
Connect to the Gateway
Open a WebSocket connection to
/api/bot-gateway using the bot token. The bot receives a ready event with its current state.Connection
Endpoint:GET /api/bot-gateway
Authenticate using the Authorization header:
<bot_id>.<secret> and are obtained when creating a bot via POST /api/bots.
Passing the token as a
?token= query parameter works but is deprecated. Use the Authorization: Bot <token> header instead.Connection Parameters
| Parameter | Value |
|---|---|
| Max message size | 4096 bytes |
| Ping interval | Server sends WebSocket ping frames every 30 seconds |
| Pong timeout | Bot must respond within 60 seconds or the connection is closed |
| Write deadline | 10 seconds |
| Channel subscription | Bots receive events only from channels they are members of |
Ready Event
Immediately after connecting, the bot receives aready event containing:
- Bot user object (id, username, avatar, etc.)
- All servers the bot is a member of, with channels the bot has been added to
- All DM channels the bot is a participant in
Client-to-Server Events
ping
Heartbeat. The server responds with a pong event.
subscribe
Subscribe to additional channels at the WebSocket level. Use this for channels added to the bot’s membership after the initial connection, or for DM channels opened after connect. This only adds the channel to the in-memory subscription — the bot must already be a member of the channel to receive events via the REST API.
typing
Broadcast a typing indicator to a channel. The bot must be subscribed to the channel.
typing event with the bot’s user ID.
Server-to-Client Events
Bots receive the same real-time events as human WebSocket clients. All events follow this structure:| Event | Description |
|---|---|
pong | Response to bot ping event |
message.created | A new message was posted in a subscribed channel |
message.updated | A message was edited |
message.deleted | A message was deleted |
reaction.sync | Reactions were added or removed (full state) |
channel.created | A new channel was created in a bot’s server |
channel.updated | A channel was renamed, moved, or reordered |
channel.deleted | A channel was deleted |
typing | A user is typing in a subscribed channel |
presence.initial | All currently online user IDs (sent on connection) |
presence.update | A user went online or offline |
server.added | Bot was added to a new server (includes server and channel list) |
Sending Messages
Bots send messages via the standard REST API using their bot token:message.created event over the gateway.
Full Example Bot (Node.js)
Reconnection Strategy
Bots should implement reconnection with exponential backoff:- Wait 1 second before the first retry
- Double the wait time on each failure (max 30 seconds)
- Reset the wait time after a successful connection
- After reconnecting, the server sends a new
readyevent with current state - Use the
readyevent to resync channel subscriptions and local state
Lifecycle Events
When a bot is removed from a server viaDELETE /api/servers/{serverID}/bots/{botID}, the server forcibly closes the bot’s gateway connection. The bot should reconnect and will receive an updated ready event reflecting the new server list.
Rate Limits
Bots share the same rate limits as human users:| Limit | Value |
|---|---|
| HTTP API | 240 requests/minute, burst 60 (per IP) |
| WebSocket message size | 4096 bytes |
| Gateway connections | One per bot token (new connections disconnect the previous one) |
The WebSocket gateway connection itself is not rate limited. Once connected, real-time events bypass the HTTP rate limiter. Only REST API calls (sending messages, etc.) count against the rate limit.
Security Best Practices
- Keep bot tokens secret: Never commit tokens to source control or expose them in client-side code.
- Rotate compromised tokens: If a token is leaked, regenerate it immediately via
POST /api/bots/{botID}/regenerate-token. - Validate event data: Do not trust message content blindly. Sanitize before processing or displaying.
- Log security events: Track unusual patterns such as spam or unauthorized access attempts.
- Use environment variables: Store the bot token in an environment variable, not in source code.
