Skip to content

Concepts

Understanding the architecture will help you build better bots. Here’s how the pieces fit together.

The SDK has four layers, from high-level to low-level:

LayerWhat it does
BotDeveloper-facing API with @event and @command() decorators
CommandsCommand parsing, argument extraction, Context object
REST ClientHTTP requests to the Syncopate API (send messages, manage channels)
SSE GatewayReal-time event stream via Server-Sent Events

You’ll mostly interact with the Bot layer. The other layers work behind the scenes.

1. bot.run() called
2. REST: POST /api/auth/login (bot token → session)
3. REST: GET /api/workspaces (discover workspace + channels)
4. SSE: Connect to /api/events/stream
5. SSE: Receive events → dispatch to handlers
6. (Loop until disconnected or stopped)

When a message arrives:

  1. The SSE Gateway receives a message.created event
  2. The Bot builds a Message model from the payload
  3. It resolves the Channel and User references
  4. It dispatches to your on_message / messageCreate handler
  5. If the message starts with the command prefix, it also dispatches to the matching command handler

Bots authenticate with a bot token (prefixed bot_). The SDK exchanges this token for a session on startup. You never need to manage sessions manually.

Bots can only see channels in their workspace. When the bot connects, it fetches the channel list and caches it. New channels are added to the cache via channel.created events.

  • Events — every event your bot can listen to
  • Commands — registering and handling commands