Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.
Merged
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
33 changes: 7 additions & 26 deletions lib/Slack_web_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,7 @@ module.exports = function(bot, config) {
* @param {function} cb A NodeJS-style callback
*/
slack_api.callAPI = function(command, data, cb, multipart) {
if (!data.token) {
data.token = config.token;
}

data.token = data.token || config.token;
bot.debug(command, data);
postForm(slack_api.api_url + command, data, cb, multipart);
};
Expand All @@ -143,16 +140,9 @@ module.exports = function(bot, config) {
* @param {function} cb A NodeJS-style callback
*/
slack_api.callAPIWithoutToken = function(command, data, cb) {
if (!data.client_id) {
data.client_id = bot.config.clientId;
}
if (!data.client_secret) {
data.client_secret = bot.config.clientSecret;
}
if (!data.redirect_uri) {
data.redirect_uri = bot.config.redirectUri;
}

data.client_id = data.client_id || bot.config.clientId;
data.client_secret = data.client_secret || bot.config.clientSecret;
data.redirect_uri = data.redirect_uri || bot.config.redirectUri;
// DON'T log options: that could expose the client secret!
postForm(slack_api.api_url + command, data, cb);
};
Expand All @@ -170,9 +160,7 @@ module.exports = function(bot, config) {
var currentGroup = slack_api;

groups.forEach(function(nextGroupName) {
if (!currentGroup[nextGroupName]) {
currentGroup[nextGroupName] = {};
}
currentGroup[nextGroupName] = currentGroup[nextGroupName] || {};
currentGroup = currentGroup[nextGroupName];
});

Expand All @@ -195,11 +183,7 @@ module.exports = function(bot, config) {

// specify that files get uploaded using multipart
slack_api.files.upload = function(options, cb) {
if (options.file) {
slack_api.callAPI('files.upload', options, cb, true);
} else {
slack_api.callAPI('files.upload', options, cb, false);
}
slack_api.callAPI('files.upload', options, cb, !!options.file);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

};

function sanitizeOptions(options) {
Expand Down Expand Up @@ -251,10 +235,7 @@ module.exports = function(bot, config) {
return cb(parseError);
}

if (json.ok) {
return cb(null, json);
}
return cb(json.error, json);
return cb((json.ok ? null : json.error), json);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}
return cb(error || new Error('Invalid response'));
});
Expand Down