Bots
What Comon bots can do, how to create a bot and send the first message.
A bot is a federation profile run by your program. The program runs anywhere and talks to the federation server over HTTP: it receives updates (messages, button presses, commands) and calls methods (send a message, answer a press, set commands).
Requests follow the Telegram Bot API: POST /bot/v1/<method>, the token in a header, an answer
of {"ok": true, "result": …}.
API basics
Requests, the token, answers and errors.
Updates
Long polling, signed webhooks and every kind of update.
Methods
All 17 methods: parameters and results.
Commands
Commands with typed options and suggestions.
Buttons
Buttons in messages and answers to presses.
Personal bots
A bot that answers someone's direct chats on their behalf.
What bots can do
- Talk in direct chats. A person finds the bot by its @username and presses "Start". The bot answers with ordinary messages with formatting and buttons.
- Work in groups, channels and communities. A bot is added as a member; in a channel it can publish posts, in a community it gets a role of its own.
- Commands with a suggestion list, typed options (a number, a date, a member, a choice) and suggestions from the bot itself as the person types.
- Buttons in messages: the bot answers with a toast, a dialog or a link; buttons can also open an address or copy text.
- Ephemeral messages only one person sees, like ephemeral answers in Discord.
- Personal bots: a person connects a bot to their direct chats, and it answers on their behalf.
A bot cannot start a direct chat first, and never sees messages of other bots or its own.
Quick start
Create a bot
In the app, open Settings › Bots › My bots › Create a bot. Choose a name and a username, which
must end with bot, such as weather_bot.
The app shows a token like cbt_<bot id>_<secret>. Copy it right away: it is shown only once.
Whoever has the token controls the bot. If you lose it, issue a new one on the bot's card ("Issue a
new token"); the old one stops working at once.
Check the token
export TOKEN='cbt_...'
export API='https://comon.chat/bot/v1' # your federation's address
curl -s -X POST "$API/getMe" -H "Authorization: Bearer $TOKEN"{"ok": true, "result": {"id": "…", "is_bot": true, "first_name": "Weather", "username": "weather_bot",
"can_join_groups": false, "reads_all_messages": false, "supports_personal": false}}Get the first message
Find the bot in the app by its @username, press "Start" and write it something. Then:
curl -s -X POST "$API/getUpdates" -H "Authorization: Bearer $TOKEN" \
-H 'Content-Type: application/json' -d '{"timeout": 30}'The answer holds a message update with chat.id.
Answer
curl -s -X POST "$API/sendMessage" -H "Authorization: Bearer $TOKEN" \
-H 'Content-Type: application/json' \
-d '{"chat_id": "<chat.id>", "text": "Hi!", "buttons": [[{"text": "More", "callback_data": "more"}]]}'Complete examples in Python and Node.js are in examples. To see every capability
live, talk to the built-in @demo_bot, unless your server turned it off.
Bot settings
On the bot's card in My bots the owner changes the name, description, "About" line, avatar and three switches:
| Switch | Meaning |
|---|---|
| Can be added to groups | The bot can be added to a group, channel or community. Without it the bot lives only in direct chats. |
| Reads all messages in groups | The bot gets every message of groups and rooms, not only commands, mentions and replies to it (privacy). |
| Can be a personal bot | People can connect the bot as a personal bot. |
How many bots someone may create is the federation's decision: 20 per person by default (bot policy).