From 6d98a743aeb77a81fd1e91087d8a3678dde80204 Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 25 Nov 2016 23:36:08 -0500 Subject: [PATCH 1/4] fix bot_channel_join and bot_group_join event with events api --- examples/slackbutton_bot.js | 10 +++++++--- lib/SlackBot.js | 6 +++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/examples/slackbutton_bot.js b/examples/slackbutton_bot.js index 0f1794522..58f553d6e 100755 --- a/examples/slackbutton_bot.js +++ b/examples/slackbutton_bot.js @@ -27,15 +27,16 @@ This is a sample Slack Button application that adds a bot to one or many slack t /* Uses the slack button feature to offer a real time bot to multiple teams */ var Botkit = require('../lib/Botkit.js'); -if (!process.env.clientId || !process.env.clientSecret || !process.env.port || !process.env.redirectUri) { - console.log('Error: Specify clientId clientSecret redirectUri and port in environment'); +if (!process.env.clientId || !process.env.clientSecret || !process.env.port) { + console.log('Error: Specify clientId clientSecret and port in environment'); process.exit(1); } var controller = Botkit.slackbot({ json_file_store: './db_slackbutton_bot/', - // rtm_receive_messages: false, // disable rtm_receive_messages if you enable events api + debug: true, + rtm_receive_messages: false, // disable rtm_receive_messages if you enable events api }).configureSlackApp( { clientId: process.env.clientId, @@ -89,6 +90,9 @@ controller.on('create_bot',function(bot,config) { } }); +controller.on('bot_channel_join', function(bot, message) { + console.log('================ BOT JOINED CHANNEL!: bot.id', bot.identity) +}) // Handle events related to the websocket connection to Slack diff --git a/lib/SlackBot.js b/lib/SlackBot.js index 0a9ca8e63..10a65ff01 100755 --- a/lib/SlackBot.js +++ b/lib/SlackBot.js @@ -228,8 +228,8 @@ function Slackbot(configuration) { id: team.bot.user_id, name: team.bot.name }; + if (team.bot.user_id === req.body.event.user && req.body.event.subtype !== 'channel_join') { - if (team.bot.user_id === req.body.event.user) { slack_botkit.debug('Got event from this bot user, ignoring it'); return; } @@ -682,7 +682,7 @@ function Slackbot(configuration) { // set up a couple of special cases based on subtype if (message.subtype && message.subtype == 'channel_join') { // someone joined. maybe do something? - if (message.user == bot.identity.id && message.bot_id) { + if (message.user == bot.identity.id){ slack_botkit.trigger('bot_channel_join', [bot, message]); return false; } else { @@ -691,7 +691,7 @@ function Slackbot(configuration) { } } else if (message.subtype && message.subtype == 'group_join') { // someone joined. maybe do something? - if (message.user == bot.identity.id && message.bot_id) { + if (message.user == bot.identity.id) { slack_botkit.trigger('bot_group_join', [bot, message]); return false; } else { From cc76fb972846ad2c8e3a18e9b1022cb73bea2af4 Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 25 Nov 2016 23:43:57 -0500 Subject: [PATCH 2/4] undo changes to example bot --- examples/slackbutton_bot.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/examples/slackbutton_bot.js b/examples/slackbutton_bot.js index 58f553d6e..0f1794522 100755 --- a/examples/slackbutton_bot.js +++ b/examples/slackbutton_bot.js @@ -27,16 +27,15 @@ This is a sample Slack Button application that adds a bot to one or many slack t /* Uses the slack button feature to offer a real time bot to multiple teams */ var Botkit = require('../lib/Botkit.js'); -if (!process.env.clientId || !process.env.clientSecret || !process.env.port) { - console.log('Error: Specify clientId clientSecret and port in environment'); +if (!process.env.clientId || !process.env.clientSecret || !process.env.port || !process.env.redirectUri) { + console.log('Error: Specify clientId clientSecret redirectUri and port in environment'); process.exit(1); } var controller = Botkit.slackbot({ json_file_store: './db_slackbutton_bot/', - debug: true, - rtm_receive_messages: false, // disable rtm_receive_messages if you enable events api + // rtm_receive_messages: false, // disable rtm_receive_messages if you enable events api }).configureSlackApp( { clientId: process.env.clientId, @@ -90,9 +89,6 @@ controller.on('create_bot',function(bot,config) { } }); -controller.on('bot_channel_join', function(bot, message) { - console.log('================ BOT JOINED CHANNEL!: bot.id', bot.identity) -}) // Handle events related to the websocket connection to Slack From 95718d4b414896eab54077ef4c3761350a7b59e1 Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 25 Nov 2016 23:49:49 -0500 Subject: [PATCH 3/4] add group_join exception to bot generated events --- lib/SlackBot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/SlackBot.js b/lib/SlackBot.js index 10a65ff01..de5199178 100755 --- a/lib/SlackBot.js +++ b/lib/SlackBot.js @@ -228,7 +228,7 @@ function Slackbot(configuration) { id: team.bot.user_id, name: team.bot.name }; - if (team.bot.user_id === req.body.event.user && req.body.event.subtype !== 'channel_join') { + if (team.bot.user_id === req.body.event.user && req.body.event.subtype !== 'channel_join' && req.body.event.subtype !== 'group_join') { slack_botkit.debug('Got event from this bot user, ignoring it'); return; From 8d95781d42c8031fb9eec7301cd5f167b4c8853c Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 25 Nov 2016 23:51:32 -0500 Subject: [PATCH 4/4] typo fix --- lib/SlackBot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/SlackBot.js b/lib/SlackBot.js index de5199178..fad642ed8 100755 --- a/lib/SlackBot.js +++ b/lib/SlackBot.js @@ -682,7 +682,7 @@ function Slackbot(configuration) { // set up a couple of special cases based on subtype if (message.subtype && message.subtype == 'channel_join') { // someone joined. maybe do something? - if (message.user == bot.identity.id){ + if (message.user == bot.identity.id) { slack_botkit.trigger('bot_channel_join', [bot, message]); return false; } else {