-
Notifications
You must be signed in to change notification settings - Fork 662
/
channels.js
268 lines (223 loc) · 8.17 KB
/
channels.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/**
* API Facet to make calls to methods in the channels namespace.
*
* This provides functions to call:
* - archive: {@link https://api.slack.com/methods/channels.archive|channels.archive}
* - create: {@link https://api.slack.com/methods/channels.create|channels.create}
* - history: {@link https://api.slack.com/methods/channels.history|channels.history}
* - info: {@link https://api.slack.com/methods/channels.info|channels.info}
* - invite: {@link https://api.slack.com/methods/channels.invite|channels.invite}
* - join: {@link https://api.slack.com/methods/channels.join|channels.join}
* - kick: {@link https://api.slack.com/methods/channels.kick|channels.kick}
* - leave: {@link https://api.slack.com/methods/channels.leave|channels.leave}
* - list: {@link https://api.slack.com/methods/channels.list|channels.list}
* - mark: {@link https://api.slack.com/methods/channels.mark|channels.mark}
* - rename: {@link https://api.slack.com/methods/channels.rename|channels.rename}
* - setPurpose: {@link https://api.slack.com/methods/channels.setPurpose|channels.setPurpose}
* - setTopic: {@link https://api.slack.com/methods/channels.setTopic|channels.setTopic}
* - unarchive: {@link https://api.slack.com/methods/channels.unarchive|channels.unarchive}
*
*/
function ChannelsFacet(makeAPICall) {
this.name = 'channels';
this.makeAPICall = makeAPICall;
}
/**
* Archives a channel.
* @see {@link https://api.slack.com/methods/channels.archive|channels.archive}
*
* @param {?} channel - Channel to archive
* @param {function=} optCb Optional callback, if not using promises.
*/
ChannelsFacet.prototype.archive = function archive(channel, optCb) {
var requiredArgs = {
channel: channel
};
return this.makeAPICall('channels.archive', requiredArgs, null, optCb);
};
/**
* Creates a channel.
* @see {@link https://api.slack.com/methods/channels.create|channels.create}
*
* @param {?} name - Name of channel to create
* @param {function=} optCb Optional callback, if not using promises.
*/
ChannelsFacet.prototype.create = function create(name, optCb) {
var requiredArgs = {
name: name
};
return this.makeAPICall('channels.create', requiredArgs, null, optCb);
};
/**
* Fetches history of messages and events from a channel.
* @see {@link https://api.slack.com/methods/channels.history|channels.history}
*
* @param {?} channel - Channel to fetch history for.
* @param {Object=} opts
* @param {?} opts.latest - End of time range of messages to include in results.
* @param {?} opts.oldest - Start of time range of messages to include in results.
* @param {?} opts.inclusive - Include messages with latest or oldest timestamp in results.
* @param {?} opts.count - Number of messages to return, between 1 and 1000.
* @param {?} opts.unreads - Include `unread_count_display` in the output?
* @param {function=} optCb Optional callback, if not using promises.
*/
ChannelsFacet.prototype.history = function history(channel, opts, optCb) {
var requiredArgs = {
channel: channel
};
return this.makeAPICall('channels.history', requiredArgs, opts, optCb);
};
/**
* Gets information about a channel.
* @see {@link https://api.slack.com/methods/channels.info|channels.info}
*
* @param {?} channel - Channel to get info on
* @param {function=} optCb Optional callback, if not using promises.
*/
ChannelsFacet.prototype.info = function info(channel, optCb) {
var requiredArgs = {
channel: channel
};
return this.makeAPICall('channels.info', requiredArgs, null, optCb);
};
/**
* Invites a user to a channel.
* @see {@link https://api.slack.com/methods/channels.invite|channels.invite}
*
* @param {?} channel - Channel to invite user to.
* @param {?} user - User to invite to channel.
* @param {function=} optCb Optional callback, if not using promises.
*/
ChannelsFacet.prototype.invite = function invite(channel, user, optCb) {
var requiredArgs = {
channel: channel,
user: user
};
return this.makeAPICall('channels.invite', requiredArgs, null, optCb);
};
/**
* Joins a channel, creating it if needed.
* @see {@link https://api.slack.com/methods/channels.join|channels.join}
*
* @param {?} name - Name of channel to join
* @param {function=} optCb Optional callback, if not using promises.
*/
ChannelsFacet.prototype.join = function join(name, optCb) {
var requiredArgs = {
name: name
};
return this.makeAPICall('channels.join', requiredArgs, null, optCb);
};
/**
* Removes a user from a channel.
* @see {@link https://api.slack.com/methods/channels.kick|channels.kick}
*
* @param {?} channel - Channel to remove user from.
* @param {?} user - User to remove from channel.
* @param {function=} optCb Optional callback, if not using promises.
*/
ChannelsFacet.prototype.kick = function kick(channel, user, optCb) {
var requiredArgs = {
channel: channel,
user: user
};
return this.makeAPICall('channels.kick', requiredArgs, null, optCb);
};
/**
* Leaves a channel.
* @see {@link https://api.slack.com/methods/channels.leave|channels.leave}
*
* @param {?} channel - Channel to leave
* @param {function=} optCb Optional callback, if not using promises.
*/
ChannelsFacet.prototype.leave = function leave(channel, optCb) {
var requiredArgs = {
channel: channel
};
return this.makeAPICall('channels.leave', requiredArgs, null, optCb);
};
/**
* Lists all channels in a Slack team.
* @see {@link https://api.slack.com/methods/channels.list|channels.list}
*
* @param {Object=} opts
* @param {?} opts.exclude_archived - Don't return archived channels.
* @param {function=} optCb Optional callback, if not using promises.
*/
ChannelsFacet.prototype.list = function list(opts, optCb) {
return this.makeAPICall('channels.list', null, opts, optCb);
};
/**
* Sets the read cursor in a channel.
* @see {@link https://api.slack.com/methods/channels.mark|channels.mark}
*
* @param {?} channel - Channel to set reading cursor in.
* @param {?} ts - Timestamp of the most recently seen message.
* @param {function=} optCb Optional callback, if not using promises.
*/
ChannelsFacet.prototype.mark = function mark(channel, ts, optCb) {
var requiredArgs = {
channel: channel,
ts: ts
};
return this.makeAPICall('channels.mark', requiredArgs, null, optCb);
};
/**
* Renames a channel.
* @see {@link https://api.slack.com/methods/channels.rename|channels.rename}
*
* @param {?} channel - Channel to rename
* @param {?} name - New name for channel.
* @param {function=} optCb Optional callback, if not using promises.
*/
ChannelsFacet.prototype.rename = function rename(channel, name, optCb) {
var requiredArgs = {
channel: channel,
name: name
};
return this.makeAPICall('channels.rename', requiredArgs, null, optCb);
};
/**
* Sets the purpose for a channel.
* @see {@link https://api.slack.com/methods/channels.setPurpose|channels.setPurpose}
*
* @param {?} channel - Channel to set the purpose of
* @param {?} purpose - The new purpose
* @param {function=} optCb Optional callback, if not using promises.
*/
ChannelsFacet.prototype.setPurpose = function setPurpose(channel, purpose, optCb) {
var requiredArgs = {
channel: channel,
purpose: purpose
};
return this.makeAPICall('channels.setPurpose', requiredArgs, null, optCb);
};
/**
* Sets the topic for a channel.
* @see {@link https://api.slack.com/methods/channels.setTopic|channels.setTopic}
*
* @param {?} channel - Channel to set the topic of
* @param {?} topic - The new topic
* @param {function=} optCb Optional callback, if not using promises.
*/
ChannelsFacet.prototype.setTopic = function setTopic(channel, topic, optCb) {
var requiredArgs = {
channel: channel,
topic: topic
};
return this.makeAPICall('channels.setTopic', requiredArgs, null, optCb);
};
/**
* Unarchives a channel.
* @see {@link https://api.slack.com/methods/channels.unarchive|channels.unarchive}
*
* @param {?} channel - Channel to unarchive
* @param {function=} optCb Optional callback, if not using promises.
*/
ChannelsFacet.prototype.unarchive = function unarchive(channel, optCb) {
var requiredArgs = {
channel: channel
};
return this.makeAPICall('channels.unarchive', requiredArgs, null, optCb);
};
module.exports = ChannelsFacet;