Configuring the mini-learn menu button in Telegram Bot

telegram bot api set chat menu button
27 April 2025

Introduction to the mini-learn menu button in Telegram



The mini-learn menu button is one of the interesting features of Telegram bots that allows you to easily present various actions to users. Using the Telegram bot API, you can customize this menu and provide various options to your users.



To use this feature, you first need to use the setChatMenuButton method. This method allows you to configure the menu button for your bot and display different options like start, help, and other actions to the users. Working with this method is very straightforward.



As an example, suppose you want to add a button called “Help” to the mini-learn menu. This action gives users easy access to the necessary information. You can also add other buttons like “Settings” and “Contact Us.” This action enhances user interaction with your bot.



Next, we will provide a sample code that will create a new mini-learn menu for your Telegram bot. First, you need to have your bot token and then you can access the Telegram bot API using an HTTP POST request.


Sample code for configuring the mini-learn menu button


const TelegramBot = require('node-telegram-bot-api');
const token = 'YOUR_TELEGRAM_BOT_TOKEN';

const bot = new TelegramBot(token, { polling: true });

const menuButton = {
text: 'Help',
};

bot.setChatMenuButton(menuButton).then(() => {
console.log('Mini-learn menu button configured successfully.');
}).catch(err => {
console.error('Error configuring mini-learn menu button:', err);
});

Explanation of code line by line


Code:const TelegramBot = require('node-telegram-bot-api');

This line imports the Telegram bot library into our program.



Code:const token = 'YOUR_TELEGRAM_BOT_TOKEN';

This is where you specify the bot token you received from BotFather.



Code:const bot = new TelegramBot(token, { polling: true });

In this line, we create a new Telegram bot instance that is connected to the polling service.



Code:const menuButton = { text: 'Help' };

In this section, we define the mini-learn menu button and specify its text.



Code:bot.setChatMenuButton(menuButton).then(() => { ... });

In this line, we use the setChatMenuButton method to configure the mini-learn menu button, and upon success, a message will be logged.



Code:console.error('Error configuring mini-learn menu button:', err);

If there is an error configuring the mini-learn menu button, this line will log the error to the console.

FAQ

?

How can I remove the mini-learn menu button?

?

Can I add multiple buttons to the mini-learn menu?

?

Will the mini-learn menu buttons appear in all bots?