Reputation: 15
I have an array of messages containing some text and an inline keyboard with "delete" button.
bot.command('items', ctx => {
items.forEach(async data => {
await ctx.reply(data.Title,
Markup.inlineKeyboard([Markup.button.callback("delete item", "DeleteItem")]));
})
})
And I have a function bot.action for the delete buttons on my inline keyboard. How do I pass a parameter to the bot.action so I can delete the item via the delete button.
bot.action("DeleteItem", async ctx => {
ctx.reply("deleting item");
})
Upvotes: 0
Views: 4878
Reputation: 79
For delete message, you can use:
bot.action('delete', ctx => ctx.deleteMessage())
As you can see from examples/echo-bot-module.js.
If you need pass a parameter to the bot.action
, you may try:
bot.action(/^data-(\d+)$/, (ctx) => {
return ctx.answerCbQuery(`Param: ${ctx.match[1]}! 👍`)
})
// And send with callback data
Markup.button.callback('Button', `data-${Math.round(Math.random()*1000)}`)
Upvotes: 2