-
Notifications
You must be signed in to change notification settings - Fork 657
/
@slack-client.js
513 lines (465 loc) · 17.2 KB
/
@slack-client.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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
/**
* @module @slack/client
*/
/**
* * A dictionary of codes for errors produced by this package
* @enum {number}
* @property TestError
* @property RequestError
* @property ReadError
* @property HTTPError
* @property PlatformError
* @property RateLimitedError
* @property RefreshFailedError
* @property RTMSendWhileDisconnectedError
* @property RTMSendWhileNotReadyError
* @property RTMSendMessagePlatformError
* @property RTMWebsocketError
* @property RTMNoReplyReceivedError
* @property KeepAliveConfigError
* @property KeepAliveClientNotConnected
* @property KeepAliveInconsistentState
* @property IncomingWebhookRequestError
* @property IncomingWebhookReadError
* @property IncomingWebhookHTTPError
*/
export var ErrorCode
/**
* * Severity levels for log entries
* @enum {number}
* @property ERROR
* @property WARN
* @property INFO
* @property DEBUG
*/
export var LogLevel
/**
* All errors produced by this package adhere to this interface
* @interface module:@slack/client.CodedError
* @extends NodeJS:ErrnoException
* @property {module:@slack/client/dist/errors.ErrorCode} code
* @property {module:@slack/client.WebAPICallResult | module:@slack/client.RTMCallResult} [data]
*/
export class CodedError {
}
/**
* A client for Slack's Incoming Webhooks
*/
export class IncomingWebhook {
/**
* Send a notification to a conversation
* @param {string | module:@slack/client.IncomingWebhookSendArguments} message the message (a simple string, or an object describing the message)
* @function module:@slack/client.IncomingWebhook#send
* @returns {Promise<module:@slack/client.IncomingWebhookResult>}
*/
send() {}
/**
* @param {string | module:@slack/client.IncomingWebhookSendArguments} message
* @param {module:@slack/client.IncomingWebhookResultCallback} callback
* @function module:@slack/client.IncomingWebhook#send
*/
send() {}
/**
* @param {string | module:@slack/client.IncomingWebhookSendArguments} message
* @param {module:@slack/client.IncomingWebhookResultCallback} callback
* @function module:@slack/client.IncomingWebhook#send
*/
send() {}
}
/**
* @interface module:@slack/client.IncomingWebhookDefaultArguments
* @property {string} [username]
* @property {string} [icon_emoji]
* @property {string} [icon_url]
* @property {string} [channel]
* @property {string} [text]
* @property {boolean} [link_names]
* @property {"undefined" | "undefined" | module:http.Agent | module:@slack/client/dist/util.__type} [agent]
*/
export class IncomingWebhookDefaultArguments {
}
/**
* @interface module:@slack/client.IncomingWebhookResult
* @property {string} text
*/
export class IncomingWebhookResult {
}
/**
* @interface module:@slack/client.IncomingWebhookResultCallback
*/
export class IncomingWebhookResultCallback {
}
/**
* @interface module:@slack/client.IncomingWebhookSendArguments
* @extends module:@slack/client.IncomingWebhookDefaultArguments
* @property {Array<module:@slack/client/dist/methods.MessageAttachment>} [attachments]
* @property {Array<module:@slack/client/dist/methods.Block>} [blocks]
* @property {boolean} [unfurl_links]
* @property {boolean} [unful_media]
*/
export class IncomingWebhookSendArguments {
}
/**
* Interface for objects where objects in this package's logs can be sent (can be used as `logger` option).
* @interface module:@slack/client.Logger
*/
export class Logger {
/**
* Output debug message
* @param {Array<any>} msg any data to log
* @function module:@slack/client.Logger#debug
*/
debug() {}
/**
* Output error message
* @param {Array<any>} msg any data to log
* @function module:@slack/client.Logger#error
*/
error() {}
/**
* Output info message
* @param {Array<any>} msg any data to log
* @function module:@slack/client.Logger#info
*/
info() {}
/**
* This disables all logging below the given level, so that after a log.setLevel("warn") call log.warn("something")
* or log.error("something") will output messages, but log.info("something") will not.
* @param {module:@slack/client/dist/logger.LogLevel} level as a string, like 'error' (case-insensitive)
* @function module:@slack/client.Logger#setLevel
*/
setLevel() {}
/**
* This allows the instance to be named so that they can easily be filtered when many loggers are sending output
* to the same destination.
* @param {string} name as a string, will be output with every log after the level
* @function module:@slack/client.Logger#setName
*/
setName() {}
/**
* Output warn message
* @param {Array<any>} msg any data to log
* @function module:@slack/client.Logger#warn
*/
warn() {}
}
/**
* Interface for functions where this package's logs can be re-routed
* @interface module:@slack/client.LoggingFunc
* @deprecated
*/
export class LoggingFunc {
}
/**
* @interface module:@slack/client.RetryOptions
* @extends module:node_modules/@types/retry/index.OperationOptions
*/
export class RetryOptions {
}
/**
* @interface module:@slack/client.RTMCallResult
* @property {string} ts
* @property {number} [reply_to]
* @property {Object.<string, any>} [error]
*/
export class RTMCallResult {
}
/**
* @interface module:@slack/client.RTMCallResultCallback
*/
export class RTMCallResultCallback {
}
/**
* An RTMClient allows programs to communicate with the {@link https://api.slack.com/rtm|Slack Platform's RTM API}.
* This object uses the EventEmitter pattern to dispatch incoming events and has several methods for sending outgoing
* messages.
* @extends EventEmitter
* @property {boolean} [connected=false] Whether or not the client is currently connected to the RTM API
* @property {boolean} [authenticated=false] Whether or not the client has authenticated to the RTM API. This occurs when the connect method completes, and a WebSocket URL is available for the client's connection.
* @property {string} [activeUserId] The user ID for the connected client.
* @property {string} [activeTeamId] The team ID for the workspace the client is connected to.
*/
export class RTMClient {
/**
* @param {boolean} awaitReply
* @param {string} type
* @param {Object.<string, any>} body
* @function module:@slack/client.RTMClient#addOutgoingEvent
* @returns {Promise<void | module:@slack/client.RTMCallResult>}
*/
addOutgoingEvent() {}
/**
* Generic method for sending an outgoing message of an arbitrary type. This method guards the higher-level methods
* from concern of which state the client is in, because it places all messages into a queue. The tasks on the queue
* will buffer until the client is in a state where they can be sent.
*
* If the awaitReply parameter is set to true, then the returned Promise is resolved with the platform's
* acknowledgement response. Not all message types will result in an acknowledgement response, so use this carefully.
* This promise may be rejected with an error containing code=RTMNoReplyReceivedError if the client disconnects or
* reconnects before receiving the acknowledgement response.
*
* If the awaitReply parameter is set to false, then the returned Promise is resolved as soon as the message is sent
* from the websocket.
* @param {"undefined"} awaitReply whether to wait for an acknowledgement response from the platform before resolving the returned
Promise.
* @param {string} type the message type
* @param {Object.<string, any>} body the message body
* @function module:@slack/client.RTMClient#addOutgoingEvent
* @returns {Promise<module:@slack/client.RTMCallResult>}
*/
addOutgoingEvent() {}
/**
* @param {"undefined"} awaitReply
* @param {string} type
* @param {Object.<string, any>} body
* @function module:@slack/client.RTMClient#addOutgoingEvent
* @returns {Promise<void>}
*/
addOutgoingEvent() {}
/**
* End an RTM session. After this method is called no messages will be sent or received unless you call
* start() again later.
* @function module:@slack/client.RTMClient#disconnect
* @returns {Promise<void>}
*/
disconnect() {}
/**
* Generic method for sending an outgoing message of an arbitrary type. The main difference between this method and
* addOutgoingEvent() is that this method does not use a queue so it can only be used while the client is ready
* to send messages (in the 'ready' substate of the 'connected' state). It returns a Promise for the message ID of the
* sent message. This is an internal ID and generally shouldn't be used as an identifier for messages (for that,
* there is `ts` on messages once the server acknowledges it).
* @param {string} type the message type
* @param body the message body
* @function module:@slack/client.RTMClient#send
* @returns {Promise<number>}
*/
send() {}
/**
* Send a simple message to a public channel, private channel, DM, or MPDM.
* @param {string} text The message text.
* @param {string} conversationId A conversation ID for the destination of this message.
* @function module:@slack/client.RTMClient#sendMessage
* @returns {Promise<module:@slack/client.RTMCallResult>}
*/
sendMessage() {}
/**
* @param {string} text
* @param {string} conversationId
* @param {module:@slack/client.RTMCallResultCallback} callback
* @function module:@slack/client.RTMClient#sendMessage
*/
sendMessage() {}
/**
* @param {string} text
* @param {string} conversationId
* @param {module:@slack/client.RTMCallResultCallback} callback
* @function module:@slack/client.RTMClient#sendMessage
*/
sendMessage() {}
/**
* Sends a typing indicator to indicate that the user with `activeUserId` is typing.
* @param {string} conversationId The destination for where the typing indicator should be shown.
* @function module:@slack/client.RTMClient#sendTyping
* @returns {Promise<void>}
*/
sendTyping() {}
/**
* Begin an RTM session using the provided options. This method must be called before any messages can
* be sent or received.
* @param {module:@slack/client/dist/methods.TokenOverridable | module:@slack/client/dist/methods.LocaleAware | module:@slack/client/dist/methods.__type | module:@slack/client/dist/methods.TokenOverridable | module:@slack/client/dist/methods.__type} options
* @function module:@slack/client.RTMClient#start
* @returns {Promise<module:@slack/client.WebAPICallResult>}
*/
start() {}
/**
* Subscribes this client to presence changes for only the given `userIds`.
* @param {Array<string>} userIds An array of user IDs whose presence you are interested in. This list will replace the list from any
previous calls to this method.
* @function module:@slack/client.RTMClient#subscribePresence
* @returns {Promise<void>}
*/
subscribePresence() {}
}
/**
* @interface module:@slack/client.RTMClientOptions
* @property {string} [slackApiUrl]
* @property {module:@slack/client.Logger | module:@slack/client.LoggingFunc} [logger] Custom logger. Using a LoggingFunc is deprecated.
* @property {module:@slack/client/dist/logger.LogLevel} [logLevel]
* @property {module:@slack/client.RetryOptions} [retryConfig]
* @property {module:http.Agent} [agent]
* @property {boolean} [autoReconnect]
* @property {boolean} [useRtmConnect]
* @property {number} [clientPingTimeout]
* @property {number} [serverPongTimeout]
* @property {number} [replyAckOnReconnectTimeout]
* @property {module:@slack/client.TLSOptions} [tls]
*/
export class RTMClientOptions {
}
/**
* @interface module:@slack/client.RTMPlatformError
* @extends module:@slack/client.CodedError
* @property {"slackclient_rtmclient_send_message_platform_error"} code
*/
export class RTMPlatformError {
}
/**
* @interface module:@slack/client.RTMWebsocketError
* @extends module:@slack/client.CodedError
* @property {"slackclient_rtmclient_websocket_error"} code
* @property {Error} original
*/
export class RTMWebsocketError {
}
/**
* @interface module:@slack/client.TLSOptions
* @property {string | Buffer | Array<string | Object | Buffer>} [pfx]
* @property {string | Buffer | Array<Object | Buffer>} [key]
* @property {string} [passphrase]
* @property {string | Buffer | Array<string | Buffer>} [cert]
* @property {string | Buffer | Array<string | Buffer>} [ca]
*/
export class TLSOptions {
}
/**
* @interface module:@slack/client.TokenRefreshedEvent
* @property {string} access_token
* @property {number} expires_in
* @property {string} team_id
* @property {string} [enterprise_id]
*/
export class TokenRefreshedEvent {
}
/**
* @interface module:@slack/client.WebAPICallOptions
*/
export class WebAPICallOptions {
}
/**
* @interface module:@slack/client.WebAPICallResult
* @property {boolean} ok
* @property {string} [error]
* @property {Array<string>} [scopes]
* @property {Array<string>} [acceptedScopes]
* @property {number} [retryAfter]
* @property {Object.<string, any>} [response_metadata]
*/
export class WebAPICallResult {
}
/**
* @interface module:@slack/client.WebAPIHTTPError
* @extends module:@slack/client.CodedError
* @property {"slackclient_http_error"} code
* @property {Error} original
* @property {number} statusCode
* @property {string} statusMessage
* @property {module:http.IncomingHttpHeaders} headers
* @property {any} [body]
*/
export class WebAPIHTTPError {
}
/**
* @interface module:@slack/client.WebAPIPlatformError
* @extends module:@slack/client.CodedError
* @property {"slackclient_platform_error"} code
* @property {module:@slack/client.WebAPICallResult | module:@slack/client/dist/WebClient.__type} data
*/
export class WebAPIPlatformError {
}
/**
* @interface module:@slack/client.WebAPIRateLimitedError
* @extends module:@slack/client.CodedError
* @property {"slackclient_rate_limited_error"} code
* @property {number} retryAfter
*/
export class WebAPIRateLimitedError {
}
/**
* @interface module:@slack/client.WebAPIReadError
* @extends module:@slack/client.CodedError
* @property {"slackclient_read_error"} code
* @property {Error} original
*/
export class WebAPIReadError {
}
/**
* @interface module:@slack/client.WebAPIRefreshFailedError
* @extends module:@slack/client.CodedError
* @property {"slackclient_refresh_failed_error"} code
* @property {Error} original
*/
export class WebAPIRefreshFailedError {
}
/**
* @interface module:@slack/client.WebAPIRequestError
* @extends module:@slack/client.CodedError
* @property {"slackclient_request_error"} code
* @property {Error} original
*/
export class WebAPIRequestError {
}
/**
* @interface module:@slack/client.WebAPIResultCallback
*/
export class WebAPIResultCallback {
}
/**
* A client for Slack's Web API
*
* This client provides an alias for each {@link https://api.slack.com/methods|Web API method}. Each method is
* a convenience wrapper for calling the {@link WebClient#apiCall} method using the method name as the first parameter.
* @extends EventEmitter
* @property {string | undefined} token Authentication and authorization token for accessing Slack Web API (usually begins with `xoxa`, `xoxp`, or `xoxb`). This should be treated as readonly. Setting this value is used for refreshing tokens, and it is deprecated.
* @property {string} [refreshToken] OAuth 2.0 refresh token used to automatically create new access tokens (`token`) when the current is expired. Deprecated: {tag.description}
* @property {string} [clientId] OAuth 2.0 client identifier Deprecated: {tag.description}
* @property {string} [clientSecret] OAuth 2.0 client secret Deprecated: {tag.description}
* @property {string} [slackApiUrl] The base URL for reaching Slack's Web API. Consider changing this value for testing purposes.
*/
export class WebClient {
/**
* Generic method for calling a Web API method
* @param {string} method the Web API method to call {@see https://api.slack.com/methods}
* @param {module:@slack/client.WebAPICallOptions} options options
* @function module:@slack/client.WebClient#apiCall
* @returns {Promise<module:@slack/client.WebAPICallResult>}
*/
apiCall() {}
/**
* @param {string} method
* @param {module:@slack/client.WebAPICallOptions} options
* @param {module:@slack/client.WebAPIResultCallback} callback
* @function module:@slack/client.WebClient#apiCall
*/
apiCall() {}
/**
* @param {string} method
* @param {module:@slack/client.WebAPICallOptions} options
* @param {module:@slack/client.WebAPIResultCallback} callback
* @function module:@slack/client.WebClient#apiCall
*/
apiCall() {}
}
/**
* @interface module:@slack/client.WebClientOptions
* @property {string} [slackApiUrl]
* @property {module:@slack/client.Logger | module:@slack/client.LoggingFunc} [logger] Custom logger. Using a LoggingFunc is deprecated.
* @property {module:@slack/client/dist/logger.LogLevel} [logLevel]
* @property {number} [maxRequestConcurrency]
* @property {module:@slack/client.RetryOptions} [retryConfig]
* @property {"undefined" | "undefined" | module:http.Agent | module:@slack/client/dist/util.__type} [agent]
* @property {module:@slack/client.TLSOptions} [tls]
* @property {number} [pageSize]
* @property {boolean} [rejectRateLimitedCalls]
* @property {string} [clientId]
* @property {string} [clientSecret]
* @property {string} [refreshToken]
* @property {any} [headers]
*/
export class WebClientOptions {
}
/**
* Appends the app metadata into the User-Agent value
* @param {Object.<string, any>} undefined
*/
export function addAppMetadata() {}