Skip to content

Fix Slack log driver: post straight to chat.postMessage - #327

Open
claude-tmgbedu wants to merge 2 commits into
mainfrom
task/slack-log-driver
Open

claude-tmgbedu wants to merge 2 commits into
mainfrom
task/slack-log-driver

Conversation

@claude-tmgbedu

Copy link
Copy Markdown

Summary

  • The Slack log driver called channels.list (retired by Slack in 2021) to resolve the channel id, so every Slack log crashed with KeyError: 'channels'.
  • The lookup and find_channel are removed. send posts JSON to chat.postMessage with Authorization: Bearer <token> and the configured channel as is (#alerts or a channel id), with a 10 s timeout.
  • HTTP error statuses raise requests.HTTPError. An ok: false response raises SlackApiError with the Slack error code, and channel_not_found raises SlackChannelNotFound, now a SlackApiError subclass.
  • The config surface is unchanged (channel, token, emoji, username, level, driver). ADR 044 explains the change.

Config

"slack": SlackChannel(
    channel="#alerts",
    token=env("SLACK_TOKEN"),
    level="error",
),

Tests

  • Mocked requests.post. The tests check the chat.postMessage URL, #alerts, the bearer header, the message text, and that channels.list is never called. They also cover ok:false → SlackApiError, channel_not_found → SlackChannelNotFound, HTTP error propagation, and that None fields are omitted.
  • pytest --ignore=tests/masoniteorm/postgres --cov: 3496 passed, coverage 92.24%. ruff and basedpyright are clean.

🤖 Generated with Claude Code

The driver resolved channel ids through channels.list, which Slack retired
in 2021, so every Slack log raised KeyError 'channels'. chat.postMessage
accepts a channel name or id, so the lookup is dropped. The token moves to
the Authorization header, HTTP errors and ok:false responses raise
SlackApiError (SlackChannelNotFound for channel_not_found), and requests
time out after 10 seconds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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