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

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.



Solution 1:[1]

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())
})

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hamroev Sodikjon