Skip to content

Commit

Permalink
rtm-api: add support for custom webClient (#1696)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishangarg0 authored Nov 27, 2023
1 parent 1312f62 commit 62e4570
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
24 changes: 24 additions & 0 deletions docs/_packages/rtm_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,30 @@ const rtm = new RTMClient(token, options);

---

### Custom WebClient

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.

```javascript
const { RTMClient } = require('@slack/rtm-api');
const { WebClient, WebClientOptions } = require('@slack/web-api');
const token = process.env.SLACK_BOT_TOKEN;

// Configure the client to have custom headers
const options = {
headers: {
'Cookie': 'myCookie=cookieValue;'
}
} as WebClientOptions;

const webClient = new WebClient(token, options);

// Initialize a client using the configuration
const rtm = new RTMClient(token, { webClient });
```

---

### Workspace state snapshot

The client can receive a snapshot of a portion of the workspace's state while its connecting. This can be useful if your
Expand Down
8 changes: 8 additions & 0 deletions docs/_reference/rtm-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ slug: rtm-api
<th align="center">Name</th>
<th align="center">Type</th>
<th align="center">Required</th>
<th align="center">Description</th>
<th></th>
</tr>
</thead>
Expand All @@ -31,6 +32,13 @@ slug: rtm-api
<td align="center">✗</td>
<td></td>
</tr>
<tr>
<td align="center">webClient</td>
<td align="center"><code><a href="web-api#webclient" title="">WebClient</a></code></td>
<td align="center">✗</td>
<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>
<td></td>
</tr>
</tbody>
</table>
<strong>Options:</strong>
Expand Down
4 changes: 3 additions & 1 deletion packages/rtm-api/src/RTMClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,10 @@ export class RTMClient extends EventEmitter {
serverPongTimeout,
replyAckOnReconnectTimeout = 2000,
tls = undefined,
webClient,
}: RTMClientOptions = {}) {
super();
this.webClient = new WebClient(token, {
this.webClient = webClient || new WebClient(token, {
slackApiUrl,
logger,
logLevel,
Expand Down Expand Up @@ -672,6 +673,7 @@ export default RTMClient;
*/

export interface RTMClientOptions {
webClient?: WebClient;
slackApiUrl?: string;
logger?: Logger;
logLevel?: LogLevel;
Expand Down

0 comments on commit 62e4570

Please sign in to comment.