Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3995752
feat(messaging): WIP slack channel, link store and link doors
claude Nov 20, 2026
77bd614
feat(messaging): WIP wire the slack channel, link doors and approvals…
claude Nov 20, 2026
194dd3b
test(messaging): the Slack link store, doors, riders, channel and rea…
claude Nov 20, 2026
e343bb6
test(approvals): an approval request reaches a linked approver by Sla…
claude Nov 20, 2026
06988fc
feat(messaging): register the Slack link objects, record step 2 in AD…
claude Nov 20, 2026
720853d
feat(messaging): translate the Slack link objects in every shipped lo…
claude Nov 20, 2026
9cad436
fix(approvals): ask for slack only while the composition mounts the c…
claude Nov 20, 2026
07ce646
docs(messaging): say exactly who writes the Slack install and who can…
claude Nov 20, 2026
0be9685
chore(messaging): declare the Slack link doors to the route-envelope …
claude Nov 20, 2026
99277cf
Merge origin/main into claude/area-a4W-34730-s2
claude Nov 20, 2026
763133e
feat(messaging): propose a Slack link only for a verified email, nami…
claude Nov 20, 2026
31d6b76
docs(messaging): record the Slack link proposal rule in ADR-0013 and …
claude Nov 20, 2026
11ef4c3
feat(messaging): a Slack link confirmation applies only to the propos…
claude Nov 20, 2026
dc0fc35
Merge origin/main into claude/area-a4W-34730-s2
claude Nov 20, 2026
73b116f
chore(census): regenerate the platform-object tenancy census on the m…
claude Nov 20, 2026
cba4fbf
feat(messaging): the slack channel is known only where connector-slac…
claude Nov 20, 2026
b6e7b43
fix(messaging): link removals read and delete by predicate; hardening…
claude Nov 20, 2026
ff91c86
Merge origin/main into claude/area-a4W-34730-s2
claude Nov 20, 2026
dfa7308
test(messaging, runtime): the composition tests' engine doubles route…
claude Nov 20, 2026
938fa8f
test(messaging): a ban removes a person's links in every organization…
claude Nov 20, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .changeset/34730-slack-dm-delivery.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
'@objectstack/service-messaging': minor
'@objectstack/connector-slack': patch
'@objectstack/plugin-approvals': patch
'@objectstack/spec': patch
'@objectstack/cli': patch
---

Clause-②: yes (widening)
Metadata-protocol: added

feat(messaging): Slack DM delivery — a `slack` channel, a per-person link store, approval requests by DM

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).

- **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.
- **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.
- **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.
- **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).
- `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.
- `PLATFORM_OBJECTS_BY_PACKAGE['service-messaging']` lists `sys_channel_account` and `sys_channel_user_link`, and the organization ownership inventory gives both a row.
17 changes: 15 additions & 2 deletions docs/adr/0013-bidirectional-messaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -815,5 +815,18 @@ Step 2 also says where the open tier keeps an organization's supplied token at r
`credentials_ref` into `service-secrets` is Draft and the vault stays enterprise; ADR-0143 and
ADR-0100 give the open connector credential path.

**Open — not ruled:** what a person's email that matches more than one Slack user proposes (§8
risk 4 is Draft); and a manual connect for a person whose email matches no Slack user.
**Step 2 chose** (the change that builds it, under #34730): the administrator doors check
`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`. The token is `sys_channel_account.bot_token`, a `secret` field (ADR-0100), the
channel `sys_connector_credential` uses (ADR-0143): encrypted on write by the host's
`ICryptoProvider` with the organization in its context, held in `sys_secret`, masked on every read,
and dereferenced only server side through `resolveSecretField()`; the object is engine-owned with
its data API closed. A Slack link is proposed only for a verified email and names no one before it
is confirmed.

**Open — not ruled:** what a person's email that matches more than one Slack user proposes (Risks &
open questions, item 4, is Draft, and it describes the converse — two `sys_user`s sharing one email —
so neither multi-match case is ruled; step 2 links one Slack user to at most one person per install,
and proposes nothing to a second person whose email resolves to an already linked Slack user); and a
manual connect for a person whose email matches no Slack user.
5 changes: 5 additions & 0 deletions packages/cli/src/utils/organization-ownership-inventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,11 @@ export const ORGANIZATION_OWNERSHIP_INVENTORY: readonly InventoryEntry[] = [
{ object: 'sys_mailbox', census: PMAIN, fate: 'attribution', citation: `${CENSUS_MAIN} (in reach, added since the first census); ${D10_SINGLE}`, anchors: [] },
{ 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')] },
{ 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')] },
// Slack DM delivery (`@objectstack/service-messaging`, #34730): the link
// store writes an install and each link with its organization stamped, so a
// NULL row has no producer; a link's install is where one would take it.
{ object: 'sys_channel_account', census: PMAIN, fate: 'attribution', citation: `${CENSUS_MAIN} (in reach, added since the first census); ${D10_SINGLE}`, anchors: [] },
{ 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')] },
// Ownership queues (`@objectstack/plugin-sharing`, ADR-0142): an organization
// authors its queues, their members and its own assignment rules, and the
// assignment engine writes its cursor, each under that organization. A
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { describe, it, expect } from 'vitest';
import { LiteKernel } from '@objectstack/core';
import { AutomationServicePlugin, type AutomationEngine } from '@objectstack/service-automation';
import { ConnectorSlackPlugin } from './connector-slack-plugin.js';
import type { SlackClientService } from './slack-connector.js';

/** A fetch stub mimicking the Slack Web API (HTTP 200 + ok in the body). */
function stubSlack() {
Expand Down Expand Up @@ -76,3 +77,25 @@ describe('ConnectorSlackPlugin — end to end with the automation engine', () =>
await kernel.shutdown();
});
});

describe('ConnectorSlackPlugin — the `slack` client service', () => {
it('hands out a client for the caller\'s own token, over the plugin\'s transport options', async () => {
const { impl, calls } = stubSlack();
const kernel = new LiteKernel();
kernel.use(new AutomationServicePlugin());
kernel.use(new ConnectorSlackPlugin({ token: 'xoxb-flow-token', fetchImpl: impl }));
await kernel.bootstrap();

const slack = kernel.getService<SlackClientService>('slack');
const out = await slack.client('xoxb-organization-token').call({ method: 'conversations.open', params: { users: 'U1' } });

expect(out.ok).toBe(true);
expect(calls).toHaveLength(1);
expect(calls[0].url).toBe('https://slack.com/api/conversations.open');
// The caller's token, never the plugin's static one.
expect((calls[0].init.headers as Record<string, string>).Authorization).toBe('Bearer xoxb-organization-token');
expect(calls[0].init.body).toBe('{"users":"U1"}');

await kernel.shutdown();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

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

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

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

async start(ctx: PluginContext): Promise<void> {
Expand Down
2 changes: 2 additions & 0 deletions packages/connectors/connector-slack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

export {
createSlackConnector,
createSlackClientService,
type SlackClientService,
type SlackConnectorOptions,
type SlackConnectorBundle,
type SlackPostMessageInput,
Expand Down
30 changes: 30 additions & 0 deletions packages/connectors/connector-slack/src/slack-connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,36 @@ export function createSlackConnector(opts: SlackConnectorOptions): SlackConnecto
};
}

/**
* The `slack` service `ConnectorSlackPlugin` registers: this package's
* client, built for a bot token the CALLER holds. `@objectstack/service-messaging`'s
* Slack DM channel sends through it with each organization's own token
* (ADR-0022 §3, ADR-0013 addendum point 1). It reaches the client through the
* service registry, not a package import: service-messaging importing this
* package would close a workspace dependency cycle through
* `@objectstack/service-automation`.
*
* The other options (`baseUrl`, `defaultHeaders`, `fetchImpl`) apply to every
* client it builds; a static `token` among them is never used here.
*/
export interface SlackClientService {
/**
* A client for `token`: the connector's `call` action — any Web API
* method, `{ method, params }`, answered `{ ok, status, body, error }`.
*/
client(token: string): { call(input: Record<string, unknown>): Promise<Record<string, unknown>> };
}

export function createSlackClientService(options: Omit<SlackConnectorOptions, 'token'> = {}): SlackClientService {
const { token: _static, ...shared } = options as SlackConnectorOptions;
return {
client: (token) => {
const { handlers } = createSlackConnector({ ...shared, token });
return { call: (input) => handlers.call(input, undefined) };
},
};
}

function toRecord(r: SlackResult): Record<string, unknown> {
return { ok: r.ok, status: r.status, body: r.body, error: r.error };
}
Expand Down
1 change: 1 addition & 0 deletions packages/plugins/plugin-approvals/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@objectstack/types": "workspace:*"
},
"devDependencies": {
"@objectstack/connector-slack": "workspace:*",
"@objectstack/driver-sql": "workspace:*",
"@objectstack/lint": "workspace:*",
"@objectstack/metadata-protocol": "workspace:*",
Expand Down
Loading
Loading