Telegraf.js custom keyboard how to make a Back button?

998 Views Asked by At

I don't know how to return to the previous menu by clicking to Back button.

bot.command('course', ctx => {
    ctx.replyWithHTML('<b>Courses</b>', Markup.keyboard(
        [
            ['Editors', 'Reviews'],
            ['JS']
        ]
    ).resize())
})

bot.hears('JS', ctx => {
    ctx.replyWithHTML('<b>Courses</b>', Markup.keyboard(
        [
            ['Angular', 'React'],
            ['Node'], ['Back'],
        ]
    ).resize())
})

I can't understand what kind of bot. function use to solve my problem.

1

There are 1 best solutions below

1
On BEST ANSWER

I resolve it like this.

bot.hears(/course|Back/, ctx => { // <==== here we have regex and change command to hears
    ctx.replyWithHTML('<b>Courses</b>', Markup.keyboard(
        [
            ['Editors', 'Reviews'],
            ['JS']
        ]
    ).resize())
})

bot.hears('JS', ctx => {
    ctx.replyWithHTML('<b>Courses</b>', Markup.keyboard(
        [
            ['Angular', 'React'],
            ['Node'], ['Back'],
        ]
    ).resize())
})