Naltox / telegram-node-bot

Node module for creating Telegram bots.
MIT License
721 stars 143 forks source link

Multiple commands #129

Open jokame opened 7 years ago

jokame commented 7 years ago

In the previous version, I could make something like

tg.router .when(['command', 'Command', 'COMMAND'], new CommandController())

Now I can't with the new version. Is the unique way to achieve this declare multiple times the "new TextCommand()"?

chiu0602 commented 7 years ago

Do you want to accept case insensitive commands? I guess you should use RegexpCommand.

ocordeiro commented 7 years ago

Really. I'am receiving this error using multiples commands array:

TypeError: command.test is not a function
at TelegramRoute.test (/node_modules/telegram-node-bot/lib/routing/TelegramRoute.js:33:25) 

Probably because of this implementation https://github.com/Naltox/telegram-node-bot/commit/865d9c435777889149567da8b6369e0e58a363e8#diff-5d0478b9911fd18a6c78d0b1bcd7b310R26 in 4.0 Version

MikhailMS commented 7 years ago

If you are planning to use RegexpCommand and you getting this error

TypeError: command.test is not a function
at TelegramRoute.test (/node_modules/telegram-node-bot/lib/routing/TelegramRoute.js:33:25)

Just pass an RegExp object rather than a string as it stated in Readme example. It should be something like this

.when(new RegexpCommand(new RegExp('query','i'), 'NameCommand'),
        new NameController())
ocordeiro commented 7 years ago

Thanks. but the README describes this structure and does not works

    .when(['/sum :num1 :num2'], new SumController())

https://github.com/Naltox/telegram-node-bot#scope-extensions

MikhailMS commented 7 years ago

Yeah, but it's completely different thing. This one is about RegExp and yours is about retrieving parameters. I have asked this one already, but still no answer. Worth digging previous version and see how it worked there.

Khalanar commented 7 years ago

Hi all, any luck with this? Im trying a similar thing and can't get it right.

Thanks!