Skip to content

Support multiple Telegram bot tokens in a single instance #99

@bchewy

Description

@bchewy

Problem

Currently, Spacebot only supports a single Telegram bot token per instance. When running multiple agents that each need their own Telegram bot identity (separate BotFather tokens), the only option is to run multiple Spacebot processes — one per bot.

This adds unnecessary operational overhead (separate containers, separate configs, separate data dirs) for what should be a single multi-agent deployment.

Current Architecture (blockers)

  1. Config modelMessagingConfig.telegram is Option<TelegramConfig>, not a Vec or map. [messaging.telegram] can only appear once in TOML.

  2. Adapter name collisionTelegramAdapter::name() returns the hardcoded string "telegram". The MessagingManager stores adapters in a HashMap<String, ...> keyed by this name, so registering a second adapter overwrites the first.

  3. Source-based response routing — Inbound messages are tagged with source: "telegram". Outbound responses are routed by looking up message.source in the adapter map. No way to distinguish which bot received the message.

Proposed Solution

Allow named Telegram adapter instances, similar to how you might configure multiple of any service:

[messaging.telegram.community]
enabled = true
token = "env:TELEGRAM_TOKEN_COMMUNITY"

[messaging.telegram.personal]
enabled = true
token = "env:TELEGRAM_TOKEN_PERSONAL"

With bindings referencing the specific instance:

[[bindings]]
agent_id = "community-bot"
channel = "telegram.community"

[[bindings]]
agent_id = "personal-bot"
channel = "telegram.personal"

Changes needed

  • config.rs: Change telegram: Option<TelegramConfig> to telegram: HashMap<String, TelegramConfig> (or BTreeMap), add backward compat for the unnamed single-token form
  • telegram.rs: Accept a name/id parameter in new(), use it in name() (e.g. "telegram.community") and as the source field on inbound messages
  • main.rs: Loop over Telegram configs and register each as a separate adapter
  • Bindings: channel field matches the qualified adapter name
  • TelegramPermissions: Per-adapter rather than shared

Use Case

Running two Telegram bots (each with distinct bot identities/usernames) bound to different agents in the same Spacebot instance. Currently requires two separate containers as a workaround.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions