Skip to content

Instantly share code, notes, and snippets.

@shinshin86
Created April 2, 2017 22:33
Show Gist options
  • Save shinshin86/a2ce4cf8b0cdbcd59a8b0693880d7a98 to your computer and use it in GitHub Desktop.
Save shinshin86/a2ce4cf8b0cdbcd59a8b0693880d7a98 to your computer and use it in GitHub Desktop.
This is a sample of slack bot for doing anonymous posting.
// Posting anonymously botn sample
// Confirm whether to submit a post => yes / no
controller.hears(['anonypost (.*)'], ['direct_message','direct_mention','mention'], function(bot,message) {
var matches = message.text.match(/anonypost (.*)/i);
var anonypost = matches[1];
bot.reply(message, 'I will post this content anonymously. Is it OK? => ' + anonypost );
bot.startConversation(message, function(err, convo) {
convo.ask('yes / no',
[
{
pattern: bot.utterances.yes,
callback: function(response, convo) {
convo.say('I posted this content anonymously!');
bot.startConversation({channel:"Your channnel"}, function(response, convo) {
convo.say("[anonypost! :mailbox_with_mail:]" + anonypost);
})
convo.next();
}
},
{
pattern: bot.utterances.no,
callback: function(response, convo) {
convo.say('OK! Post canceled!');
convo.next();
}
},
{
default: true,
callback: function(response, convo) {
convo.say('Please answer yes or no');
convo.repeat();
convo.next();
}
}
]);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment