首页 > 解决方案 > 如何使用 NodeJS 在 inlinekeyboard 中动态添加一行和两个按钮?

问题描述

我有一个名为“stateNames”的数组。我想在电报机器人的 inlineKeyboard 中显示数组中的元素。我想在一行中显示两个 stateNames 按钮。

但我不明白。我尝试了下面的代码,但它不起作用。

GitHub:https ://github.com/nilesh-kawar/Covid19-Stats-bot

请帮忙

bot.command('covid', (ctx) => {
getStates()

.then((stateNames) => {
    

    ctx.telegram.sendMessage(ctx.chat.id,'Choose State',
    {    
        reply_markup: {
            inline_keyboard : stateNames.map((item, index) => ([
                {
                    text: item,
                    callback_data: String(index),
                },
                {
                    text: item+1,
                    callback_data: String(index), 
                }
            ])), 
        }
    })  
})

})

标签: node.jsarraystelegramtelegram-bottelegraf

解决方案


推荐阅读