具有多个触发器的电报机器人 .hears() 方法?

Telegram bot .hears()-method with multiple triggers?

我正在使用 node.js 和 telegraf 开发电报聊天机器人。

有没有办法在电报机器人的 bot.hears 方法中使用多个触发器,例如使用 || 时的 if 语句? 我希望如果用户输入菜单,就会出现一个菜单,当用户输入回来时,同样的菜单也会出现。

现在我必须写两次相同的方法,像这样:

bot.hears('Menu', ctx =>
    {
        ctx.telegram.sendMessage(ctx.chat.id, 'These are our products.',
                {
                     //show menu
                })

    })

bot.hears('Back', ctx =>
    {
        ctx.telegram.sendMessage(ctx.chat.id, 'These are our products.',
                {
                     //show menu
                })

    })

正在查看 .hears() documentation;

您可以使用 RegEx 作为触发器;

例如,像 /Menu|Back/ 这样的正则表达式将同时触发 /Menu/Back


examples uses this method. Take a look at the source 之一,了解实施的总体思路。