Docs

How bots work

A bot as a profile, where it can be, what it hears, stopping, channels and communities.

A bot is a profile

A bot is an ordinary federation profile marked as a bot. It has no devices and never signs in to the app: your program acts for it with the token. In chats the bot carries a "bot" badge, and its owner is shown only to the owner.

  • The username ends with bot (case does not matter) and shares the namespace of people and public chats.
  • The token is cbt_<bot id>_<43 characters>. The server keeps only its hash. A new token disables the old one at once: unfinished requests of the old token get 401, its webhook is removed, its long poll ends, and updates not yet received stay for the new token.
  • Deleting the bot revokes the token, removes the bot from every group and community and marks the profile deleted. Nobody can open a direct chat with a deleted bot.

Where a bot can be

  • Direct chat. Always started by a person, usually with "Start" (the bot gets /start). The person may stop the bot ("Stop bot", or by deleting the chat): then the bot cannot write to them until they restart it. The bot learns about stops and restarts through the my_chat_member update.
  • Groups and channels. Only when the bot has "Can be added to groups" and it was added by someone who may add members. The bot learns the chat's ID from my_chat_member when added and from every message it receives. A bot never becomes the owner of a group, channel or community.
  • Channels. In a channel a bot starts as a subscriber. To let it post, make it a publisher in the subscriber list; then it posts with sendMessage, and new posts reach it as channel_post.
  • Communities. A member who may manage the community adds the bot ("Add to community"). The bot gets a role of its own with the chosen permissions: it cannot be deleted or given to anyone else, and it disappears when the bot leaves. Room permissions apply to the bot as to any member.

What a bot hears

In direct chats and channels a bot gets everything. In groups and community rooms privacy mode applies: the bot gets only

  • commands (/command, and /command@bot_username only when it is its name);
  • messages that mention it;
  • replies to its messages.

It gets everything else when it has "Reads all messages in groups", or when its rights in the chat let it delete messages.

A bot never gets its own messages or other bots' messages. Service messages ("X added Y") do not reach bots. Direct chats with a bot create no contacts.

Restrictions

  • A bot does not start direct chats and cannot write to people who stopped it (bot_stopped).
  • A bot passes the same checks as a person: a chat closed by moderators, the word filter, blocks, the recipient's privacy settings. Such refusals come as 403 (errors).
  • Sending spends the same rate budget as a person's: 30 messages at once, then 5 per second.
  • A deleted bot, and a bot whose owner moderators suspended or deleted, fails token checks and gets no updates.

On this page