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

Commit 8d487e3

Browse files
committed
adds correct jsdoc style docs
1 parent fbdfb0f commit 8d487e3

File tree

1 file changed

+39
-18
lines changed

1 file changed

+39
-18
lines changed

lib/Slack_web_api.js

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
var request = require('request');
22

3+
/**
4+
* Does nothing. Takes no params, returns nothing. It's a no-op!
5+
*/
36
function noop() {}
47

8+
/**
9+
*
10+
* @param {Object} bot The botkit bot object
11+
* @param {Object} config A config containing auth credentials.
12+
* @returns {Object} A callback-based Slack API interface.
13+
*/
514
module.exports = function(bot, config) {
615
var slack_api = {
716
api_url: 'https://slack.com/api/'
@@ -79,28 +88,40 @@ module.exports = function(bot, config) {
7988
'users.setActive'
8089
];
8190

82-
slack_api.callAPI = function(command, options, cb) {
83-
if (!options.token) {
84-
options.token = config.token;
91+
/**
92+
* Calls Slack using a Token for authentication/authorization
93+
* @param {string} command The Slack API command to call
94+
* @param {Object} data The data to pass to the API call
95+
* @param {function} cb A NodeJS-style callback
96+
*/
97+
slack_api.callAPI = function(command, data, cb) {
98+
if (!data.token) {
99+
data.token = config.token;
85100
}
86101

87-
bot.debug(command, options);
88-
postForm(slack_api.api_url + command, options, cb);
102+
bot.debug(command, data);
103+
postForm(slack_api.api_url + command, data, cb);
89104
};
90105

91-
slack_api.callAPIWithoutToken = function(command, options, cb) {
92-
if (!options.client_id) {
93-
options.client_id = bot.config.clientId;
106+
/**
107+
* Calls Slack using OAuth for authentication/authorization
108+
* @param {string} command The Slack API command to call
109+
* @param {Object} data The data to pass to the API call
110+
* @param {function} cb A NodeJS-style callback
111+
*/
112+
slack_api.callAPIWithoutToken = function(command, data, cb) {
113+
if (!data.client_id) {
114+
data.client_id = bot.config.clientId;
94115
}
95-
if (!options.client_secret) {
96-
options.client_secret = bot.config.clientSecret;
116+
if (!data.client_secret) {
117+
data.client_secret = bot.config.clientSecret;
97118
}
98-
if (!options.redirect_uri) {
99-
options.redirect_uri = bot.config.redirectUri;
119+
if (!data.redirect_uri) {
120+
data.redirect_uri = bot.config.redirectUri;
100121
}
101122

102123
// DON'T log options: that could expose the client secret!
103-
postForm(slack_api.api_url + command, options, cb);
124+
postForm(slack_api.api_url + command, data, cb);
104125
};
105126

106127

@@ -141,11 +162,11 @@ module.exports = function(bot, config) {
141162

142163
/**
143164
* Makes a POST request as a form to the given url with the options as data
144-
* @param url
145-
* @param options
146-
* @param cb
165+
* @param {string} url The URL to POST to
166+
* @param {Object} formData The data to POST as a form
167+
* @param {function=} cb An optional NodeJS style callback when the POST completes or errors out.
147168
*/
148-
function postForm(url, options, cb) {
169+
function postForm(url, formData, cb) {
149170
cb = cb || noop;
150171

151172
bot.log('** API CALL: ' + url);
@@ -165,6 +186,6 @@ module.exports = function(bot, config) {
165186
return cb(json.error, json);
166187
}
167188
return cb(error || new Error('Invalid response'));
168-
}).form(options);
189+
}).form(formData);
169190
}
170191
};

0 commit comments

Comments
 (0)