mokbot
v1.0.0
Published
``` _____ _ _ _ _ _ _ / ____| | | | | | | | | | | | | (___ | | __ _ ___| | __ | |__ ___ | |_ | |_ ___ ___| |_ ___ _ __ \___ \| |/ _` |/ __| |/ / |
Downloads
3
Readme
_____ _ _ _ _ _ _
/ ____| | | | | | | | | | | |
| (___ | | __ _ ___| | __ | |__ ___ | |_ | |_ ___ ___| |_ ___ _ __
\___ \| |/ _` |/ __| |/ / | '_ \ / _ \| __| | __/ _ \/ __| __/ _ \ '__|
____) | | (_| | (__| < | |_) | (_) | |_ | || __/\__ \ || __/ |
|_____/|_|\__,_|\___|_|\_\ |_.__/ \___/ \__| \__\___||___/\__\___|_|
install (todo)
npm install slack-bot-tester
example test using tape
Let's say you have a bot that says 'hello' when you say hi to it, and it reacts with a :heart: when you tell it 'you rock'. Here is how you test it.
var test = require('tape');
var botTester = require('slack-bot-tester');
test('simple test', function (t) {
tester = botTester({
token: '<your slack topen here>',
name: <name of bot you want to test>
});
tester.nextReply(onreply);
tester.nextReaction(onreaction);
tester.say('hi');
function onreply (err, msg) {
t.notOk(err);
t.equal(msg.text, 'hello');
}
function onreaction (err, reaction) {
t.notOk(err);
t.equal(reaction.reaction, 'heart');
}
});
api
Setup
var mokbot = require('slack-bot-tester');
var tester = mokbot({
token: '<your slack topen here>',
name: '<name of bot you want to test>'
});
.join(channel)
Join a channel
tester.join('general');
.say(message)
Say something in the channel
tester.say('Hello everyone!');
.mention(message)
Mention the bot by name directly in a message
tester.mention('Can I have some beer?');
.dm(message)
Directly message your bot
tester.dm('I like private chats more.');
.nextReply(callback)
Calls the callback the next time your bot says something, either in the channel, or as a direct message.
tester.nextReply(function (message) {
console.log('My bot said', message, 'in the channel or as a direct message');
});
.nextMention(callback)
Calls the callback the next time the tester bot is mentioned.
tester.nextMention(function (message) {
console.log('I got a mention with this message:', message);
});
.nextMatch(regex, callback)
Calls the callback the next time a message matches your regex.
tester.nextMention(/hello/, function (message) {
console.log('This message contains the word "hello":', message);
});
.nextReaction(callback)
Call a callback when the bot reacts to a message in the current channel.
tester.nextReaction(function (reaction) {
console.log('The bot reacted to a message in the channel.');
});
.conversation()
TBI