Slack. State
(SlackKit v1.0.0-alpha.0)
View Source
Workspace snapshot maintained for a running Slack.Bot.
Each callback in a module that does use Slack receives a %Slack.State{}
as its slack argument. The struct starts from the payload Slack returns onrtm.start and is rolled forward by update/2 as each RTM event arrives,
so the maps you read inside a callback always reflect the latest known
state of the workspace.
Fields
| Field | Description |
|---|---|
:me | The bot's own identity (id, name, profile). |
:team | The workspace's identity (id, name, domain). |
:bots | Map of bot_id => bot for bots known to the workspace. |
:channels | Map of channel_id => channel for public channels. |
:groups | Map of channel_id => channel for private channels. |
:users | Map of user_id => user. Includes :presence as it's reported. |
:ims | Map of channel_id => im for open direct-message channels. |
:process | PID of the Slack.Bot GenServer driving the WebSocket. |
:client | Module implementing the WebSocket transport — used by Slack.Sends. |
:token | The bot's Slack API token. |
All entity maps use Slack's string IDs as keys. The values are atom-keyed
maps mirroring the Slack API types — for
example slack.users["U123"].profile.display_name.
Access
Slack.State implements the Access behaviour and is keyed like a map, so
the standard get_in/put_in/update_in helpers work directly against it:
get_in(slack, [:channels, "C123", :name])
put_in(slack, [:users, "U123", :presence], "away")Updating from RTM events
update/2 pattern-matches on event.type and folds the event into the
state. Supporting a new RTM event type means adding another update/2
clause here. Unrecognised events fall through to a catch-all and leave the
state untouched.
Summary
Functions
Callback implementation for Access.fetch/2.
Callback implementation for Access.get_and_update/3.
Callback implementation for Access.pop/2.
Folds a single RTM event into slack, returning the updated state.
Types
Functions
Callback implementation for Access.fetch/2.
See Map.get/3.
Callback implementation for Access.get_and_update/3.
Callback implementation for Access.pop/2.
Folds a single RTM event into slack, returning the updated state.
Recognised event types include channel_created, channel_joined,channel_left, channel_rename, channel_archive, channel_unarchive,
their group_* equivalents, team_rename, team_join, user_change,presence_change, bot_added, bot_changed, im_created, and themessage subtypes that signal topic/join/leave changes. Any other event is
returned unchanged.