Slack: authenticate as a real member with a user token - #22
Merged
Merged
Conversation
chat_slack()'s token is a bot token, and chat_send()'s identity/ username only relabel that bot's own post with a cosmetic name and icon -- there was no way to actually post or resolve identity as a real workspace member. Add an optional user_token (xoxp-...) to chat_slack(), and an as_user = TRUE flag on chat_send()/chat_whoami() that authenticates with it instead of the bot token, so a send shows the member's real name and photo. Confined to the Slack adapter; identity/username and as_user are separate mechanisms and chat_capabilities()$user_identity reports whether a given client is configured for the latter. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F1QZ4ESCCu2V94jus4rzM3
- Send username and icon_emoji as empty strings on the as_user path too. Omitted, slackr fills them from SLACK_USERNAME and SLACK_ICON_EMOJI, which is exactly what the bot path suppresses. - Every adapter answers user_identity, FALSE outside Slack, and the contract loop checks it: a consumer reading NULL cannot tell an adapter with no such thing from a client not given a token. The flag is documented on chat_capabilities(). - Note in chat_slack()'s docs that an as_user post is the member's own message to this client's poll as well, since Slack carries no self. - Regenerate man pages with the repo's tinyrox.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
chat_slack()'stokenis a bot token, andchat_send()'sidentity/usernameonly relabel that bot's own post with a cosmetic name and icon (needschat:write.customize) — there was no way to actually authenticate as a real workspace member.user_token(xoxp-...) tochat_slack(), and anas_user = TRUEflag onchat_send()/chat_whoami()that authenticates with it instead of the bot token — a send then shows the member's real name and photo in Slack, confirmed viaauth.test.R/slack.R) — no changes tocontract.Ror any other adapter.identity/usernameandas_userare separate mechanisms and can't be combined meaningfully (a user-token send carries no bot identity to relabel, sousername/icon_emojiare simply not sent on that path).chat_capabilities()$user_identityreports whether a given client instance was configured with a user token — flagged in review as a deliberate departure from every other capability flag here (per-instance rather than static-per-adapter), since there's no construction-time failure to fail with the way a missing bot token already has.Raised with Troy first; this PR follows his go-ahead.
Test plan
tinytest::test_package("chat.api", pattern = "slack")— all 134 tests pass (100 pre-existing + 34 new, covering constructor storage,as_usersend routing, missing-token errors, dualchat_whoami()caching, and the capability flag)test_matrix_mxclient.Rfailures on this box are present on unmodifiedmaintoo (localmx.clientversion mismatch, unrelated to this change)tinyrox::document()regenerateschat_slack.Rdcorrectly once merged (the local run also picked up an unrelated, pre-existing tinyrox-version formatting change across ~24 other man pages; excluded from this diff to keep it focused — happy to open that separately if wanted)🤖 Generated with Claude Code
https://claude.ai/code/session_01F1QZ4ESCCu2V94jus4rzM3