Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Integrating Wordhop plugin #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ require(__dirname + '/components/onboarding.js')(controller);
// // Reconnect all pre-registered bots
// rtm_manager.reconnect();

// Enable Wordhop.io plugin
require(__dirname + '/components/plugin_wordhop.js')(controller);

// Enable Dashbot.io plugin
require(__dirname + '/components/plugin_dashbot.js')(controller);

Expand All @@ -111,12 +114,18 @@ require("fs").readdirSync(normalizedPath).forEach(function(file) {
if (process.env.studio_token) {
controller.on('direct_message,direct_mention,mention', function(bot, message) {
controller.studio.runTrigger(bot, message.text, message.user, message.channel).then(function(convo) {
// If your bot is paused (Wordhop feature), stop it from replying
if (message.paused) { return }
if (!convo) {
// no trigger was matched
// If you want your bot to respond to every message,
// define a 'fallback' script in Botkit Studio
// and uncomment the line below.
// controller.studio.run(bot, 'fallback', message.user, message.channel);
if (controller.wordhop) {
// log an unknown intent with Wordhop
controller.wordhop.logUnkownIntent(message);
}
} else {
// set variables here that are needed for EVERY script
// use controller.studio.before('script') to set variables specific to a script
Expand Down
41 changes: 41 additions & 0 deletions components/plugin_wordhop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module.exports = function(controller) {

// Wordhop provides a toolkit to monitor bots for problems and take over live
// Visit https://www.wordhop.io/ to add Wordhop to Slack and start getting alerts.
if (process.env.wordhop_api_key && process.env.wordhop_client_key) {
var wordhop = require('wordhop')(process.env.wordhop_api_key, process.env.wordhop_client_key, {platform:'slack'});
controller.wordhop = wordhop;
// Add the wordhop middleware
controller.middleware.receive.use(wordhop.receive);
controller.middleware.send.use(wordhop.send);
// Handle forwarding the messages sent by a human through your bot
wordhop.on('chat response', function (message) {
var team_id = message.team || null;
controller.findTeamById(team_id, function(err, team) {
if (err) {
controller.log.error('Could not load team while processing webhook: ', err);
return;
} else if (!team) {
// if this is NOT a slack app, it is ok to spawn a generic bot
// this is only likely to happen with custom slash commands
return
} else {
// spawn a bot
var bot = controller.spawn(team);

// Identify the bot from either team storage or identifyBot()
bot.team_info = team;
bot.identity = {
id: team.bot.user_id,
name: team.bot.name
};
bot.say(message);
}
});
});

controller.log.info('Thanks for using Wordhop.');
} else {
controller.log.info('No wordhop_api_key or wordhop_client_key specified. To monitor your bots For problems & take over live, go to https://www.wordhop.io/ to get your keys.');
}
}
4 changes: 4 additions & 0 deletions skills/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ module.exports = function(controller) {
convo.gotoThread(matches[1]);
}
}
// Forwards request to talk to a human to Wordhop
if (controller.wordhop) {
controller.wordhop.assistanceRequested(convo.source_message);
}

next();

Expand Down
6 changes: 6 additions & 0 deletions skills/sample_conversations.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ module.exports = function(controller) {

controller.hears(['color'], 'direct_message,direct_mention', function(bot, message) {

// If your bot is paused (Wordhop feature), stop it from replying
if (message.paused) { return }

bot.startConversation(message, function(err, convo) {
convo.say('This is an example of using convo.ask with a single callback.');

Expand All @@ -29,6 +32,9 @@ module.exports = function(controller) {

controller.hears(['question'], 'direct_message,direct_mention', function(bot, message) {

// If your bot is paused (Wordhop feature), stop it from replying
if (message.paused) { return }

bot.createConversation(message, function(err, convo) {

// create a path for when a user says YES
Expand Down
4 changes: 4 additions & 0 deletions skills/sample_hears.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ module.exports = function(controller) {
});

controller.hears(['^say (.*)','^say'], 'direct_message,direct_mention', function(bot, message) {

// If your bot is paused (Wordhop feature), stop it from replying
if (message.paused) { return }

if (message.match[1]) {

if (!wordfilter.blacklisted(message.match[1])) {
Expand Down