Skip to content

Commit 62e4570

Browse files
authored
rtm-api: add support for custom webClient (#1696)
1 parent 1312f62 commit 62e4570

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

docs/_packages/rtm_api.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,30 @@ const rtm = new RTMClient(token, options);
644644

645645
---
646646

647+
### Custom WebClient
648+
649+
In some cases, you might want to customize the underlying component making HTTP requests to the Slack API, the [`WebClient`](reference/web-api#webclient), beyond the provided [`RTMClientOptions`](reference/rtm-api#rtmclientoptions). Note that overriding the [`WebClient`](reference/web-api#webclient) instance takes precedence over any other [`RTMClientOptions`](reference/rtm-api#rtmclientoptions) specified.
650+
651+
```javascript
652+
const { RTMClient } = require('@slack/rtm-api');
653+
const { WebClient, WebClientOptions } = require('@slack/web-api');
654+
const token = process.env.SLACK_BOT_TOKEN;
655+
656+
// Configure the client to have custom headers
657+
const options = {
658+
headers: {
659+
'Cookie': 'myCookie=cookieValue;'
660+
}
661+
} as WebClientOptions;
662+
663+
const webClient = new WebClient(token, options);
664+
665+
// Initialize a client using the configuration
666+
const rtm = new RTMClient(token, { webClient });
667+
```
668+
669+
---
670+
647671
### Workspace state snapshot
648672

649673
The client can receive a snapshot of a portion of the workspace's state while its connecting. This can be useful if your

docs/_reference/rtm-api.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ slug: rtm-api
1515
<th align="center">Name</th>
1616
<th align="center">Type</th>
1717
<th align="center">Required</th>
18+
<th align="center">Description</th>
1819
<th></th>
1920
</tr>
2021
</thead>
@@ -31,6 +32,13 @@ slug: rtm-api
3132
<td align="center">✗</td>
3233
<td></td>
3334
</tr>
35+
<tr>
36+
<td align="center">webClient</td>
37+
<td align="center"><code><a href="web-api#webclient" title="">WebClient</a></code></td>
38+
<td align="center">✗</td>
39+
<td align="center">An optional parameter to provide a customized <a href="web-api#webclient">WebClient</a>. Any desired options for the custom client must be set in this parameter (<code>webClient</code>) as they will take precedence over other arguments passed into <code>RTMClient</code>.</td>
40+
<td></td>
41+
</tr>
3442
</tbody>
3543
</table>
3644
<strong>Options:</strong>

packages/rtm-api/src/RTMClient.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,10 @@ export class RTMClient extends EventEmitter {
348348
serverPongTimeout,
349349
replyAckOnReconnectTimeout = 2000,
350350
tls = undefined,
351+
webClient,
351352
}: RTMClientOptions = {}) {
352353
super();
353-
this.webClient = new WebClient(token, {
354+
this.webClient = webClient || new WebClient(token, {
354355
slackApiUrl,
355356
logger,
356357
logLevel,
@@ -672,6 +673,7 @@ export default RTMClient;
672673
*/
673674

674675
export interface RTMClientOptions {
676+
webClient?: WebClient;
675677
slackApiUrl?: string;
676678
logger?: Logger;
677679
logLevel?: LogLevel;

0 commit comments

Comments
 (0)