-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Conversation
…web api when RTM fails
add events_api boolean, event_ts, authed_users
…ntity is not in team storage use identifyBot
…ts api to play nice together start ticking when webhooks are setup
Read the changelog earlier and the latest 0.4.1 release already support the Events API - no? |
Nope! It was mostly small fixes in 4.1 Any feedback @sundeepgupta? I left it this way because that's how Botkit did it before, but this would likely be very confusing unless explained well in the docs. |
@jonchurch I've yet to learn about Events API and haven't looked at your PR, sorry. Thought I'd just check to make sure this wasn't duplicated effort but I obviously mis-understood the changelog. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! I haven't tested this against the API yet, but I left some comments.
@@ -27,8 +27,8 @@ 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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is redirectUri required in this example now? It's optional in the Slack OAuth flow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was actually part of a PR from #458, which I realize now was not necessary.
You are correct, redirectUri is not required here, I misunderstood their issue.
Removing
@@ -287,15 +358,19 @@ function Slackbot(configuration) { | |||
|
|||
slack_botkit.webserver = express(); | |||
slack_botkit.webserver.use(bodyParser.json()); | |||
slack_botkit.webserver.use(bodyParser.urlencoded({ extended: true })); | |||
slack_botkit.webserver.use(bodyParser.urlencoded({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These formatting changes make it a bit hard to understand what changes are relevant to this functionality. Would it be possible to exclude them from this PR?
|
||
// Save bot identity to team storage for retrieval when handling Events API | ||
slack_botkit.findTeamById(identity.team_id, function(err, team_data) { | ||
if (!team_data.bot.identity) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
team_data will probably not be defined if there is an error. I suggest testing for the error immediately, then exiting early if one exists.
examples/db_slackbutton_bot/ | ||
examples/db_slackbutton_incomingwebhook/ | ||
examples/db_slackbutton_slashcommand/ | ||
examples/db_team_bot/ | ||
.DS_Store | ||
*/.DS_Store | ||
.env | ||
.idea |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure we need .idea
in the gitignore. That seems like it should be in users global .gitignore if they are webstorm users.
@@ -2,10 +2,12 @@ node_modules/ | |||
start.sh | |||
start_button.sh | |||
db/ | |||
db_slack_events_api/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not put this db under either the examples/ directory?
res.status(200).json({ | ||
challenge: req.body.challenge | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a lot of extra spaces in this file before closing braces. Would you mind removing them to be more consistent with the rest of the file?
|
||
// Receive messages and trigger events from the Events API | ||
if (req.body.type === 'event_callback') { | ||
// respond to events api with a 200 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be possible to pull all of this logic inside the if
into it's own function? this function is getting very long and hard to follow, decomposing it will make it easier to read.
if (err || !team) { | ||
slack_botkit.log.error('Received Events API message, but could not load team'); | ||
if (err) { | ||
slack_botkit.log.error(err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you return here, then you save yourself the if and keeps the indentation flatter.
bot.identifyBot(function(err, identity) { | ||
bot.identity = identity; | ||
|
||
if (req.body.event.type === 'message') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this logic is duplicated, could we make this a function?
|
||
if (team.bot.identity == undefined || team.bot.identity.id == null) { | ||
// API call to slack to identify bot user | ||
bot.identifyBot(function(err, identity) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if there is an error identifying the bot?
This got merged in to #500 and is now released! Thanks @jonchurch and @colestrode and @sundeepgupta and @peterswimm for your attention to this!! |
Had to resubmit this because I somehow got the other branch into a non-repairable headless state that github support advised I abandon ¯_(ツ)_/¯
Receive Events API events at the webhook setup by
createWebhookEndpoints()
EDIT:
startTicking()
is now called for you when wehbhook endpoints are createdUsecontroller.startTicking()
when running bot to enable conversationsWould like feedback on Bot Identity management without RTM. I'm saving bot identity to team storage when a user completes oauth flow, and looking it up from storage each time an Events API request is received.
closes #438