Nanfeng

Notes on software development, code, and curious ideas

Configuring a Telegram Bot Menu Button

Set the lower-left menu button to open a Web App:

1
2
3
4
5
6
7
8
9
10
11
12
13
import { Bot } from "https://deno.land/x/grammy@v1.25.0/mod.ts";

const bot = new Bot('BOT_TOKEN');

await bot.api.setChatMenuButton({
menu_button: {
type: 'web_app',
text: 'Open Web App',
web_app: { url: 'https://example.com' }
}
});

bot.start();

Web App menu button

Alternatively, publish bot commands:

1
2
3
4
5
6
7
await bot.api.setMyCommands([
{ command: 'one', description: 'First action' },
{ command: 'two', description: 'Second action' },
{ command: 'three', description: 'Third action' },
]);

console.log(await bot.api.getMyCommands());

Command menu

Changes may not appear immediately because Telegram clients cache menu configuration.

+