depoio/node-telegram-bot

Improve documentation on use of Bot commands

iambibhas opened this issue · 3 comments

I see here that it's possible to parse commands with this library, but there are no documentation/examples of it. Can you please provide some detailed doc?

The example only mentions .on('message', function (message) { ... } where message.text has the command and the text. Is it possible to do something like .on('start', function (message) { ... } or .on('help', function (message) { ... }?

rdev commented

It's possible.
When bot receives "/whatever" it triggers "whatever" event, so you can do .on('whatever'. function(message){ //do stuff });
You can also send "/whatever argument1 argument2" etc. Then you should do like so:

.on('wharever', function(message, args){
    if(args){ //To avoid crashing if no arguments specified
        console.log(args[0]); // -> "argument1"
        console.log(args[1]); // -> "argument2"
    }
});

@fivepointseven awesome. This should be on the readme file as the commands are the most basic part of any bot.

Will do thanks.