Skip to content

Allow channel management to be disabled - #16

Closed
neilberkman wants to merge 4 commits into
ryanwinchester:mainfrom
neilberkman:optional-channel-server
Closed

neilberkman wants to merge 4 commits into
ryanwinchester:mainfrom
neilberkman:optional-channel-server

Conversation

@neilberkman

@neilberkman neilberkman commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Starting a bot always discovers its conversations, which needs channels:read, groups:read, im:read and mpim:read even when the bot doesn't use channel management (for example a bot that only sends DMs or handles interactions). This adds channels: false to skip the channel server, the message queues and their registries. Socket Mode, the task supervisors and event callbacks stay on, including member_joined_channel and channel_left, which are still dispatched to the bot. Omitting channels keeps today's behavior. The README documents the option and direct Slack.API.post("chat.postMessage", ...) when the queues are off, since send_message/2 needs them.

Rebased onto main after #15: events_api envelopes pass the channels flag through handle_envelope, interactions are unchanged, and the message clauses keep your %{id: bot_id} fix. Slack.Socket.start_link/1 keeps your {app_token, bot, ssl_options} form (it defaults channel management on) and the supervisor passes {app_token, bot, ssl_options, channels?}. The supervisor tests now stub WebSockex.start_link/4.

Tested with mix test --warnings-as-errors (43 passed), mix format --check-formatted, mix compile --warnings-as-errors in dev and test, and mix dialyzer. This branch is stacked on #17 (the credo fixes for main), so its first commit is #17's; merge #17 first and this PR's diff drops to the channels commit. mix credo passes on the stack.

@neilberkman
neilberkman force-pushed the optional-channel-server branch 2 times, most recently from 00913ae to 200bcc7 Compare October 28, 2026 02:21
Re-raise the CA load error with the original stacktrace, and name the
test certificate's curve by atom instead of its raw OID.
@neilberkman
neilberkman force-pushed the optional-channel-server branch from 200bcc7 to 37b6bf0 Compare October 28, 2026 02:23
- send_message/2 raises with channels: false instead of silently
  dropping the message.
- channels: true and nil keep the defaults, and other non-list values
  raise a clear ArgumentError instead of crashing in ChannelServer.
- Decide channels? once in the supervisor, and pass state.channels? to
  every handle_slack_event call instead of defaulting it to true.
- ChannelServer starts the message servers for the channels it found
  directly, so they are no longer added to its state twice, and are
  running once it has started.
- Test join/part dispatch in the socket tests, including that it's
  skipped with channels: false, verify supervisor test expectations,
  and check the 3-tuple Socket.start_link defaults channels? to true.
- README: give channels its own section, and list chat:write.
- send_message/2 starts a queue for a channel the bot hasn't joined yet
  (a new DM, or a join still on its way), through the ChannelServer so
  a pending join is handled first. Without queues (channels: false, or
  Slack.Supervisor not running) it logs an error and returns
  {:error, :no_message_queues} instead of raising.
- Add post_message/3 to send right away without a queue, and use it
  for the queued messages too.
- Leaving a channel stops its queue through the DynamicSupervisor, so
  it isn't restarted, and leaving a channel without a queue is a no-op.
- Joining a channel that already has a queue reuses it, so a restarted
  ChannelServer or a rejoin no longer crashes.
- Handle group_left, which Slack sends when the bot leaves a private
  channel, and subscribe to it in the README.
- Check channels? once, before dispatching, instead of threading it
  through every handle_slack_event clause, and drop the unused 3-tuple
  Socket.start_link.
- Only accept a keyword list for channels.
- README: the join and leave subscriptions still need channels:read,
  groups:read and mpim:read with channels: false.
@neilberkman

Copy link
Copy Markdown
Contributor Author

Closing in favor of #18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants