I.R.M.A. the Interactive Robotic Messaging Assistant - A Yammer bot written in JavaScript for node.js
MIT License
I.R.M.A. is chat bot for your Yammer network. It's written in JavaScript and runs inside a node.js environment.
I.R.M.A. comes with a small number of plugins:
Required none-core modules:
Some plugins require additional modules:
Get the code:
git clone git://github.com/maxkueng/irma.git
cd irma
Install dependencies:
npm install
Run:
npm start
Copy the distribution configuration file and edit it:
cp config.dist.json config.json
vim config.json
yammer.email
: The email address used with your yammer account.yammer.api.consumer_key
: Your Yammer API OAuth consumer key.yammer.api.consumer_secret
: Your Yammer API OAuth consumer secret.plugins
: An array of plugin names to be loadedspaghetti.chef_user_id
: User ID of the spaghetti chef. You only need thiswebinterface.ip
: IP the web interface plugin should listen on.webinterface.port
: Port the web interface plugin should listen on.You can add additional properties to the configuration file and access them in your plugin code.
Here's what a configuration file might look like. It's usually located at
./config.json
{
"yammer" : {
"email" : "[email protected]",
"api" : {
"consumer_key" : "UkjUbkjBKVHJfGhygygGGG",
"consumer_secret" : "iuhuHYFUhvghyvJYfjhyVTDKbbVYTFytuyfUYvvVVVy"
}
},
"plugins" : [
"webinterface",
"spaghetti"
]
"webinterface" : {
"ip" : "0.0.0.0",
"port" : 1337
},
"spaghetti" : {
"cron_open" : "0 0 9 * * 5",
"cron_close" : "0 45 11 * * 5",
"chef_user_id" : "777124"
}
}
Please node that the cron module has a bug. Sunday is 1
, not 0
. So 5
is Thursday, not Friday.
y
: The instance of the Yammer client. Use it to send and receive messages.config
: The configuration objectmessages
: The none-boring messages manager used to add and get messages.cron
: The cron instance used to schedule codelogger
: The logger instanceHere's what a plugin that does nothing might look like. ./plugins/nothing.js
exports.init = function (y, config, messages, cron, logger) {
logger.info("Initializing the nothing plugin. Whoooo!!");
// Your plugin code goes here
};
The messages manager keeps a list of one or more messages per message type. This means you can say the same thing in different ways so your bot will apear less boring.
Example:
messages.add('saysomething', 'Something');
messages.add('saysomething', 'Another thing');
messages.add('saysomething', 'Anything');
messages.add('tellthetime', 'The time is [time].');
messages.add('tellthetime', 'It is exactly [time].');
console.log(messages.get('saysomething')); // Will print one of the the above.
console.log(messages.get('tellthetime', {
'time' : new Date()
}));
Send a message to your network:
var messageText = messages.get('saysomething');
y.sendMessage(function (error, message) {
logger.info('Sent message with ID ' + message.id());
}, messageText);
Reply to a message:
var messageText = messages.get('saysomething');
y.sendMessage(function (errr, message) {
logger.info('Sent message with ID ' + message.id());
}, messageText, { 'reply_to': 999876543 }); // <-- this is the message id
Send direct message:
var messageText = messages.get('saysomething');
y.sendMessage(function (error, message) {
logger.info('Sent message with ID ' + message.id());
}, messageText, { 'direct_to': 1234567 }); // <-- this is the user id
Note: The bot will only receive messages that are either sent to it directly or mention it in the message body.
Receive channel message:
y.on('message', function (message) {
logger.info('Received message with ID ' + message.id());
});
Receive reply to a thread:
var thread = y.thread(9997654767); // <-- this is the thread id
thread.on('message', function (message) {
logger.info('Received message with ID ' + message.id());
});
Read the cron documentation. Sending a message is the same as above.
Send a message at 9.15am every day:
new cron.CronJob('0 15 9 * * *', function () {
y.sendMessage(function (error, message) {
logger.info('Sent message with ID ' + message.id());
}, "This is the daily announcement!");
});
Examples:
logger.info('Something happened');
logger.warn('Something strange happened');
logger.error('Something bad happened');
More documentation will be added some time in the future. For now, please look at the existing plugins. It's easy. You'll get it.