Dynamically creating inline keyboard buttons Markup Telegraf?
See original GitHub issueHello, I am trying to send buttons to my telegram bot using the telegram bot api. For now, for creating the buttons, I have to hard code the values in the fields but lets say I want to create the inline keyboard buttons dynamically through an array and passing the array index and the array values as parameters. How should i go about it ? This is what I tried so far.
import Telegraf from 'telegraf';
const { Markup } = Telegraf;
const buttons = ['low', 'middle', 'high'];
const inlineKeyboard = Markup
.inlineKeyboard(
buttons.map((button) => {
Markup.callbackButton(button, button);
})
)
.resize()
.extra();
Thanks
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
Dynamic inlineKeyboard buttons (nodejs, telegraf)
I'm working with telegraf API and this is how i create a static one: const bookMenu = Telegraf.Extra .markdown() .markup((m) ...
Read more >Inline Keyboards And Menus | Telegram Bot Development
Telegram bot development using node.js and Telegraf API. What you will learn: Inline Keyboards and creating menus.
Read more >telegraf-inline-menu
Inline Menus for Telegraf made simple.. Latest version: 6.3.0, last published: a year ago. Start using telegraf-inline-menu in your project ...
Read more >Inline Keyboard Markup - YouTube
Build Telegram Chat Bots with Node.js using the Modern Telegraf Framework ...
Read more >Building your First Telegram Bot using Node.js and Telegraf
To add more functionality let's write code that shows you images of animals when you click inline keyboard buttons. Create a res folder...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Here you go. The buttons have to be passed as an array. You can have 8 buttons in one row so if you want less you have to split your array / create chunks. Here is example with lodash chunks.
@shnigi How, exactly, do you handle
.action()for dynamically created buttons?