telekit-cmd
The module that simplifies work with commands in telekit
Install
npm:
$ npm install telekit telekit-cmd --save
yarn:
$ yarn add telekit telekit-cmd
Usage
const telekit = require('telekit');
const telecmd = require('telekit-cmd');
const bot = telekit(options);
bot.use(telecmd);
bot.on('/ping', (context) => {
context.chat.sendMessage({
text: 'Pong!',
});
});
Documentation
Coming soon...
Examples
context.command
const bot = telekit(options);
bot.use(telecmd);
bot.message = (context) => {
if (context.command.name == 'hello') {
return context.chat.sendMessage({
text: 'Glad to see you!',
});
}
};
Events
const bot = telekit(options);
bot.use(telecmd);
bot.on('command', (context) => {
context.chat.sendMessage({
text: `Command ${context.command.name} is not implemented 😞`,
});
});
bot.on('/meow', (context) => {
context.chat.sendMessage({
text: 'Woof, woooof-woof! 🐶',
});
});
Method command
for the instance
const bot = telekit(options);
bot.use(telecmd);
bot.command = (context) => {
if (context.command.name == 'source') {
context.chat.sendMessage({
text: '[Source code available on Github](https://github.com/telekits/telekit-cmd) ❤️️',
parse_mode: 'markdown',
});
}
}
Method command
for the custom helpers
const bot = telekit(options);
bot.use(telecmd);
bot.use(class MyBestClassHelper {
command(context, next) {
if (context.command.name == 'start') {
return context.chat.sendMessage({
text: 'Welcome to My Super Awesome Bot! 😊',
});
}
next();
}
});
LICENSE
MIT