Docs

Bots and bridges

Who may create bots, the demo bot, webhooks, mirroring Telegram channels and importing stickers.

Bots

People create bots themselves in the app, and the bots' programs run anywhere and talk to the server over the HTTP Bot API (https://<domain>/bot/v1/<method>). No separate bot service is needed.

Who may create bots

Without settings, everyone may create up to 20 bots. Otherwise a JSON file in --bot-config sets the policy:

{
  "everyone": { "canCreate": false, "maximumBots": 0 },
  "roles": {
    "developers": { "canCreate": true, "maximumBots": 50 }
  },
  "profileRoles": {
    "<profile id>": ["developers"]
  }
}
FieldMeaning
everyoneEveryone's rights: canCreate and maximumBots.
rolesNamed sets of the same rights.
profileRolesWhich roles which profiles have.

A person gets the most generous of the rights of everyone and their roles. These roles exist only in the bot settings and are unrelated to the federation roles of moderation.

The demo bot

The server runs @demo_bot itself, which shows every bot capability: buttons, commands with suggestions, ephemeral messages. Its owner is the federation's service profile. To turn it off: --no-demo-bot. The demo bot also does not start when someone already holds the name demo_bot.

Webhooks

A bot gets updates either by requesting them from the server or by webhook, where the server sends them to the bot's address. By default webhooks to private addresses (the local network, localhost) are forbidden, so a bot cannot be used to reach internal services. For development on your own machine the --bot-private-webhooks flag allows them. Do not turn it on for a public server.

Bridges: Telegram channels

The bridge mirrors public Telegram channels into the federation: a person searches for a Telegram channel by link or name, and a mirrored channel with new posts appears in Comon, marked "Mirrored from Telegram".

python3 tools/mvp-stack.py enable-bridge
python3 tools/mvp-stack.py up

The command writes the federation's policy bridges.json, the bridge process settings bridge.json (with one shared token) and adds the bridge service. The bridge and the server talk only inside the Docker network. Change the policy in bridges.json, then run up.

Reading through a service account

Without an account the bridge reads the channels' web preview: only the latest ~20 posts are visible, and edits and deletions arrive late. With a service account the bridge reads Telegram through TDLib and sees edits and deletions at once.

  1. On my.telegram.org, sign in with the service account's number (not a personal one) and create an application.

  2. Put its keys into stack.env and run up:

    TELEGRAM_API_ID=<id>
    TELEGRAM_API_HASH=<hash>
  3. Sign the account in once: the command asks for the number, the code from Telegram and the two-step password, if there is one.

    python3 tools/mvp-stack.py bridge-login

The session lives in the bridge-tdlib volume. One account joins about 500 channels; past that, mirrors get new posts but not edits.

Policy (bridges.json)

{
  "networks": {
    "telegram": {
      "title": "Telegram", "usernamePrefix": "telegram_", "linkHosts": ["t.me", "telegram.me"],
      "url": "http://bridge:8090", "token": "<16+ characters>",
      "mediaBudgetBytes": 10737418240, "maximumPortals": 1000,
      "allow": [], "deny": [], "keepPolledMinutes": 60
    }
  },
  "everyone": { "canMirror": true, "mirrorsPerDay": 10 },
  "roles": { "moderator": { "canTakeDown": true } },
  "profileRoles": { "<profile id>": ["moderator"] }
}
FieldMeaning
mediaBudgetBytesHow much media all mirrors of the network keep. Past the budget, media stays a link. 10 GiB by default.
maximumPortalsHow many mirrored channels there may be, stopped ones included. 1000 by default.
allow, denyChannel names in lowercase, without @. An empty allow allows all.
everyone, roles, profileRolescanMirror and mirrorsPerDay: who may mirror and how many new channels a day; canTakeDown: who may stop mirrors.

Stopping a mirror

A person with canTakeDown opens the mirrored channel's page and chooses "Stop mirroring". Posts and media are deleted for everyone, and the channel can never be mirrored again. To keep a channel from being mirrored in the first place, add it to deny.

Importing stickers from Telegram

People can import Telegram sticker sets by link. For that the federation needs a Telegram bot of its own: create one with @BotFather and give the server a file with its token, --telegram-bot-token-file=<file>. Without it importing is off. The limit is 10 imports a day per person (stickers).

On this page