I want to make it so that when I press the keyboard next to the text input field, the bot sends inline_keyboard, but I can’t, if I try to write the code, then when I press /menu, it sends the message ‘Bot menu’ several times and increases by one, help me solve the problem
bot.onText(//menu/, (msg) => {
bot.sendMessage(msg.chat.id, "Bot menu", mainKeyboard);
});
const mainKeyboard = {
reply_markup: {
keyboard: [
[{text:'⭐️ chapter1', callback_data:'section1'}],
[{text:'⭐️ chapter2', callback_data:'section2'}],
[{text:'⭐️ chapter3', callback_data:'section3'}],
]
}
}
bot.on('message', (msg) => {
const chatId = msg.chat.id
const text = msg.text
if (text === '⭐️ chapter1') {
const section1Keyboard = {
reply_markup: {
inline_keyboard: [
[{ text: 'subsection 1.1', callback_data: 'subsection1_1' }],
[{ text: 'subsection 1.2', callback_data: 'subsection1_2' }],
[{ text: 'Назад', callback_data: 'back' }],
],
},
}
bot.sendMessage(chatId, 'you have chosen chapter 1', section1Keyboard);
} else if (text === '⭐️ chapter2') {
bot.sendMessage(chatId, 'you have chosen chapter 2');
} else if (text === '⭐️ chapter3') {
bot.sendMessage(chatId, 'you have chosen chapter 3');
}
})
I’m just trying to make bots, I don’t know what can be done in this situation, I’m starting to doubt that it is possible to connect a keyboard and inline_keyboard