Skip to main content

@slack/rtm-api / RTMClient

Class: RTMClient

Defined in: packages/rtm-api/src/RTMClient.ts:63

An RTMClient allows programs to communicate with the Platform's RTM API. This object uses the EventEmitter pattern to dispatch incoming events and has several methods for sending outgoing messages.

Extends​

  • EventEmitter

Constructors​

Constructor​

new RTMClient(token, __namedParameters?): RTMClient;

Defined in: packages/rtm-api/src/RTMClient.ts:367

Parameters​

token​

string

__namedParameters?​

RTMClientOptions = {}

Returns​

RTMClient

Overrides​

EventEmitter.constructor

Properties​

activeTeamId?​

optional activeTeamId?: string;

Defined in: packages/rtm-api/src/RTMClient.ts:83

The team ID for the workspace the client is connected to.


activeUserId?​

optional activeUserId?: string;

Defined in: packages/rtm-api/src/RTMClient.ts:78

The user ID for the connected client.


authenticated​

authenticated: boolean = false;

Defined in: packages/rtm-api/src/RTMClient.ts:73

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.


connected​

connected: boolean = false;

Defined in: packages/rtm-api/src/RTMClient.ts:67

Whether or not the client is currently connected to the RTM API


prefixed​

static prefixed: string | boolean;

Defined in: node_modules/eventemitter3/index.d.ts:9

Inherited from​

EventEmitter.prefixed

Methods​

addListener()​

addListener<T>(
event,
fn,
context?): this;

Defined in: node_modules/eventemitter3/index.d.ts:45

Type Parameters​

T​

T extends string | symbol

Parameters​

event​

T

fn​

(...args) => void

context?​

any

Returns​

this

Inherited from​

EventEmitter.addListener

addOutgoingEvent()​

Call Signature​

addOutgoingEvent(
awaitReply,
type,
body?): Promise<RTMCallResult>;

Defined in: packages/rtm-api/src/RTMClient.ts:525

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.

Parameters​
awaitReply​

true

whether to wait for an acknowledgement response from the platform before resolving the returned Promise.

type​

string

the message type

body?​

Record<string, unknown>

the message body

Returns​

Promise<RTMCallResult>

Call Signature​

addOutgoingEvent(
awaitReply,
type,
body?): Promise<undefined>;

Defined in: packages/rtm-api/src/RTMClient.ts:526

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.

Parameters​
awaitReply​

false

whether to wait for an acknowledgement response from the platform before resolving the returned Promise.

type​

string

the message type

body?​

Record<string, unknown>

the message body

Returns​

Promise<undefined>


disconnect()​

disconnect(): Promise<void>;

Defined in: packages/rtm-api/src/RTMClient.ts:464

End an RTM session. After this method is called no messages will be sent or received unless you call start() again later.

Returns​

Promise<void>


emit()​

emit<T>(event, ...args): boolean;

Defined in: node_modules/eventemitter3/index.d.ts:32

Calls each of the listeners registered for a given event.

Type Parameters​

T​

T extends string | symbol

Parameters​

event​

T

args​

...any[]

Returns​

boolean

Inherited from​

EventEmitter.emit

eventNames()​

eventNames(): (string | symbol)[];

Defined in: node_modules/eventemitter3/index.d.ts:15

Return an array listing the events for which the emitter has registered listeners.

Returns​

(string | symbol)[]

Inherited from​

EventEmitter.eventNames

listenerCount()​

listenerCount(event): number;

Defined in: node_modules/eventemitter3/index.d.ts:27

Return the number of listeners listening to a given event.

Parameters​

event​

string | symbol

Returns​

number

Inherited from​

EventEmitter.listenerCount

listeners()​

listeners<T>(event): (...args) => void[];

Defined in: node_modules/eventemitter3/index.d.ts:20

Return the listeners registered for a given event.

Type Parameters​

T​

T extends string | symbol

Parameters​

event​

T

Returns​

(...args) => void[]

Inherited from​

EventEmitter.listeners

off()​

off<T>(
event,
fn?,
context?,
once?): this;

Defined in: node_modules/eventemitter3/index.d.ts:69

Type Parameters​

T​

T extends string | symbol

Parameters​

event​

T

fn?​

(...args) => void

context?​

any

once?​

boolean

Returns​

this

Inherited from​

EventEmitter.off

on()​

on<T>(
event,
fn,
context?): this;

Defined in: node_modules/eventemitter3/index.d.ts:40

Add a listener for a given event.

Type Parameters​

T​

T extends string | symbol

Parameters​

event​

T

fn​

(...args) => void

context?​

any

Returns​

this

Inherited from​

EventEmitter.on

once()​

once<T>(
event,
fn,
context?): this;

Defined in: node_modules/eventemitter3/index.d.ts:54

Add a one-time listener for a given event.

Type Parameters​

T​

T extends string | symbol

Parameters​

event​

T

fn​

(...args) => void

context?​

any

Returns​

this

Inherited from​

EventEmitter.once

removeAllListeners()​

removeAllListeners(event?): this;

Defined in: node_modules/eventemitter3/index.d.ts:79

Remove all listeners, or those of the specified event.

Parameters​

event?​

string | symbol

Returns​

this

Inherited from​

EventEmitter.removeAllListeners

removeListener()​

removeListener<T>(
event,
fn?,
context?,
once?): this;

Defined in: node_modules/eventemitter3/index.d.ts:63

Remove the listeners of a given event.

Type Parameters​

T​

T extends string | symbol

Parameters​

event​

T

fn?​

(...args) => void

context?​

any

once?​

boolean

Returns​

this

Inherited from​

EventEmitter.removeListener

send()​

send(type, body?): Promise<number>;

Defined in: packages/rtm-api/src/RTMClient.ts:578

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).

Parameters​

type​

string

the message type

body?​

the message body

Returns​

Promise<number>


sendMessage()​

sendMessage(text, conversationId): Promise<RTMCallResult>;

Defined in: packages/rtm-api/src/RTMClient.ts:487

Send a simple message to a public channel, private channel, DM, or MPDM.

Parameters​

text​

string

The message text.

conversationId​

string

A conversation ID for the destination of this message.

Returns​

Promise<RTMCallResult>


sendTyping()​

sendTyping(conversationId): Promise<void>;

Defined in: packages/rtm-api/src/RTMClient.ts:495

Sends a typing indicator to indicate that the user with activeUserId is typing.

Parameters​

conversationId​

string

The destination for where the typing indicator should be shown.

Returns​

Promise<void>


start()​

start(options?): Promise<WebAPICallResult>;

Defined in: packages/rtm-api/src/RTMClient.ts:438

Begin an RTM session using the provided options. This method must be called before any messages can be sent or received.

Parameters​

options?​

RTMStartOptions

Returns​

Promise<WebAPICallResult>


subscribePresence()​

subscribePresence(userIds): Promise<void>;

Defined in: packages/rtm-api/src/RTMClient.ts:504

Subscribes this client to presence changes for only the given userIds.

Parameters​

userIds​

string[]

An array of user IDs whose presence you are interested in. This list will replace the list from any previous calls to this method.

Returns​

Promise<void>