Slack Developer Kit for Node.js
Go to GitHub

RTMClient

Kind: global class

new RTMClient(token, opts)

Creates a new instance of RTM client.

Param Type Description
token String The token to use for connecting
opts Object  
opts.socketFn function A function to call, passing in a websocket URL, that should return a websocket instance connected to that URL
opts.dataStore Object A store to cache Slack info, e.g. channels, users etc. in. Pass null or false to use no store
opts.autoReconnect Boolean Whether or not to automatically reconnect when the connection closes. Defaults to true
opts.useRtmConnect Boolean True to use rtm.connect rather than rtm.start
opts.retryConfig Object The retry policy to use, defaults to forever with exponential backoff {@see https://github.com/SEAPUNK/node-retry}
opts.maxReconnectionAttempts Number DEPRECATED: Use retryConfig instead
opts.reconnectionBackoff Number DEPRECATED: Use retryConfig instead
opts.wsPingInterval Number The time to wait between pings with the server
opts.maxPongInterval Number The max time (in ms) to wait for a pong before reconnecting
opts.logLevel String The log level for the logger
opts.logger function Function to use for log calls, takes (logLevel, logString) parameters

rtmClient._socketFn : function

Kind: instance property of [RTMClient](#RTMClient)

rtmClient.ws : Object

The active websocket.

Kind: instance property of [RTMClient](#RTMClient)

rtmClient.connected : boolean

Kind: instance property of [RTMClient](#RTMClient)

rtmClient.authenticated : boolean

Kind: instance property of [RTMClient](#RTMClient)

rtmClient.activeUserId : string

The id of the user that’s currently connected via this client.

Kind: instance property of [RTMClient](#RTMClient)

rtmClient.activeTeamId : string

The id of the team that’s currently connected via this client.

Kind: instance property of [RTMClient](#RTMClient)

rtmClient.dataStore : [SlackDataStore](#SlackDataStore)

Kind: instance property of [RTMClient](#RTMClient)

rtmClient._pingTimer : ?

The timer repeatedly pinging the server to let it know the client is still alive.

Kind: instance property of [RTMClient](#RTMClient)

rtmClient._createFacets()

Kind: instance method of [RTMClient](#RTMClient)

rtmClient.start(opts)

Begin an RTM session.

Kind: instance method of [RTMClient](#RTMClient)

Param Type
opts object

rtmClient.login()

Deprecated

Kind: instance method of [RTMClient](#RTMClient)

rtmClient.nextMessageId()

Generates the next message id to use.

NOTE: This id must be unique per RTM connection.

Kind: instance method of [RTMClient](#RTMClient)

rtmClient.connect(socketUrl)

Connects to the RTM API.

Kind: instance method of [RTMClient](#RTMClient)

Param Type Description
socketUrl String The URL of the websocket to connect to.

rtmClient.disconnect(optReason, optCode)

Disconnects from the RTM API.

Kind: instance method of [RTMClient](#RTMClient)

Param Type
optReason Error
optCode Number

rtmClient.reconnect()

Attempts to reconnect to the websocket by retrying the start method.

Kind: instance method of [RTMClient](#RTMClient)

rtmClient.handleWsOpen()

Handler to deal with the WebSocket open event. NOTE: this.connected doesn’t get set to true until the helloHandler is called.

Kind: instance method of [RTMClient](#RTMClient)

rtmClient.handleWsMessage(wsMsg)

Handler to deal with the WebSocket message event.

Kind: instance method of [RTMClient](#RTMClient)

Param Type
wsMsg object

rtmClient._handleMessageAck(replyTo, message)

Handler for the remote server’s response to a message being sent on the websocket.

Kind: instance method of [RTMClient](#RTMClient)

Param
replyTo
message

rtmClient.handleWsError(err)

Emits the websocket error.

Kind: instance method of [RTMClient](#RTMClient)

Param Type
err Object

rtmClient.handleWsClose(code, reason)

Occurs when the websocket closes.

Kind: instance method of [RTMClient](#RTMClient)

Param Type Description
code String The error code
reason String The reason for closing

rtmClient._handlePong(message)

Handles the RTM API’s pong message, updating the lastPong time on the client.

Kind: instance method of [RTMClient](#RTMClient)

Param Type
message Object

rtmClient._maybeKeepAlive(message)

If we haven’t received a pong in too long, treat any incoming message as a pong to prevent unnecessary disconnects.

Kind: instance method of [RTMClient](#RTMClient)

Param Type
message Object

rtmClient._handleHello()

Occurs when the socket connection is opened. Begin ping-pong with the server. hello

Kind: instance method of [RTMClient](#RTMClient)

rtmClient.sendMessage(text, channelId, [optCb])

Helper for sending a simple message to a channel|group|DM etc via the RTM API.

Kind: instance method of [RTMClient](#RTMClient)

Param Type Description    
text string The text of the messsage to send.    
channelId string The id of the channel group DM to send this message to.
[optCb] function      

rtmClient.updateMessage(message, [optCb])

Helper for updating a sent message via the ‘chat.update’ API call

Kind: instance method of [RTMClient](#RTMClient)

Param Type Description
message object message The message object to be updated, see /lib/clients/web/facets/chat.js for more details
[optCb] function Optional callback

rtmClient.sendTyping(channelId)

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

Kind: instance method of [RTMClient](#RTMClient)

Param Type Description    
channelId string The id of the channel group DM to send this message to.

rtmClient.subscribePresence(userIds)

Subscribes this socket to presence changes for only the given userIds. This requires presence_sub to have been passed as an argument to start.

Kind: instance method of [RTMClient](#RTMClient)

Param Type Description
userIds Array The user IDs to subscribe to

rtmClient.send(message, [optCb])

Sends a message over the websocket to the server.

Kind: instance method of [RTMClient](#RTMClient)

Param Type Description
message \* The message to send back to the server.
[optCb] function