feat: add slack api command#538
Conversation
Adds a new top-level `slack api <method> [key=value ...] [flags]` command that calls any Slack API method with automatic token resolution, body format detection, and response formatting. Token resolution priority: --token flag, --app/--team flags (via AppSelectPrompt in project), SLACK_BOT_TOKEN env, SLACK_USER_TOKEN env, interactive prompt fallback. Supports form-encoded key=value params, JSON auto-detection, --json and --data flags, custom headers (-H), HTTP method override (-X), response header display (--include), and TTY-aware pretty printing.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #538 +/- ##
==========================================
+ Coverage 71.30% 71.52% +0.21%
==========================================
Files 222 224 +2
Lines 18695 18927 +232
==========================================
+ Hits 13331 13537 +206
- Misses 4184 4190 +6
- Partials 1180 1200 +20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Token resolution now errors if no token is found rather than falling back to a workspace selection prompt. Users must provide a token via --token, --app, or SLACK_BOT_TOKEN/SLACK_USER_TOKEN env vars.
srtaalej
left a comment
There was a problem hiding this comment.
This is looking great! ⭐ thanks for adding the test commands in the description 🫂
the command is working great except
lack api auth.test | cat
the test implies there should be JSON output but slack api auth.test is an interactive prompt so it errors out instead. perhaps we update the pr description? the command should be
lack api auth.test --token xoxb-... | cat
lack api auth.test --app A... | cat
right?
| attempts++ | ||
| if attempts == 1 { | ||
| w.Header().Set("Retry-After", "1") | ||
| w.WriteHeader(http.StatusTooManyRequests) |
There was a problem hiding this comment.
qq: does this cover retries on both 429 and 503 returns 🤔
srtaalej
left a comment
There was a problem hiding this comment.
left 2 testing-related comments/ questions but this is working great ! ⭐ ⭐ ⭐ such a handy command
Changelog
Summary
Adds a new top-level
slack apicommand that lets users call any Slack API method without leaving the terminal.Key features:
--tokenflag--appflagSLACK_BOT_TOKENenv varSLACK_USER_TOKENenv varslack api chat.postMessage channel=C123 text="hi"slack api chat.postMessage '{"channel":"C123","text":"hi"}'--json <string>and--data <string>slack api chat.postMessage --data 'channel=C123 text="hi"'slack api chat.postMessage --json '{"channel":"C123","text":"hi"}'-X)-H)--include)Open Questions
Preview
Post Message as Form Data (with app selection prompt):
2026-05-10-slack-cli-api-1.mov
Post Message as JSON (with app selection prompt):
2026-05-10-slack-cli-api-2.mov
Post Message with Custom Token
--token:2026-05-10-slack-cli-api-3.mov
JSON Responses are Pretty-Printed in TTY:
2026-05-10-slack-cli-api-5.mov
JSON Responses are Condense in Scripting/Non-TTY:
2026-05-10-slack-cli-api-4.mov
--includeAll Response Headers:2026-05-10-slack-cli-api-6.mov
Testing
slack api --help- shows correct token priority and examplesslack api auth.test --token xoxb-...- returns auth infoslack api auth.test --app local- installs app and uses bot token (in project)SLACK_BOT_TOKEN=xoxb-... slack api auth.test- uses env var (outside project)slack api auth.test- prompts interactively when no flags/env set (in project)slack api chat.postMessage channel=C123 text="hi"- sends form-encoded bodyslack api chat.postMessage '{"channel":"C123","text":"hi"}'- auto-detects JSONslack api auth.test --include- shows HTTP status and response headersslack api auth.test | cat- outputs compact JSON (non-TTY)go test ./cmd/api/... ./internal/api/...- all unit tests passRequirements