rtm

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package rtm is a hand-written client for Slack's legacy Real Time Messaging API — the WebSocket stream that works with a user/session token (xoxc+xoxd), the credential a browser web-client session already has. Unlike Socket Mode (which needs an app-level token and acks enveloped work items), RTM delivers raw event objects and requires no ack; the client just reads frames and keeps the socket alive with periodic pings. RTM is legacy and not officially supported for xoxc tokens — see DECISIONS.md ("listen transports").

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// OpenURL fetches a fresh wss:// URL (rtm.connect). RTM URLs are single-use and must be
	// connected within ~30s, so every (re)connection asks for a new one.
	OpenURL func(ctx context.Context) (string, error)
	// Dial opens the websocket. Defaults to coder/websocket; injectable for tests.
	Dial func(ctx context.Context, url string) (conn, error)
	// Log receives connection-lifecycle notes (connected, reconnecting). Never event data.
	Log io.Writer
	// Header carries credential headers on the WebSocket handshake. For a browser-session
	// token this holds `Cookie: d=<xoxd>`, which the RTM gateway validates on the UPGRADE —
	// the URL ticket alone answers invalid_auth for xoxc tokens.
	Header http.Header
	// PingInterval is how often to send an application-level RTM ping to keep the
	// connection alive. Zero uses the 30s default; negative disables pings (tests).
	PingInterval time.Duration
	// contains filtered or unexported fields
}

Client streams raw RTM event frames.

func New

func New(openURL func(ctx context.Context) (string, error), logW io.Writer) *Client

New builds a Client over an OpenURL func (which calls rtm.connect).

func (*Client) Run

func (c *Client) Run(ctx context.Context, handler func(json.RawMessage)) error

Run connects and streams every event frame to handler until ctx is cancelled. RTM needs no per-event ack. Reconnects (socket error, expired URL) fetch a fresh URL with full-jitter backoff; the backoff resets after each successful hello.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL