Hi everyone, hope someone of you can help me with this.
I'm starting with Telegraf and I'm trying to work with keyboards, so my scenario is:
When my bot hears 'status' he respond:
bot.hears(/status/i, ctx => {
return ctx.reply('Wich one of these you want check?', Extra.markup(
Markup.keyboard([
['One', 'Two', 'Three', 'Four']
], { columns: 4 })
.oneTime()
.extra()
))
})
What I want: When the user select one of these options, my bot will do something.
What I tried to do was:
bot.hears(/status/i, ctx => {
return ctx.reply('Wich one of these you want check?', Extra.markup(
Markup.keyboard([
['One', 'Two', 'Three', 'Four']
], { columns: 4 })
.oneTime()
.extra()))
})
bot.action(/.+/, (ctx) => {
return ctx.answerCallbackQuery(`Oh, ${ctx.match[0]}! Great choise`)
})
I know this is a dummy question, but I hope someone can help me.
Thanks!
Hi @mncustodio
Telegram keyboard is nothing more than shortcuts for text messages, in other words: bot don't see any difference between keyboard click and manually typed message.
Otherwise, bot.action will handle only callback queries, not text updates.
So there are two choices:
Markup.inlineKeyboard, and handle buttons with .action handler.bot.hears to listen for text messages from the keyboard.Thanks @dotcypress!
I'll try it and give you a feedback.
Thanks again @dotcypress!
It's working fine.