Skip to content

Commit 8e46424

Browse files
feat(messaging): Slack DM delivery — slack channel, per-person link store, approval requests by DM (Part of #34730) (#35789)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} --> _Requested by **Elon** · [project thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9D62xGLMbyWJaMEVnAMEjTK1)_ Part of #34730 Clause-②: yes (widening) Metadata-protocol: added Skills-docs: none — skills/objectstack-automation states `channels` as RAW with default inbox and lists no channel values (its evals use `inbox` / `email` only), so no skill sentence becomes false; `slack` delivers only where connector-slack is composed. ## 维护者速读 - 用户能看到的变化:在接入了 Slack 连接器的部署上,组织管理员可以接入本组织自己的 Slack 应用,通知设置页和流程的通知节点多出 Slack 这个渠道;邮箱已验证的成员确认与自己的 Slack 账号关联后,审批请求会以 Slack 私信送达,私信里的链接与审批邮件指向同一页面;没有关联的人照旧只收站内信和邮件。 - 为什么做:这是「Slack 私信通知」专题的第二步(服务端部分),让审批人不必盯着控制台铃铛或邮箱。 - 出错会怎样:最坏是某位审批人收不到 Slack 私信,或令牌失效后该组织停发私信,站内信和邮件不受影响;没有接入 Slack 连接器的部署,通知设置页和流程可选的渠道都不变,只多出两张空表、几个回答「未接入 Slack」的接口,以及通知设置页里一个新的通知主题「Slack 关联被移除」(`messaging.slack_link_removed`,所有部署都会列出,但只有接入 Slack 的部署才会真的发出);整个改动可以直接撤回。 - 要你做什么:无。 ## What changes Server side of step 2 of #34730 (ADR-0013 addendum of 2026-11-19, ruling of record 7023437637, riders of 7024100939). One PR, as ordered; the settings page UI is step 3. - **Binding store** (`service-messaging`): two new engine-owned objects. `sys_channel_account` is one organization's Slack install, one row per organization (unique per organization on `channel_id`), with the bot token in `bot_token`, a `secret` field. `sys_channel_user_link` is a person's link to their own Slack user, `proposed` then `confirmed`; `user_id` cascades (as `sys_user_device`), `account_id` cascades, and the indexes allow one link per person per install and one person per Slack user per install. `SlackLinkStore` (`slack-links.ts`) does every read and write; each write is an engine write under a system context naming who acted, so the platform's write audit records each creation, confirmation and removal with its actor. - **Proposal and confirm**: a Slack link is proposed only for a verified email and names no one before it is confirmed. A proposal looks the person's own email up with Slack `users.lookupByEmail` only while `sys_user.email_verified` reads verified (`isEmailVerifiedUserRow`); an unverified email gets exactly the answer no match gets, and Slack is not asked. No match, a deleted or bot Slack user, or a Slack user already linked in the install proposes nothing. Before the person confirms, no answer names the Slack user: the person's own view of a proposal is `{ state: 'proposed' }`, and the administrator's list shows it with `slackUserId` and `slackUserName` null. A confirmation holds only while the email is still verified and still the one the proposal was made for (the link keeps its SHA-256 digest, `proposal_email_hash`); otherwise `409 RESOURCE_CONFLICT`, whose sentence is in all eleven locales and answered as the envelope's `userMessage` in the caller's language. Confirm applies only to the proposal that was checked: the write is conditioned on the link's id, its `proposed` state and that email digest (a predicate write, `multi: true`), and a write that changes no row answers the same `409`. A new proposal replaces one made for another email. A proposal delivers nothing until the person confirms it. - **Doors** (`slack-link-routes.ts`, nine routes, all in the messaging route ledger, all with an empty closed query set): - the person, about themselves in their current organization: `GET`/`DELETE /api/v1/messaging/me/slack-link`, `POST /api/v1/messaging/me/slack-link/proposal`, `POST /api/v1/messaging/me/slack-link/confirm`; - an organization administrator: `GET`/`PUT`/`DELETE /api/v1/messaging/slack/account` (`PUT` takes only `{ token }`, proven with Slack `auth.test` before anything is saved; a token for another workspace than the installed one is refused 409), `GET /api/v1/messaging/slack/links`, `DELETE /api/v1/messaging/slack/links/:id`. - **The admin permission (rider 5)**: `SLACK_ADMIN_CAPABILITY = 'setup.write'`, held in the caller's current organization (`ExecutionContext.systemPermissions`), the capability the in-app message door already asks of an organization administrator; not `isPlatformAdmin`. - **Riders (ruling 7024100939)**: (1) every removal is an attributed engine delete, so the write audit records it; (2) an administrator's removal, one link or the whole install, emits `messaging.slack_link_removed` to the person on inbox and email, translated in all eleven locales (keyed text); one link is found by a pushed-down read on its id and the install, and the uninstall reads the install's links in pages, in id order, so every linked person is told; (3) a link goes with the person (cascade), when they are banned (`sys_user` update setting `banned`), and when their `sys_member` row in that organization is deleted or moved, through engine hooks registered by the plugin and unregistered on `destroy`; (4) an administrator's removal deletes the link, so the person can propose and confirm again at once. - **`slack` channel** (`slack-channel.ts`): registered only on a composition where connector-slack's `slack` client service resolves at `kernel:ready` (`ConnectorSlackPlugin` registers it at init), then mounted per lookup like email/sms/push. Without it the messaging service does not know `slack`, so the `/automation` save doors still refuse a `notify` node naming it (400) and the two preference doors do not list it, as on `main`. With it, `slack` is a new accepted value on a `notify` node, hence `Metadata-protocol: added`. `isAvailable` answers the organization (an active install, else `transport_not_configured`). It sends `conversations.open` then `chat.postMessage` with the title in bold, linked to the notification's deep link made absolute under `OS_AUTH_URL` (legacy `BETTER_AUTH_URL`), then `OS_BASE_URL` (the same chain the approval email's link defaults to), then the body; Slack's control characters are escaped and unfurling is off. Classification: a refused token (`invalid_auth`, `token_revoked`, `token_expired`, `account_inactive`, `not_authed`) is `permanent` and marks the install `revoked`; a person Slack cannot DM, or a link gone by send time, is `invalid_recipient` (suppressed, never dead); HTTP 429 or `ratelimited` is `rate_limited` (retried); anything else is retryable. The DM carries no text of its own, so it needs no catalog keys. - **Per-recipient skip** (`channel.ts`, `messaging-service.ts`): `MessagingChannel` gains an optional `reachableRecipients`. Fan-out asks each channel that has it once per emit, after the preference filter, and drops the recipients it cannot reach on that channel before any delivery row exists: no row, no send, no failure, no `suppressed_channels` entry. A throw keeps everyone (fail-open, `warn`). Preferences, digest and quiet hours run before it as for every channel. - **connector-slack**: `ConnectorSlackPlugin` registers a `slack` service, `createSlackClientService(options)`, whose `client(token)` sends with a token the caller holds (each organization's own), over the plugin's transport options. service-messaging reaches it through the service registry because importing connector-slack would close a workspace cycle (measured: turbo `Cyclic dependency detected`, via connector-slack's devDependency on service-automation). - **First consumer** (`plugin-approvals`, one hunk at the emit site): `approval.requested` also asks for `slack`, and only while the composition mounts the channel, so a deployment without connector-slack does not log a refusal on every request. `ApprovalMessagingSurface` declares the optional `getChannel` it reads. - **Hardening of token input and proposal audit** (`slack-link-routes.ts`, `slack-links.ts`), pinned in `slack-links.integration.test.ts`. - **Registries**: `PLATFORM_OBJECTS_BY_PACKAGE['service-messaging']` lists the two objects (the registry's own contract: "Each group is the exact set that package registers"), the organization ownership inventory gives each a row (fate `attribution`; a link's install carries its organization), the tenancy census is regenerated, the objects are provisioned at boot and in the manifest, `messaging.slack_link_removed` joins the platform topic list, and the route-envelope gate's module list declares `slack-link-routes.ts` conformant (every body through the shared `sendOk` / `sendError` / `sendServerFault`). Touching `packages/spec` makes this Tier H, so per the claim amendment's fold rule ADR-0013's addendum is edited here (below). ## Step-2 choices (for the ADR follow-up) ADR-0013's addendum records, in this PR (fold rule of the claim amendment), the admin permission, the token store and the proposal rule, the choices its addendum asks step 2 to name; the other choices below are recorded in this body only: - **Admin permission**: `setup.write` in the caller's current organization. - **Proposal rule**: a Slack link is proposed only for a verified email and names no one before it is confirmed; the confirmation checks again that the email is verified and unchanged, and applies only to the proposal that was checked. - **Token at rest**: `sys_channel_account.bot_token`, a `secret` field (ADR-0100), the channel `sys_connector_credential` uses (ADR-0143). The engine encrypts it on write through the host's `ICryptoProvider`, with scope `object_secret_field`, namespace `sys_channel_account`, key `bot_token` and the organization as `tenantId` in the context; the ciphertext is a `sys_secret` row and the column holds only its reference; every read path masks it; the write audit masks it; only `resolveSecretField()` dereferences it, server side, called by `SlackLinkStore.slackFor` alone. No route answers it. The object is engine-owned, `apiEnabled: false` with no API methods, and `access: private`. With no crypto provider the write is refused (fail-closed). - **Multi-match**: one Slack user is linked to at most one person per install; a second person whose email resolves to an already linked Slack user is proposed nothing. ADR-0013's "Risks & open questions, item 4" (two `sys_user`s sharing one email) stays open; the cite in the addendum is corrected from "§8 risk 4". - **Who is asked for `slack`**: the producer (approvals) names the channel; fan-out is not changed to add channels. - **Skip, not dead-letter**: `reachableRecipients`, a per-recipient counterpart of `isAvailable`. - **Deep link origin**: the deployment's `OS_AUTH_URL` / `OS_BASE_URL` chain. ## Scope out - The DM's deep link keeps the deployment's env origin chain: for a canonical origin it opens the same page as the approval e-mail's link. A host that sets only approvals' `publicBaseUrl` and neither `OS_AUTH_URL` nor `OS_BASE_URL` gets an absolute link in the e-mail and none in the DM; one origin source for both is #35844. - `ConnectorSlackPlugin` still takes its static token option; making it optional is #35791. - The settings page UI is step 3. A step-3 follow-up goes with it, #35861: paging for the administrator's link list (`GET /api/v1/messaging/slack/links`), which today answers at most 10,000 links. The removals do not depend on that list: one link is read by its id and install, and the uninstall reads every link in pages. - **Changeset sentence owed, head left unmoved (seat N2 of 7040887222).** The topic `messaging.slack_link_removed` joins the platform topic list, so `GET /api/v1/messaging/preference-options` and `GET /api/v1/messaging/me/preferences` list it as a topic on every deployment, with or without connector-slack; only a deployment that composes connector-slack ever emits it. The changeset's channel bullet does not say so. It is not amended here, so as not to move the reviewed head; the next commit on this branch, or the step-3 PR, carries the sentence. ## Generated files (reviewers can skip) - The eleven-locale object bundles, written by `node scripts/check-i18n-bundles.mjs --write --filter=service-messaging` (the non-English labels then translated in place): `packages/services/service-messaging/src/translations/ar.objects.generated.ts`, `de.objects.generated.ts`, `en.objects.generated.ts`, `es-ES.objects.generated.ts`, `fr.objects.generated.ts`, `ja-JP.objects.generated.ts`, `ko.objects.generated.ts`, `pt-BR.objects.generated.ts`, `ru.objects.generated.ts`, `zh-CN.objects.generated.ts`, `zh-Hant.objects.generated.ts`. - Their fill records, by the same writer: `packages/services/service-messaging/src/translations/de.source-hashes.generated.ts`, `pt-BR.source-hashes.generated.ts`. - `scripts/platform-object-tenancy-census.json` (`node scripts/platform-object-tenancy-census.mjs --write`) and `pnpm-lock.yaml` (the approvals devDependency, +3). ## Evals This round (the review of `73b116f0fe`) runs on head `938fa8f8c8`: the round's commits, a merge of `origin/main` with no conflicts, and one test commit; `origin/main` had nothing newer at push time. The readings below this round's are from `73b116f0fe` and earlier, as each one names. <details><summary>This round, on 938fa8f: typecheck and full suites of service-messaging (78 files, 1054 tests), plugin-approvals (126 files, 1792 tests), connector-slack (3 files, 11 tests); runtime's touched files (21 tests)</summary> Under the shared verify lock (`VERDICT command-exit 0`), after building the dependency closure of runtime, plugin-approvals and cli under it (`VERDICT command-exit 0`): - service-messaging: `typecheck` exit 0; `vitest run` Test Files 78 passed (78), Tests 1054 passed (1054). - plugin-approvals: `typecheck` exit 0; `vitest run` Test Files 126 passed (126), Tests 1792 passed (1792). - runtime: `automation-notify-slack-composition.test.ts` and `automation-authoring-doors-durable.test.ts`: Test Files 2 passed (2), Tests 21 passed (21). The rest of runtime's suite is CI's (Test Core); runtime's published surface is unchanged. - connector-slack: Test Files 3 passed (3), Tests 11 passed (11). - Derived gates on `938fa8f8c8`: `node scripts/pm/dispatch-gates.mjs --commands` (137), every command run with its exit code captured before any pipe; `--ran` reconciliation: 137 derived, 135 run, 2 NOT MEASURED, 0 UNRUN. The two NOT MEASURED are `check:dual-build-cjs-loads` and `check:i18n-coverage` (exit 3, PREREQUISITE NOT MET: they read a full workspace build this box does not hold); CI runs both. `check:i18n` and `check:i18n-walk-parity` first answered exit 3 (the CLI not built) and are recorded from their rerun after building the CLI and the packages they extract under the lock: both exit 0, `check-i18n-bundles: OK (10 package(s) — all bundles in sync)`. `check:engine-double-contract` exit 0 (`OK — 1370 pinned`; the six seams this round adds are in the pinned ledger, written with `--write`; no baseline entry added); `check:platform-object-tenancy-census` exit 0 (108 objects, 57 in reach); `check:route-envelope` exit 0. The changeset gates with this body as the `pull_request` event: `check-changeset-no-major.mjs --base origin/main` exit 0, its level axis reading `Metadata-protocol: added` and `@objectstack/service-messaging: minor`; its `--self-test`, `check-adr-0087-registration`, `check-changeset-fixed` and `check-empty-changeset` exit 0. `overlap-check --branch=claude/area-a4W-34730-s2`: `VERDICT clean exit 0` (origin/main, #35129, #34223). New pins: - `slack-channel-composition.test.ts` (service-messaging, 2): a real `MessagingServicePlugin` without a `slack` service does not know or mount `slack`, and neither preference door lists it; with one, `slack` is known, mounted and listed by both. - `automation-notify-slack-composition.test.ts` (runtime, 2): over the same real plugin, a `notify` node naming `slack` is refused `400 VALIDATION_FAILED` at `POST /automation` without connector-slack and nothing is saved (a node naming `inbox` and `email` saves), and saves with it. - `slack-links.integration.test.ts` (now 20): an administrator removes only a link to their own organization's install (`404` otherwise); the uninstall tells every linked person across more than one page of links; rider 3's membership moved to another organization removes the link, audited as who moved it, and a membership write that keeps the organization removes nothing; a ban removes the person's links in every organization in one engine delete, with one audited `afterDelete` per removed link (measured over two installs: one `delete` call on `sys_channel_user_link`, two dispatches, each naming who banned); and the hardening of token input and proposal audit (3 cases). </details> <details><summary>service-messaging on 73b116f: typecheck + full suite (77 files, 1045 tests)</summary> `pnpm --filter @objectstack/service-messaging typecheck` exit 0; `vitest run` Test Files 77 passed (77), Tests 1045 passed (1045). New: `slack-links.integration.test.ts` (13: the token encrypted in the stored row, never in an answer, opening only under its organization; proposal and confirm; refusals; riders 1 to 5; the proposal rule: an unverified email answered exactly as no match with no `users.lookupByEmail` call made, a match naming no Slack user or Slack id to the person or an administrator before confirmation, a confirmation refused `409` once the email changed or is no longer verified with the sentence in the caller's language, an unchanged verified email confirming, a proposal row changed between the check and the write answered `409` and left unconfirmed, and a new proposal replacing one made for another email), `slack-channel.test.ts` (10: send, the five error classes, the unlinked recipient, the deep link and origin chain), `recipient-reach.test.ts` (3), ledger conformance (now enumerates the Slack doors). </details> <details><summary>plugin-approvals on 73b116f: typecheck + full suite (126 files, 1792 tests), including the Slack DM end to end (its approver's email now verified)</summary> `typecheck` (tsc, scripts tsconfig, `check:test-typecheck` OK at its recorded debt) exit 0; Test Files 126 passed (126), Tests 1792 passed (1792). `approval-requested-slack-dm.integration.test.ts`, real ObjectQL on SqlDriver, the real MessagingServicePlugin with its outbox and dispatcher, the real ApprovalsServicePlugin, connector-slack's real client stubbed at `fetch`: a confirmed link gets a `slack` delivery at `success`, `conversations.open` with the linked user, and a `chat.postMessage` whose link opens the same page as the approval email's (the same string, for the test's canonical origin); a muted `slack` and quiet hours send no DM; a proposed link and no link give `email` + `inbox` rows only; no connector-slack: no `slack` ask and no refusal logged. </details> <details><summary>connector-slack, spec, cli</summary> On `73b116f0fe`, after the merge: spec `platform-object-names.test.ts` 14/14 and cli `organization-ownership-inventory.test.ts` 26/26 (main's two working-calendar objects and this branch's two Slack objects both listed); `check:platform-object-tenancy-census` (self-test and check) green on the regenerated census, 108 objects, 57 in reach. On `99277cfb01`: connector-slack typecheck exit 0, Test Files 3 passed (3), Tests 11 passed (11), the client service sending with the caller's token, not the plugin's static one; spec `typecheck` exit 0, `platform-object-names.test.ts` + `scripts/platform-catalog.test.ts` 34/34; cli `typecheck` exit 0, `vitest run --project unit` Test Files 433 passed (433), Tests 6176 passed (6176). The cli integration layer is left to CI. </details> <details><summary>Derived gates on 73b116f: 137 derived, 135 run green, 2 NOT MEASURED</summary> `node scripts/pm/dispatch-gates.mjs --commands` on `73b116f0fe`, every command run and recorded with its exit code; `--ran` reconciliation: 137 derived, 135 run, 2 NOT-MEASURED, 0 UNRUN. The two NOT MEASURED are `check:dual-build-cjs-loads` and `check:i18n-coverage` (exit 3, PREREQUISITE NOT MET: they read a full workspace build this box does not hold); CI runs both. `check:platform-object-tenancy-census` (self-test and check) green on the census regenerated after the merge: on `11ef4c3d74` CI's merge with `origin/main` had found the committed census stale beside main's two new working-calendar objects. `check:route-envelope` green since the Slack route module's declaration. `check:type-check-debt` re-measured under the lock: 0 raw errors above any recorded number. `check:i18n` and `check:i18n-stale-fill` green. overlap-check: clean against `origin/main`, #35129 and #34223. CI on `73b116f0fe`: 62 success, 9 skipped, no failure. </details> <details><summary>Ablations (one per behaviour, each restored with `git diff HEAD` empty)</summary> 1. The reach step removed in `messaging-service.ts` (`const reached = targets`): 4 red, `recipient-reach` 2 and the approvals end-to-end `proposed` / `none` cases, which received `slack:u_approver:suppressed`. Restored to the HEAD blob. 2. The mounted-channel guard removed in `approval-service.ts` (always ask for `slack`), through `scripts/ablation-replace.mjs` under the lock (anchor 1 to 0, blob `c0a7c038924b` to `7098bc5123b7`): the `without connector-slack` case red, receiving the warning `channel 'slack' is not registered; refused 1 delivery row(s)`. Restored: blob equals HEAD (`c0a7c038924b`) and `git diff HEAD` empty. A first attempt never got the lock (exit 99, not measured) and was restored the same way. 3. The verified-email check in `SlackLinkStore` (any email used): 2 red, the unverified-email case and the unverified half of the confirmation case. 4. The person's pre-confirmation view (the full link answered): 3 red, the cases reading the person's proposal. 5. The administrator's pre-confirmation view (the Slack user always named): 1 red, the no-one-named case. 6. The confirmation re-check (always confirming): 1 red, the refused-confirmation case. 7. The replacement of a proposal made for another email (the old one always answered): 1 red, the replacement case. 8. The confirm write keyed on the id alone (`{ where: { id } }`, by-id): 1 red, the row-changed-before-the-write case. Ablations 3 to 8 ran through `scripts/ablation-replace.mjs` under the lock against `slack-links.integration.test.ts` (12 tests; 13 for ablation 8), each mutation landing (anchor 1 to 0) and each restored with its blob equal to HEAD and `git diff HEAD` empty. This round, on `b6e7b432f7` (its slack-links, routes and plugin sources are byte-identical at `dfa7308cb9`), through `scripts/ablation-replace.mjs` outside the lock (the narrowing above), each mutation landing (anchor 1 to 0) and restored with its blob equal to HEAD and `git diff HEAD` empty: 9. The plugin's `slack` registration made unconditional: `slack-channel-composition.test.ts` 1 failed | 1 passed, the without-a-slack-service case. 10. The uninstall's paging cut to one page: 1 red of 19, the more-than-one-page case. 11. The administrator's removal read by id alone, not by id and install: 1 red, the other-organization case. 12. Hardening of token input and proposal audit: each of its three mutations turned its own pin red. 13. Rider 3's moved-membership trigger short-circuited: 1 red, the moved case. </details> ## Verification Read first, by risk: 1. `packages/services/service-messaging/src/slack-links.ts`: `propose` and `confirm` (the proposal rule), `install` (the token proven, then written as a secret under the organization), `slackFor` (the one reader), `removeLink` (the notice), `bindSlackLinkRemovalTriggers`. 2. `packages/services/service-messaging/src/slack-link-routes.ts`: `door()`, the gate order and the `setup.write` check; `linkView` / `ownLinkView` (nothing named before confirmation). 3. `packages/services/service-messaging/src/messaging-service.ts`: `dropUnreachable` and where step 3c sits in `emit`. Two-minute check: `pnpm --filter @objectstack/plugin-approvals exec vitest run src/approval-requested-slack-dm.integration.test.ts` shows 6 passed, the first case printing nothing and asserting the DM link equals the email's. ## Acceptance notes - Size, measured against the merge base on `938fa8f8c8`: 52 files, +3330 / -30, net 3300 (the order's soft size ~900, hard stop 2700). On `73b116f0fe` it was 2866; this round's four commits added 434: the two composition test files 241, `slack-links.integration.test.ts` 107, source 56 (`slack-links.ts` 40, approvals 7, the plugin 6, the routes 3), and the engine-double ledger 30. It is past the stop and reported to the seat, not trimmed. What drives the total (additions on `938fa8f8c8`): tests 1164; generated files and ledgers 718 (the 11 `*.objects.generated.ts` translation bundles, 638 of it, plus the route ledger, census, inventory and engine-double ledger); provider and link code about 1410, mostly `slack-links.ts` 561, `slack-link-routes.ts` 222, `slack-channel.ts` 172 and the two new objects 124; docs and changeset 36. The seat accepted the size with no split, since the PR is Tier H and a maintainer reads it anyway. - File surface beyond the claim's: `packages/spec` (registry constant and its test), `packages/cli` (one inventory row per object), `scripts/platform-object-tenancy-census.json` (regenerated), `scripts/check-route-envelope.mjs` (one module declared), `docs/adr/0013` (fold rule), `plugin-approvals` `package.json` / `vitest.config.ts` (connector-slack as a devDependency, aliased to source) and the lockfile. - Without ConnectorSlackPlugin composed, the `slack` channel is not mounted and approvals do not ask for it. With it composed and an organization with no install, `isAvailable` records `transport_not_configured` on that event, as for email without a transport. - The `PUT` token and every Slack answer are never logged; refusals name Slack's error code only. Session: https://claude.ai/code/session_016WV4czKnDE6hsyXQzB9wB2 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- signed: repo:objectstack#4 · os-elon-musk · session_016WV4czKnDE6hsyXQzB9wB2 --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 75925e1 commit 8e46424

52 files changed

Lines changed: 3330 additions & 30 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
'@objectstack/service-messaging': minor
3+
'@objectstack/connector-slack': patch
4+
'@objectstack/plugin-approvals': patch
5+
'@objectstack/spec': patch
6+
'@objectstack/cli': patch
7+
---
8+
9+
Clause-②: yes (widening)
10+
Metadata-protocol: added
11+
12+
feat(messaging): Slack DM delivery — a `slack` channel, a per-person link store, approval requests by DM
13+
14+
An organization can now receive notifications in Slack, as direct messages to each person who connected their own Slack user (ADR-0013 addendum of 2026-11-19, step 2 of #34730).
15+
16+
- **The install.** An organization administrator (`setup.write` in their current organization) installs the organization's own Slack app with `PUT /api/v1/messaging/slack/account` `{ token }`. Slack proves the bot token (`auth.test`) before it is saved. The app's bot token needs the scopes `chat:write`, `im:write`, `users:read` and `users:read.email` (the methods called are `auth.test`, `users.lookupByEmail`, `conversations.open` and `chat.postMessage`); `auth.test` does not check scopes, so an app without `users:read.email` installs and every proposal then answers 502. The token is kept in `sys_channel_account.bot_token`, a `secret` field: encrypted at rest by the host's `ICryptoProvider`, masked on every read, never returned by any route, and read only by the server when it calls Slack. `GET` and `DELETE` on the same route read and remove the install.
17+
- **A person's link.** `POST /api/v1/messaging/me/slack-link/proposal` proposes a link by the person's email (Slack `users.lookupByEmail`); it delivers nothing until the person confirms it with `POST /api/v1/messaging/me/slack-link/confirm`. A Slack link is proposed only for a verified email and names no one before it is confirmed. `GET` and `DELETE /api/v1/messaging/me/slack-link` read and remove it. An administrator lists links with `GET /api/v1/messaging/slack/links` and removes one with `DELETE /api/v1/messaging/slack/links/:id`; the person is told by inbox and e-mail (topic `messaging.slack_link_removed`) and may link again. A link goes when the person is deleted, banned, or leaves the organization. Links are `sys_channel_user_link` rows; every write names who acted, so the platform's write audit records each one.
18+
- **The channel, only where connector-slack is composed.** `slack` is registered beside inbox, email, sms and push only on a composition where connector-slack's `slack` client service resolves at boot: `ConnectorSlackPlugin` now registers that service, which sends with a caller-held token. On such a composition, and only there, the `/automation` save doors accept `slack` on a `notify` node, and `GET /api/v1/messaging/preference-options` and `GET /api/v1/messaging/me/preferences` list `slack` as a channel. A `notify` node naming `slack` delivers only where connector-slack is composed, the organization installed Slack and the recipient confirmed a link. Without connector-slack, those doors answer as before: a `notify` node naming `slack` is refused 400, and neither preference door lists it. It sends `conversations.open` then `chat.postMessage` with the notification's title linked to its deep link, made absolute under `OS_AUTH_URL` / `OS_BASE_URL`. Preferences, digest and quiet hours apply as on every channel. A recipient with no confirmed link is skipped before any delivery row is written, so nothing is dead-lettered for them; a refused token stops delivery on that install until an administrator sets it again; a rate limit is retried.
19+
- **Approval requests.** `approval.requested` also asks for `slack`, beside inbox and e-mail, only while the `slack` channel is registered and mounted (connector-slack composed).
20+
- `MessagingChannel` gains an optional `reachableRecipients(ctx, { organizationId, recipients })`, consulted once per channel per emit after preferences. A channel without it reaches every recipient, as before.
21+
- `PLATFORM_OBJECTS_BY_PACKAGE['service-messaging']` lists `sys_channel_account` and `sys_channel_user_link`, and the organization ownership inventory gives both a row.

‎docs/adr/0013-bidirectional-messaging.md‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,5 +815,18 @@ Step 2 also says where the open tier keeps an organization's supplied token at r
815815
`credentials_ref` into `service-secrets` is Draft and the vault stays enterprise; ADR-0143 and
816816
ADR-0100 give the open connector credential path.
817817

818-
**Open — not ruled:** what a person's email that matches more than one Slack user proposes (§8
819-
risk 4 is Draft); and a manual connect for a person whose email matches no Slack user.
818+
**Step 2 chose** (the change that builds it, under #34730): the administrator doors check
819+
`setup.write` held in the caller's current organization (`ExecutionContext.systemPermissions`, the
820+
capability the in-app message door already asks of an organization administrator), not
821+
`isPlatformAdmin`. The token is `sys_channel_account.bot_token`, a `secret` field (ADR-0100), the
822+
channel `sys_connector_credential` uses (ADR-0143): encrypted on write by the host's
823+
`ICryptoProvider` with the organization in its context, held in `sys_secret`, masked on every read,
824+
and dereferenced only server side through `resolveSecretField()`; the object is engine-owned with
825+
its data API closed. A Slack link is proposed only for a verified email and names no one before it
826+
is confirmed.
827+
828+
**Open — not ruled:** what a person's email that matches more than one Slack user proposes (Risks &
829+
open questions, item 4, is Draft, and it describes the converse — two `sys_user`s sharing one email —
830+
so neither multi-match case is ruled; step 2 links one Slack user to at most one person per install,
831+
and proposes nothing to a second person whose email resolves to an already linked Slack user); and a
832+
manual connect for a person whose email matches no Slack user.

‎packages/cli/src/utils/organization-ownership-inventory.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,11 @@ export const ORGANIZATION_OWNERSHIP_INVENTORY: readonly InventoryEntry[] = [
839839
{ object: 'sys_mailbox', census: PMAIN, fate: 'attribution', citation: `${CENSUS_MAIN} (in reach, added since the first census); ${D10_SINGLE}`, anchors: [] },
840840
{ object: 'sys_mail_message', census: PMAIN, fate: 'attribution', citation: `${CENSUS_MAIN} (in reach); the message's mailbox carries the organization`, anchors: [parent('mailbox_id', 'sys_mailbox')] },
841841
{ object: 'sys_mail_association', census: PMAIN, fate: 'attribution', citation: `${CENSUS_MAIN} (in reach); the association's message carries the organization`, anchors: [parent('mail_message_id', 'sys_mail_message')] },
842+
// Slack DM delivery (`@objectstack/service-messaging`, #34730): the link
843+
// store writes an install and each link with its organization stamped, so a
844+
// NULL row has no producer; a link's install is where one would take it.
845+
{ object: 'sys_channel_account', census: PMAIN, fate: 'attribution', citation: `${CENSUS_MAIN} (in reach, added since the first census); ${D10_SINGLE}`, anchors: [] },
846+
{ object: 'sys_channel_user_link', census: PMAIN, fate: 'attribution', citation: `${CENSUS_MAIN} (in reach); the link's install carries the organization`, anchors: [parent('account_id', 'sys_channel_account')] },
842847
// Ownership queues (`@objectstack/plugin-sharing`, ADR-0142): an organization
843848
// authors its queues, their members and its own assignment rules, and the
844849
// assignment engine writes its cursor, each under that organization. A

‎packages/connectors/connector-slack/src/connector-slack-plugin.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { describe, it, expect } from 'vitest';
44
import { LiteKernel } from '@objectstack/core';
55
import { AutomationServicePlugin, type AutomationEngine } from '@objectstack/service-automation';
66
import { ConnectorSlackPlugin } from './connector-slack-plugin.js';
7+
import type { SlackClientService } from './slack-connector.js';
78

89
/** A fetch stub mimicking the Slack Web API (HTTP 200 + ok in the body). */
910
function stubSlack() {
@@ -76,3 +77,25 @@ describe('ConnectorSlackPlugin — end to end with the automation engine', () =>
7677
await kernel.shutdown();
7778
});
7879
});
80+
81+
describe('ConnectorSlackPlugin — the `slack` client service', () => {
82+
it('hands out a client for the caller\'s own token, over the plugin\'s transport options', async () => {
83+
const { impl, calls } = stubSlack();
84+
const kernel = new LiteKernel();
85+
kernel.use(new AutomationServicePlugin());
86+
kernel.use(new ConnectorSlackPlugin({ token: 'xoxb-flow-token', fetchImpl: impl }));
87+
await kernel.bootstrap();
88+
89+
const slack = kernel.getService<SlackClientService>('slack');
90+
const out = await slack.client('xoxb-organization-token').call({ method: 'conversations.open', params: { users: 'U1' } });
91+
92+
expect(out.ok).toBe(true);
93+
expect(calls).toHaveLength(1);
94+
expect(calls[0].url).toBe('https://slack.com/api/conversations.open');
95+
// The caller's token, never the plugin's static one.
96+
expect((calls[0].init.headers as Record<string, string>).Authorization).toBe('Bearer xoxb-organization-token');
97+
expect(calls[0].init.body).toBe('{"users":"U1"}');
98+
99+
await kernel.shutdown();
100+
});
101+
});

‎packages/connectors/connector-slack/src/connector-slack-plugin.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import type { Plugin, PluginContext } from '@objectstack/core';
44
import type { Connector } from '@objectstack/spec/integration';
5-
import { createSlackConnector, type SlackConnectorOptions } from './slack-connector.js';
5+
import { createSlackClientService, createSlackConnector, type SlackConnectorOptions } from './slack-connector.js';
66

77
/**
88
* Minimal surface of the automation engine this plugin depends on — the
@@ -35,6 +35,8 @@ export class ConnectorSlackPlugin implements Plugin {
3535
name = 'com.objectstack.connector.slack';
3636
version = '1.0.0';
3737
type = 'standard' as const;
38+
/** The client factory init() registers (`SlackClientService`), for the Slack DM channel. */
39+
providesServices = ['slack'];
3840
// Ensure the automation engine (and its connector registry) is started first.
3941
dependencies = ['com.objectstack.service-automation'];
4042

@@ -46,9 +48,12 @@ export class ConnectorSlackPlugin implements Plugin {
4648
this.options = options;
4749
}
4850

49-
async init(_ctx: PluginContext): Promise<void> {
50-
// No services to register; the connector is registered in start() once
51-
// the automation engine is available.
51+
async init(ctx: PluginContext): Promise<void> {
52+
// The client, for a token its caller holds: the messaging service's
53+
// Slack DM channel sends with each organization's own bot token. The
54+
// flow connector is registered in start(), once the automation engine
55+
// is available.
56+
ctx.registerService('slack', createSlackClientService(this.options));
5257
}
5358

5459
async start(ctx: PluginContext): Promise<void> {

‎packages/connectors/connector-slack/src/index.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
export {
1818
createSlackConnector,
19+
createSlackClientService,
20+
type SlackClientService,
1921
type SlackConnectorOptions,
2022
type SlackConnectorBundle,
2123
type SlackPostMessageInput,

‎packages/connectors/connector-slack/src/slack-connector.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,36 @@ export function createSlackConnector(opts: SlackConnectorOptions): SlackConnecto
196196
};
197197
}
198198

199+
/**
200+
* The `slack` service `ConnectorSlackPlugin` registers: this package's
201+
* client, built for a bot token the CALLER holds. `@objectstack/service-messaging`'s
202+
* Slack DM channel sends through it with each organization's own token
203+
* (ADR-0022 §3, ADR-0013 addendum point 1). It reaches the client through the
204+
* service registry, not a package import: service-messaging importing this
205+
* package would close a workspace dependency cycle through
206+
* `@objectstack/service-automation`.
207+
*
208+
* The other options (`baseUrl`, `defaultHeaders`, `fetchImpl`) apply to every
209+
* client it builds; a static `token` among them is never used here.
210+
*/
211+
export interface SlackClientService {
212+
/**
213+
* A client for `token`: the connector's `call` action — any Web API
214+
* method, `{ method, params }`, answered `{ ok, status, body, error }`.
215+
*/
216+
client(token: string): { call(input: Record<string, unknown>): Promise<Record<string, unknown>> };
217+
}
218+
219+
export function createSlackClientService(options: Omit<SlackConnectorOptions, 'token'> = {}): SlackClientService {
220+
const { token: _static, ...shared } = options as SlackConnectorOptions;
221+
return {
222+
client: (token) => {
223+
const { handlers } = createSlackConnector({ ...shared, token });
224+
return { call: (input) => handlers.call(input, undefined) };
225+
},
226+
};
227+
}
228+
199229
function toRecord(r: SlackResult): Record<string, unknown> {
200230
return { ok: r.ok, status: r.status, body: r.body, error: r.error };
201231
}

‎packages/plugins/plugin-approvals/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@objectstack/types": "workspace:*"
3636
},
3737
"devDependencies": {
38+
"@objectstack/connector-slack": "workspace:*",
3839
"@objectstack/driver-sql": "workspace:*",
3940
"@objectstack/lint": "workspace:*",
4041
"@objectstack/metadata-protocol": "workspace:*",

0 commit comments

Comments
 (0)