Docs

Commands

Bot commands, scopes, typed options, conditions and suggestions as the person types.

Commands are /names with descriptions that the app shows when someone types / in a chat with the bot. As in Discord, a command may have options with types, choices and suggestions from the bot.

Setting commands

curl -s -X POST "$API/setMyCommands" -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: application/json' -d @- <<'JSON'
{
  "commands": [
    { "command": "start", "description": "Start" },
    { "command": "weather", "description": "Weather in a city",
      "options": [
        { "name": "city", "description": "Where", "required": true, "autocomplete": true },
        { "name": "days", "type": "integer", "min_value": 1, "max_value": 7 }
      ] }
  ]
}
JSON
  • Names are lowercase Latin letters, digits and _; descriptions are up to 256 characters.
  • Up to 100 commands in one scope, at most 64 KiB together.
  • setMyCommands replaces every command of the scope; an empty list deletes them.

The app caches a chat's commands for five minutes, but sees changes at once when the bot makes them.

Scopes

scopeWhere it applies
{"type": "default"} (the default)Everywhere.
{"type": "all_private_chats"}In every direct chat.
{"type": "all_group_chats"}In every group and room.
{"type": "chat", "chat_id": "…"}In one chat the bot belongs to.

The most specific scope wins. A bot may have commands in up to 64 scopes.

How a command reaches the bot

An ordinary command. The app sends the command's text as the person's message, which everyone in the chat sees. The bot gets a message update and, when the command was picked from the list, the parsed options too:

"command": { "name": "weather", "options": { "city": "Almaty", "days": 3 } }

A command typed by hand reaches the bot as plain text, without options. In groups commands reach the bot in privacy mode too; /command@bot_username reaches only the bot with that name.

An ephemeral command ("ephemeral": true). Nothing is written to the chat, nobody else sees the invocation, and the bot gets an ephemeral_command with an interaction ID and answers with an ephemeral message (ephemeral messages).

Options

FieldType
namestringThe option's name.
descriptionstringA hint.
requiredbooleanRequired. Required options without a condition come first.
typestringstring (default), integer, number, boolean, user, date.
choicesarrayUp to 25 choices {"name", "value"}; other values are refused.
autocompletebooleanThe bot suggests values as the person types (instead of choices).
min_value, max_valuenumberBounds for integer and number.
min_length, max_lengthintegerLength for string, up to 1024.
shown_whenobjectA condition: the option exists only while another one has one of the values.

Values reach the bot by option name:

TypeJSON valueHow the person chooses
stringstringTypes text.
integer, numbernumberTypes a number.
booleantrue / false"Yes" or "No".
userprofile IDPicks a member of the chat.
datestring YYYY-MM-DDPicks a date.

The server itself refuses an unknown option, a value of the wrong type, out of bounds or not one of the choices, a person outside the chat, and a missing required option: the bot gets only checked values.

Conditions

An option with shown_when appears only while an earlier option has one of the values:

{ "command": "event", "description": "Event", "options": [
  { "name": "kind", "required": true, "choices": [
    { "name": "One-off", "value": "once" }, { "name": "Weekly", "value": "weekly" } ] },
  { "name": "date", "type": "date", "required": true,
    "shown_when": { "option": "kind", "values": ["once"] } }
] }

Here the date is required only for a one-off event. The server refuses a value of a hidden option.

Suggestions

For an option with "autocomplete": true the app asks the bot what to offer. The bot gets an autocomplete_query:

{ "id": "…", "from": {...}, "chat": {...}, "command": "weather",
  "options": {"days": 3}, "focused": "city", "query": "Al" }

and answers with up to 25 choices within 3 seconds, or the list stays empty:

curl -s -X POST "$API/answerAutocompleteQuery" -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{"autocomplete_query_id": "…", "choices": [{"name": "Almaty", "value": "Almaty"}, {"name": "Altai", "value": "Altai"}]}'

value must fit the option's type and bounds.

How it looks to people

Options are written right in the composer: /weather city:Almaty days:3. Above it the app shows the command with a pill per option and suggestions for the option under the caret: choices, the bot's answers, "Yes"/"No", members or a calendar. A wrong value turns red, and sending is refused until it is fixed.

On this page