Commands
app.command binds a /command to a page or a dialogue, and app.syncCommands puts the commands in Telegram's command menu (the ☰ button next to the message field), so the menu always matches your code.
const app = new EasyTG()
.command('start', home, { description: 'Main menu' })
.command(['find', 'search'], search, { description: 'Search the catalog', params: (args) => ({ q: args }) })
.command('feedback', feedbackForm, { description: 'Send us feedback' })
.command('settings', settings, { description: 'Settings', chats: 'private' })
.command('debug', debugPage); // no description: works, but isn't listed
bot.use(app);
await app.syncCommands(bot); // at startup- The target is registered if it isn't yet. A page opens like
app.open(a reply to the command), a dialogue starts in a new message. paramsturns the text after the command into params:/find green teagivesargs === 'green tea'. Withoutparamsthe target gets none, so it can't require params./command@yourbotworks too;/command@otherbotis left alone.- A command leaves an active dialogue (with
dialogues.cancelOnCommand, the default) and a page's text input. - Commands easytg doesn't know go on to your own handlers (
bot.command(...)afterbot.use(app)). A/start <payload>deep link is handled first; other/startpayloads reach yourstartcommand. - Names are 1–32 lowercase letters, digits or underscores; defining one twice throws.
Private chats and groups
chats: 'private' or chats: 'groups' limits where a command works; elsewhere it goes on to your handlers. syncCommands sets one list for all chats and, when some commands are only for private chats or only for groups, separate lists for those (Telegram shows the most specific list). Lists for a kind of chat without commands of its own are deleted.
Ephemeral commands
ephemeral: true makes a command private in groups (Bot API 10.2): syncCommands lists it with is_ephemeral, so Telegram sends it to the bot only, and the page or dialogue answers the sender only, "Only you can see this". The group never sees either. Good for settings, personal lists, help:
app.command('mytasks', myTasks, { description: 'Your tasks', ephemeral: true, chats: 'groups' });The answer replies to the ephemeral command, which Telegram accepts from a bot that isn't an admin too. Any ephemeral message the bot receives is answered ephemerally, whether or not its command was declared so. In private chats nothing changes. See examples/team.ts.
Translated descriptions
A description can be a function of the language. syncCommands then sets one list per language of i18n.messages / i18n.locales (Telegram uses two-letter codes, so pt-br counts as pt), plus the default list in fallbackLocale:
app.command('help', help, { description: (locale, t) => t('commands.help') });Try it
A whole bot. On the docs site it runs next to the code, in a Telegram simulator: press ☰ Menu next to the message field.