Slack. Sends
(SlackKit v1.0.0-alpha.0)
View Source
Helpers for writing frames back through an open RTM WebSocket.
These functions are imported into any module that does use Slack, so
inside a bot callback you can write send_message("hi", channel, slack)
directly. They serialise messages to JSON and cast them onto the WebSocket
process referenced by the Slack.State you pass in — so they require an
active RTM connection.
For richer messages (attachments, blocks, files, ephemeral posts), use the
generated Web API modules (Slack.Web.Chat, Slack.Web.Files, etc.)
instead — send_message/3 covers only plain text.
Summary
Functions
Notifies Slack that the bot is typing in channel.
Sends text to channel over the RTM WebSocket held by slack.
Same as send_message/3, but threads the message under an existing parent.
Sends a ping frame, optionally merging extra fields into the payload.
Casts an already-encoded JSON string onto the RTM WebSocket.
Subscribes to presence_change events for ids.
Types
@type channel() :: String.t()
@type slack() :: Slack.State.t() | %{process: pid(), client: module()}
Functions
Notifies Slack that the bot is typing in channel.
Slack clients render the "@bot is typing…" indicator for a few seconds
after this is called. There is no acknowledgement.
Sends text to channel over the RTM WebSocket held by slack.
channel may be:
- a channel name prefixed with
#(e.g."#general") — resolved viaSlack.Lookups.lookup_channel_id/2 - a user ID starting with
UorW— the message is sent to the open
DM channel for that user, opening one viaim.openif necessary - a user reference starting with
@(deprecated; see
Slack's changelog) - any channel ID that Slack accepts directly (
"C…","G…","D…")
Raises ArgumentError if #CHANNEL_NAME cannot be resolved against the
current state.
Same as send_message/3, but threads the message under an existing parent.
thread is the ts of the message you want to reply to — use the
top-level parent's ts, not a nested reply's. RTM threaded replies are
always posted, never broadcast back to the channel; for reply_broadcast
support, use the Web API (Slack.Web.Chat).
Sends a ping frame, optionally merging extra fields into the payload.
Slack replies with a matching pong. The default Slack.WebSocketClient
already issues low-level WebSocket keepalive pings; this is the
application-level RTM ping, useful when you want to round-trip a custom
payload such as a request id.
Casts an already-encoded JSON string onto the RTM WebSocket.
Escape hatch for RTM event types Slack.Sends doesn't wrap directly. The
string must be a complete, well-formed JSON message — Slack will close the
connection on malformed frames.
Subscribes to presence_change events for ids.
Slack's RTM no longer broadcasts presence updates by default — callers
must opt-in per user. Pass a list of user IDs to start receiving events;
pass [] to clear the subscription.