From 026785a04b3260bc2ba9d3a1890b2b658a89b5b9 Mon Sep 17 00:00:00 2001 From: Noam Lustiger Date: Tue, 2 Aug 2016 12:07:07 -0400 Subject: [PATCH] don't require callback for synchronous identify functions --- lib/Slackbot_worker.js | 27 ++++++++++++++++----------- readme-slack.md | 9 ++------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/Slackbot_worker.js b/lib/Slackbot_worker.js index 0d8dc236e..815aab939 100755 --- a/lib/Slackbot_worker.js +++ b/lib/Slackbot_worker.js @@ -227,34 +227,39 @@ module.exports = function(botkit, config) { }; bot.identifyBot = function(cb) { + var data; if (bot.identity) { - bot.identifyTeam(function(err, team) { - cb(null, { - name: bot.identity.name, - id: bot.identity.id, - team_id: team - }); - }); + data = { + name: bot.identity.name, + id: bot.identity.id, + team_id: bot.identifyTeam() + }; + cb && cb(null, data); + return data; } else { /** * Note: Are there scenarios other than the RTM * where we might pull identity info, perhaps from * bot.api.auth.test on a given token? */ - cb('Identity Unknown: Not using RTM api'); + cb && cb('Identity Unknown: Not using RTM api'); + return null; }; }; bot.identifyTeam = function(cb) { - if (bot.team_info) - return cb(null, bot.team_info.id); + if (bot.team_info) { + cb && cb(null, bot.team_info.id); + return bot.team_info.id; + } /** * Note: Are there scenarios other than the RTM * where we might pull identity info, perhaps from * bot.api.auth.test on a given token? */ - cb('Unknown Team!'); + cb && cb('Unknown Team!'); + return null; }; /** diff --git a/readme-slack.md b/readme-slack.md index 51da43b50..ed155d137 100644 --- a/readme-slack.md +++ b/readme-slack.md @@ -596,18 +596,13 @@ controller.setupWebserver(process.env.port,function(err,webserver) { ### How to identify what team your message came from ```javascript -bot.identifyTeam(function(err,team_id) { - -}) +var team = bot.identifyTeam() // returns team id ``` ### How to identify the bot itself (for RTM only) ```javascript -bot.identifyBot(function(err,identity) { - // identity contains... - // {name, id, team_id} -}) +var identity = bot.identifyBot() // returns object with {name, id, team_id} ```