I’m trying to make a Telegram bot that shows a list of drinks and their prices. I want to create multiple inline buttons in a single row, but I’m having trouble figuring out how to do it.
Here’s what I’m working with:
const drinks = {
soda: '1.50',
juice: '2.00',
water: '1.00'
}
// How can I create buttons for each drink?
bot.command('menu', (ctx) => {
// Need help here
})
I want to show ‘Drink Menu’ once at the top, then have buttons for each drink and its price. I can’t seem to use a loop inside the ctx.reply function. Any ideas on how to make this work? Thanks!
Having worked on Telegram bots before, I can offer some insights. The key is to use the Markup.inlineKeyboard() method from the Telegraf library. You’ll want to create an array of button objects first, then pass that to the inlineKeyboard method.
This creates a single row with all drink buttons. Adjust the ‘columns’ value to change the layout. Remember to handle the callback queries for these buttons in your bot logic.