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

Commit

Permalink
Merge pull request #353 from noam3127/identify-sync
Browse files Browse the repository at this point in the history
don't require callback for synchronous identify functions
  • Loading branch information
Ben Brown authored Aug 13, 2016
2 parents 6d8eb7e + 026785a commit 3ae09e3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
27 changes: 16 additions & 11 deletions lib/Slackbot_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/**
Expand Down
9 changes: 2 additions & 7 deletions readme-slack.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}
```


Expand Down

0 comments on commit 3ae09e3

Please sign in to comment.