Skip to content

Instantly share code, notes, and snippets.

@devStepsize
devStepsize / botkit_slack_specific_fields.js
Created April 22, 2016 19:43
Botkit reply to Slack with specific fields
// From https://github.com/howdyai/botkit#botreply
bot.reply(message,{
text: "A more complex response",
username: "ReplyBot",
icon_emoji: ":dash:",
});
@devStepsize
devStepsize / botkit_direct_message.js
Created April 22, 2016 19:37
Botkit reply to a direct message
// From https://github.com/howdyai/botkit#receiving-messages
controller.on('direct_message',function(bot,message) {
// reply to _message_ by using the _bot_ object
bot.reply(message,'You are talking directly to me');
});
@devStepsize
devStepsize / botkit_direct_mention.js
Created April 22, 2016 19:36
Botkit reply to a direct mention @bot
// From https://github.com/howdyai/botkit#receiving-messages
controller.on('direct_mention',function(bot,message) {
// reply to _message_ by using the _bot_ object
bot.reply(message,'I heard you mention me!');
});
@devStepsize
devStepsize / random_choice.py
Last active April 22, 2016 19:35
Select randomly a value from an array
import random
random.choice(array)
@devStepsize
devStepsize / botkit_message_received.js
Last active April 22, 2016 19:35
Botkit reply to any incoming message
// From https://github.com/howdyai/botkit#receiving-messages
controller.on('message_received', function(bot, message) {
bot.reply(message, 'I heard... something!');
});
@devStepsize
devStepsize / botkit_example_sentiment.js
Created April 22, 2016 19:32
A simple example using Botkit of a chatbot using sentiment analysis (from https://github.com/howdyai/botkit/blob/master/examples/sentiment_analysis.js)
'use strict';
/* "dependencies": {
"botkit": "0.0.7",
"escape-string-regexp": "^1.0.5",
"lodash": "^4.5.1",
"mongodb": "^2.1.7",
"sentiment": "^1.0.6",
}
*/
var _ = require('lodash');
@devStepsize
devStepsize / botkit_slackbutton_incomingwebhooks.js
Created April 22, 2016 19:24
Botkit example of using the Slack Button to offer an incoming webhook integration (from https://github.com/howdyai/botkit/blob/master/examples/slackbutton_incomingwebhooks.js)
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
______ ______ ______ __ __ __ ______
/\ == \ /\ __ \ /\__ _\ /\ \/ / /\ \ /\__ _\
\ \ __< \ \ \/\ \ \/_/\ \/ \ \ _"-. \ \ \ \/_/\ \/
\ \_____\ \ \_____\ \ \_\ \ \_\ \_\ \ \_\ \ \_\
\/_____/ \/_____/ \/_/ \/_/\/_/ \/_/ \/_/
This is a sample Slack Button application that allows the application
to post messages into Slack.
This bot demonstrates many of the core features of Botkit:
@devStepsize
devStepsize / botkit_slack_buttonbot.js
Created April 22, 2016 19:03
An example of Botkit using the Slack Button to offer a bot integration (from https://github.com/howdyai/botkit/blob/master/examples/slackbutton_bot.js)
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
______ ______ ______ __ __ __ ______
/\ == \ /\ __ \ /\__ _\ /\ \/ / /\ \ /\__ _\
\ \ __< \ \ \/\ \ \/_/\ \/ \ \ _"-. \ \ \ \/_/\ \/
\ \_____\ \ \_____\ \ \_\ \ \_\ \_\ \ \_\ \ \_\
\/_____/ \/_____/ \/_/ \/_/\/_/ \/_/ \/_/
This is a sample Slack Button application that adds a bot to one or many slack teams.
# RUN THE APP:
Create a Slack app. Make sure to configure the bot user!
-> https://api.slack.com/applications/new
@devStepsize
devStepsize / botkit_slack_example2.js
Created April 22, 2016 19:00
An example Botkit Slack bot showing how to perform slightly different actions (from https://github.com/howdyai/botkit/blob/master/examples/demo_bot.js)
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
______ ______ ______ __ __ __ ______
/\ == \ /\ __ \ /\__ _\ /\ \/ / /\ \ /\__ _\
\ \ __< \ \ \/\ \ \/_/\ \/ \ \ _"-. \ \ \ \/_/\ \/
\ \_____\ \ \_____\ \ \_\ \ \_\ \_\ \ \_\ \ \_\
\/_____/ \/_____/ \/_/ \/_/\/_/ \/_/ \/_/
This is a sample Slack bot built with Botkit.
This bot demonstrates many of the core features of Botkit:
* Connect to Slack using the real time API
* Receive messages based on "spoken" patterns
@devStepsize
devStepsize / botkit_hears_example.js
Created April 22, 2016 18:43
Example code snippet using Botkit's hears function
controller.hears('open the (.*) doors',['message_received'],function(bot,message) {
var doorType = message.match[1]; //match[1] is the (.*) group. match[0] is the entire group (open the (.*) doors).
if (doorType === 'pod bay') {
return bot.reply(message, 'I\'m sorry, Dave. I\'m afraid I can\'t do that.');
}
return bot.reply(message, 'Okay');
});