Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Type parameters

  • EventTypes: string | symbol

Hierarchy

Index

Constructors

constructor

  • new RTMClient(token: string, __namedParameters?: object): RTMClient
  • Parameters

    • token: string
    • Optional __namedParameters: object
      • agent: undefined | Agent
      • autoReconnect: undefined | false | true
      • clientPingTimeout: undefined | number
      • logLevel: undefined | ERROR | WARN | INFO | DEBUG
      • logger: undefined | Logger | LoggingFunc
      • replyAckOnReconnectTimeout: undefined | number
      • retryConfig: undefined | RetryOptions
      • serverPongTimeout: undefined | number
      • slackApiUrl: undefined | string
      • tls: undefined | TLSOptions
      • useRtmConnect: undefined | false | true

    Returns RTMClient

Properties

Optional activeTeamId

activeTeamId: undefined | string

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

Optional activeUserId

activeUserId: undefined | string

The user ID for the connected client.

Private Optional agentConfig

agentConfig: any

An agent used to manage TCP connections for requests. Most commonly used to implement proxy support. See npm packages tunnel and https-proxy-agent for information on how to construct a proxy agent.

authenticated

authenticated: boolean

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.

Private autoReconnect

autoReconnect: any

Whether this client will automatically reconnect when (not manually) disconnected

Private awaitingReplyList

awaitingReplyList: any

A list of cancelable Promises that each represent a caller waiting on the server to acknowledge an outgoing message with a response (an incoming message containing a "reply_to" property with the outgoing message's ID). This list is emptied by canceling all the promises when the client no longer expects to receive any replies from the server (when its disconnected or when its reconnected and doesn't expect replies for past outgoing messages). The list is a sparse array, where the indexes are message IDs for the sent messages.

connected

connected: boolean

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

Private keepAlive

keepAlive: any

The instance of KeepAlive used to monitor this client's connection.

Private logger

logger: any

This object's logger instance

Private messageId

messageId: any

The last message ID used for an outgoing message

Private nextMessageId

nextMessageId: any

Atomically increments and returns a message ID for the next message.

Private onWebsocketMessage

onWebsocketMessage: any

onmessage handler for the client's websocket. This will parse the payload and dispatch the relevant events for each incoming message.

Private outgoingEventQueue

outgoingEventQueue: any

A queue of tasks used to serialize outgoing messages and to allow the client to buffer outgoing messages when its not in the 'ready' state. This queue is paused and resumed as the state machine transitions.

Private replyAckOnReconnectTimeout

replyAckOnReconnectTimeout: any

The number of milliseconds to wait upon connection for reply messages from the previous connection. The default value is 2 seconds.

Private setupWebsocket

setupWebsocket: any

Set up method for the client's websocket instance. This method will attach event listeners.

Private Optional startOpts

startOpts: any

A cache of the options used to start the connection, so that it can be reused during reconnections.

Private stateMachine

stateMachine: any

State machine that backs the transition and action behavior

Private stateMachineConfig

stateMachineConfig: any

Configuration for the state machine

Private teardownWebsocket

teardownWebsocket: any

Tear down method for the client's websocket instance. This method undoes the work in setupWebsocket(url).

Private tlsConfig

tlsConfig: any

Configuration for custom TLS handling

Private useRtmConnect

useRtmConnect: any

Use the rtm.connect method to connect when true, or the rtm.start method when false

Private webClient

webClient: any

Internal use web client

Private Optional websocket

websocket: any

The client's websocket

Static EventEmitter

EventEmitter: EventEmitterStatic

Static Private loggerName

loggerName: any

The name used to prefix all logging generated from this object

Static prefixed

prefixed: string | boolean

Methods

addListener

  • addListener(event: EventTypes, fn: ListenerFn, context?: any): this
  • Parameters

    • event: EventTypes
    • fn: ListenerFn
    • Optional context: any

    Returns this

addOutgoingEvent

  • addOutgoingEvent(awaitReply: true, type: string, body?: undefined | __type): Promise<RTMCallResult>
  • addOutgoingEvent(awaitReply: false, type: string, body?: undefined | __type): Promise<void>
  • 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

    • Optional body: undefined | __type

      the message body

    Returns Promise<RTMCallResult>

  • Parameters

    • awaitReply: false
    • type: string
    • Optional body: undefined | __type

    Returns Promise<void>

disconnect

  • disconnect(): Promise<void>
  • 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(event: EventTypes, ...args: Array<any>): boolean
  • Calls each of the listeners registered for a given event.

    Parameters

    • event: EventTypes
    • Rest ...args: Array<any>

    Returns boolean

eventNames

  • eventNames(): Array<EventTypes>
  • Return an array listing the events for which the emitter has registered listeners.

    Returns Array<EventTypes>

listenerCount

  • listenerCount(event: EventTypes): number
  • Return the number of listeners listening to a given event.

    Parameters

    • event: EventTypes

    Returns number

listeners

  • Return the listeners registered for a given event.

    Parameters

    • event: EventTypes

    Returns Array<ListenerFn>

off

  • off(event: EventTypes, fn?: ListenerFn, context?: any, once?: undefined | false | true): this
  • Parameters

    • event: EventTypes
    • Optional fn: ListenerFn
    • Optional context: any
    • Optional once: undefined | false | true

    Returns this

on

  • on(event: EventTypes, fn: ListenerFn, context?: any): this
  • Add a listener for a given event.

    Parameters

    • event: EventTypes
    • fn: ListenerFn
    • Optional context: any

    Returns this

once

  • once(event: EventTypes, fn: ListenerFn, context?: any): this
  • Add a one-time listener for a given event.

    Parameters

    • event: EventTypes
    • fn: ListenerFn
    • Optional context: any

    Returns this

removeAllListeners

  • Remove all listeners, or those of the specified event.

    Parameters

    Returns this

removeListener

  • removeListener(event: EventTypes, fn?: ListenerFn, context?: any, once?: undefined | false | true): this
  • Remove the listeners of a given event.

    Parameters

    • event: EventTypes
    • Optional fn: ListenerFn
    • Optional context: any
    • Optional once: undefined | false | true

    Returns this

send

  • send(type: string, body?: undefined | __type): Promise<number>
  • 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

    • Optional body: undefined | __type

      the message body

    Returns Promise<number>

sendMessage

  • 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>

  • Parameters

    Returns void

sendTyping

  • sendTyping(conversationId: string): Promise<void>
  • 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?: methods.RTMStartArguments | methods.RTMConnectArguments): Promise<WebAPICallResult>
  • Begin an RTM session using the provided options. This method must be called before any messages can be sent or received.

    Parameters

    • Optional options: methods.RTMStartArguments | methods.RTMConnectArguments

    Returns Promise<WebAPICallResult>

subscribePresence

  • subscribePresence(userIds: string[]): Promise<void>
  • 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>

Generated using TypeDoc