$ npm install seed-slackbot
Options should contain a token field that is string.
Options could contain a processSlackbot field, that is an optional boolean and false by default
Options could contain a processReplies field, that is an optional boolean and false by default
Options could contain a processSubtypes field, that is an optional boolean and false by default
Options could contain a processSelf field, that is an optional boolean and false by default
Options could contain a mock field, that is an optional boolean and false by default
var Slack = require('seed-slackbot');
var slack = new Slack({ token: 'ABC123', processReplies: true });
var slack = new Slack('ABC123'); // shorthandUsed to call slack web api
slack.request('chat.postMessage', msg, function(err, result) {});Get channel by name or id
var channel = slack.channel('C1234');Get user by name or id
var user = slack.user('U4567');Get IM by id or user name or user id
var im = slack.im('C5678');Get current user
var self = slack.self();Send message to channel
slack.send('1234', 'Hello world!');
slack.send({ type: 'message', channel: '1234', text: 'Hello world!' }); // alternativeGet slackbot's internal duplex stream
var stream = slack.stream();
stream.pipe(through(function(message, enc, cb) {
if (message.type === 'presence_change' && message.user.id === slack.self().id) {
this.push(['test', 'I\'m back!']);
}
cb();
})).pipe(stream);var Slack = require('seed-slackbot');
var slack = new Slack({ token: process.env.SLACK_TOKEN });
slack.on('message', function(data) {
slack.send(channel, message);
slack.request('chat.postMessage', msg, function(err, result) {
});
});It's possible to mock slack transports to test slackbot and it's dependents
var slack = new Slack({ mock: true });
// simulate a message coming from slack
slack.mock(JSON.stringify({
channel: 'C123',
type: 'message',
text: 'Hello world',
user: 'U123'
}));
// examine messages going to slack
slack.on('mock:message', function(payload) {
console.log(JSON.parse(payload));
});
// examine requests going to slack and simulate slack response
slack.on('mock:request', function(data) {
// data.url
// data.method 'rtm.start'
// data.data {}
// data.callback
data.callback(null, { data: { users: [{}], channels: [{}], groups: [], ims: [{}], ...} });
});Buffer stream until slack is connected
MIT