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

don't require callback for synchronous identify functions #353

Merged
merged 1 commit into from
Aug 13, 2016
Merged
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
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