EdJoPaTo / grammy-inline-menu

Inline Menus for Telegram made simple. Successor of telegraf-inline-menu.
MIT License
357 stars 44 forks source link

How to handle unsupported commands? #53

Closed expelliamus closed 4 years ago

expelliamus commented 4 years ago

Hi,

is there a way to handle all unsupported commands? Suppose I have:

 const menu = new TelegrafInlineMenu(ctx => ctx.i18n.t('welcomeMsg', {
    username: ctx.from.first_name
 }));
 menu.setCommand('start');

if the user write in the chat "hello world" or some other messages, I would like to display a default reply, how can I do this?

Thanks.

EdJoPaTo commented 4 years ago

you can use "native" telegraf for handling"unsupported" commands. Add a middleware after the middlewares which handle the supported commands. For example like this:

bot.command('start', ctx => ctx.reply('was started'))
bot.command(/.+/, ctx => ctx.reply('unsupported))

You can define any middleware in the last statement.

I personally prefer to reply with an explanation what happened and that the user did something unexpected. But containing something like 'You can open the main menu with /start' so the user only has to tap / click on that one to find his way. Alternatively you can use const middleware = menu.replyMenuMiddleware() and use this middleware to always respond with the menu.