ba0f3 / telebot.nim

Async Telegram Bot API Client implement in @Nim-Lang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I catch an unknown command?

facorazza opened this issue · comments

I'd like to use a proc like this one in events.nim:

proc onUnknownCommand*(b: TeleBot, cb: CommandCallback) =
  b.commandCallbacks["-"].add(cb)

but I'm not sure how things are handled so I'm asking for help.

Perhaps, this new proc is not necessary. However, we must be sure not to catch commands already processed with onCommand().

Well, we can pass them to a catch all handler, or pass them to onUpdate when no match command found.

My idea would be to have a structure like this one:

bot.onUpdate(updateHandler)
bot.onCommand("command_a", commandAHandler)
bot.onCommand("command_b", commandBHandler)
bot.onCommand("command_c", commandCHandler)
bot.onUnknownCommand(unknownCommandHandler)

I guess if we did like so:

bot.onCommand("command_a", commandAHandler)
bot.onCommand("command_b", commandBHandler)
bot.onCommand("command_c", commandCHandler)
bot.onUpdate(updateHandler)

where the unknown command is caught as a regular message by onUpdate(), it would work as well, but it might be confusing to mix messages and commands into one proc when commands usually have their own.

Could we overload onCommand() to catch unknown commands? I would still prefer to use a separate proc though.