Commit 5c91bbb
committed
feat(plugin-slack): role-aware outbound client routing — OWNER posts as user
Adds the runtime primitive PR #7868 unblocks: when a Slack
account is configured with role: "OWNER" and a user token (xoxp-)
is present, outbound chat.postMessage calls go through a second
WebClient bound to the user token so the agent acts as the user.
AGENT accounts continue to use the bot client (xoxb-), preserving
all existing single-bot deployments unchanged.
Changes:
- accounts.ts:
* SlackAccountConfig gains an optional `role` field.
* ResolvedSlackAccount gains a required `role: ConnectorAccountRole`.
* `resolveSlackAccount` reads role from per-account character.settings
or the SLACK_ACCOUNT_ROLE env var (default-account only); falls
back to "AGENT". Config role beats env role.
* New `normalizeSlackAccountRole` helper accepts OWNER/AGENT/TEAM
(mixed case, trimmed) and defaults unknown / non-string input to
AGENT.
- service.ts:
* SlackAccountRuntime gains `userClient: WebClient | null`,
constructed in `initializeAccount` only when `account.userToken`
is set. The user client is outbound-only — no socket mode.
* New private `getOutboundClient(accountId)` selects the user
client when the account's role is OWNER and a user client
exists; otherwise the bot client. Falls back to
`getClientForAccount` when per-account state hasn't been
initialised yet.
* `sendMessage` switches from `getClientForAccount` to
`getOutboundClient`. Other call sites stay on the bot client
because Slack's user-scope grant for chat:write covers
chat.postMessage only — broadening to reactions/pins/files
requires additional user scopes and is left for a follow-up.
- accounts.test.ts (new, 8 tests):
* normalizeSlackAccountRole canonical / mixed-case / fallback paths.
* resolveSlackAccount role resolution from config, env, default,
and config-beats-env precedence.
Out of scope (separate PR):
- Hydration of `botToken` / `userToken` / `role` from
ConnectorAccount records persisted by the OAuth callback
(#7868). The credential-refs read path is not currently
exposed by ConnectorAccountManager; adding it would mean a
cross-plugin runtime change. Today admins who want OWNER
routing must set the role + userToken in
character.settings.slack.accounts.<id> (or via the
SLACK_ACCOUNT_ROLE + SLACK_USER_TOKEN env pair for the default
account). Once hydration lands, the OWNER routing in this PR
picks up the OAuth-stored xoxp- automatically.
Verification:
- bunx tsc --noEmit -p plugins/plugin-slack/tsconfig.json: clean
- bunx vitest run plugins/plugin-slack/src/: 17/17 (8 new + 9 existing)1 parent e57124a commit 5c91bbb
3 files changed
Lines changed: 195 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
84 | 92 | | |
85 | 93 | | |
86 | 94 | | |
| |||
138 | 146 | | |
139 | 147 | | |
140 | 148 | | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
141 | 155 | | |
142 | 156 | | |
143 | 157 | | |
| |||
190 | 204 | | |
191 | 205 | | |
192 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
193 | 223 | | |
194 | 224 | | |
195 | 225 | | |
| |||
359 | 389 | | |
360 | 390 | | |
361 | 391 | | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
362 | 401 | | |
363 | 402 | | |
364 | 403 | | |
365 | 404 | | |
| 405 | + | |
366 | 406 | | |
367 | 407 | | |
368 | 408 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
317 | 317 | | |
318 | 318 | | |
319 | 319 | | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
320 | 328 | | |
321 | 329 | | |
322 | 330 | | |
| |||
717 | 725 | | |
718 | 726 | | |
719 | 727 | | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
720 | 736 | | |
721 | 737 | | |
722 | 738 | | |
723 | 739 | | |
724 | 740 | | |
| 741 | + | |
725 | 742 | | |
726 | 743 | | |
727 | 744 | | |
| |||
897 | 914 | | |
898 | 915 | | |
899 | 916 | | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
900 | 936 | | |
901 | 937 | | |
902 | 938 | | |
| |||
2855 | 2891 | | |
2856 | 2892 | | |
2857 | 2893 | | |
2858 | | - | |
| 2894 | + | |
2859 | 2895 | | |
2860 | 2896 | | |
2861 | 2897 | | |
| |||
0 commit comments