A simple bot for Node.js, with plugins support.
Via npm on Node:
npm install simplebot
Reference in your program:
var simpletbot = require('simplebot');
Create, configure and launch a bot:
var bot = simplebot.createBot();
bot.use(plugin1);
bot.use(plugin2);
bot.use(plugin3);
bot.start();
A plugin can:
- Produce message to be processed by the bot and its plugins
- Emit outcoming message using the bot
- Subscribe to incoming message to the bot
A plugin is an object with methods:
.initialize(bot)
called when the plugin is added to the bot.start()
called whenbot.start()
is called.stop()
called whenbot.stop()
is called
Your plugin code can access and use all the Node.js ecosystem. It can call these bot methods:
bot.process(msg)
sending a message (simple number, string, object) to be processed by bot and its plugins, in asynchronous waybot.emit(msg)
emitting an outcoming message using the bot
Some plugins can subscribe to incoming message, or can be interested in process the outcoming messages:
bot.emitter(fn)
registering a function that receives amsg
parameter for each message emitted by the bot and its pluginsbot.subscribe(fn)
registering a function that receives and process amsg
parameter for each message received by the bot
See the test and samples folders for more detailed use cases.
git clone git://github.com/ajlopez/SimpleBot.git
cd SimpleBot
npm install
npm test
- Primes a prime number detector
MIT
- 0.0.1: Published
Feel free to file issues and submit pull requests — contributions are welcome<
If you submit a pull request, please be sure to add or update corresponding
test cases, and ensure that npm test
continues to pass.