Button¶
A tappable item in the Telegram menu. A button has a name and, when tapped,
runs a function on your server and sends the result back to the
chat.
Buttons and categories together form the menu tree
under the top-level menu key in your config file. A button
does the work; a category only opens a submenu.
What a button looks like¶
Buttons appear on the keyboard under the message box, two per row by default. The name you choose is the text on the key, so keep it short enough to read on a phone. See Menu → How the Telegram menu looks.
The parts of a button¶
Every line controls one part of the button
- name: Restart nginx # (1)!
type: button # (2)!
icon: "🔄" # (3)!
function: command # (4)!
command: "systemctl restart nginx" # (5)!
confirm: true # (6)!
- The text on the key in Telegram. It must be unique among its neighbours in the same menu.
- Always
buttonhere. Usecategoryinstead when you want a submenu. - Optional emoji shown before the name. It is decoration only and changes nothing about what runs.
- Which function to use.
commandis the built-in one that runs a shell command. - What the
commandfunction runs. Anything you could type in a terminal works here. - Optional. Ask "Are you sure?" before running. Leave it out for anything that only reads.
What happens when you tap it¶
- The bot posts a short Running line so you know it started.
- The command runs on the machine where the bot is running.
- The output comes back as a code block, with the exit code and how long it took. Long output arrives as several messages in a row.
- You stay on the same menu you were on, so Back still leaves that category.
Common buttons¶
Icons¶
icon puts an emoji in front of the name. It is purely cosmetic, so you can
change or remove it at any time without touching what the button runs.
An icon only changes the label
Ask before risky buttons¶
Add confirm: true and the bot asks Yes or Cancel first. Use it for anything
that stops a service, deletes data, or reboots the machine. The prompt expires
after a while (five minutes by default).
Read Confirmation for when it is worth asking and how to change the waiting time.
Settings for one button only¶
Most global settings can be overridden on a single button, which is handy when one job behaves differently from the rest:
Override settings for one slow job
timeout gives this one command longer to finish, workdir chooses the
directory it runs in, and env adds environment variables just for it.
Values for the function¶
Write function values directly on the button. command, path, and args
are shortcut fields for parameters with those names. Custom names such as
url, host, unit, and lines work in the same way.
Pass custom values
Do not put these values inside params:. Every key must match a parameter
declared by the selected function. validate reports
unknown names, missing required values, and invalid int or bool values.
Configuration¶
For every field a button accepts, see Configuration → Menu.