feat(automations): Notion trigger provider
Summary
Adds the Notion trigger provider (kind: "notion") — the tier-3 "connection + fetch-on-notify" shape.
Events (exactly three, as briefed)
| event | sentence | filters |
|---|---|---|
data_source.content_updated | Rows changed in [data sources] | dataSources (ScopeChip, required) |
comment.created | Comment added in [data sources] on [Any page] by [Anyone] | dataSources · pages (optional, any by default) · actor |
comment.mentioned | Comment mentions [Me] in [data sources] on [Any page] | dataSources · pages · mentionedUser (ActorChip anyone/me/people, defaults to me) |
comment.mentioned is ours on top of comment.created: the route fetches the comment and reads rich_text for mention items of type: "user"; the matcher tests those ids against mentionedUser (me resolves through user_identities provider notion). Comments only — no page-body diffing.
Pieces
packages/shared:notionTriggerConfigSchema(union on event) +describeTriggerProblemsrules;automation-matching/notion.ts+ onecase "notion"intriggerMatches(context.notioncarriesdataSourceId / pageId / mentionedUserIds / ownerIds).- Desktop:
providers/notion/{grammar,notion,useNotionOptions}+ registry line + hook inuseProviderOptions. Two OptionKeys added (dataSources,notionUsers) — Notion user ids are their own id space so the actor chips can't reuse GitHub'speople. (The coordinator is landing a consolidated provider-namespaced options shape; I'll rebase onto it when it lands.) - tRPC:
integration.notion.{getConnection, disconnect, listDataSources, listUsers}; a plain-fetch Notion client (@superset/trpc/integrations/notion, no SDK, no new package, API version2025-09-03). - API:
integrations/notion/{connect,callback,webhook}. Callback upsertsintegration_connections(externalOrgId= workspace id) and auser_identitiesrow for the authorizing member. Webhook: answers the one-timeverification_tokenhandshake (logs the token) → verifiesX-Notion-Signature(HMAC-SHA256 of the raw body, timing-safe) → fetches the entity (comment → page → parent data source; or the data source) →automation_eventskeyed on the Notion event id per connection → dispatch. Permanent Notion API errors (400/401/403/404) acknowledge the delivery as skipped; other errors 500 so Notion retries. - Web:
/integrations/notionpage + card (copy of Slack's).
Deviation from the brief (approved by the coordinator): the verification token is a per-integration secret — the subscription lives in the integration's settings, the handshake carries no workspace id, and one token signs deliveries for every workspace — so it is NOTION_WEBHOOK_VERIFICATION_TOKEN (same shape as LINEAR_WEBHOOK_SECRET), not a column on the connection. The three Notion env vars are optional; the routes answer 503 until they're set, so nothing needs to change in the deploy workflows in this PR.
No migration: automation_triggers.kind / integration_provider already carry notion (#6581).
Verification
Live Notion OAuth was not available (no public integration registered yet), so:
- Editor over CDP (this worktree's renderer, signed in as the org owner): added all three triggers, configured data sources (Product Roadmap) and
me, saved, reloaded → rows persisted withkind = notionand rendered with resolved labels. Empty data source scope blocks Save with the shared banner. - Webhook: with a local
NOTION_WEBHOOK_VERIFICATION_TOKENand a seeded connection using an internal-integration token for the same workspace, replayed self-signed payloads for a real comment (mentioning a workspace user) and a real data source:- handshake
{verification_token}→ 200; unsigned / bad signature → 401; unknown workspace →no_subscribers. comment.created→automation_eventsrow with the fetched comment (rich_text incl. the mention's user id), page title/url,resource_key = notion:<pageId>; dispatch selected 2/3 triggers (comment.mentioned viame, comment.created via the page's parent data source), not the rows-changed one.data_source.content_updated→ row for the data source; dispatch selected 1/3.- Redelivery of the same event id → deduped (row count stays 1). Bad entity id → 400 from Notion → delivery acknowledged as skipped.
- QStash publish itself cannot be proven locally (
invalid destination url: endpoint resolves to a loopback address) — the selection log line is the evidence, same as the other providers.
- handshake
bun run typecheck→ exit 0.bun run lint→ exit 1 only onTerminalAgentAutoResume.tsx:141(pre-existing on main, being fixed there); nothing in this diff.
To go live
Register the Notion public integration (capabilities: read content, read comments, read user info; redirect URI <API_URL>/api/integrations/notion/callback), set NOTION_CLIENT_ID / NOTION_CLIENT_SECRET, create the webhook subscription pointing at <API_URL>/api/integrations/notion/webhook with comment.created + data_source.content_updated, copy the token from the API log into NOTION_WEBHOOK_VERIFICATION_TOKEN, then add the three vars to the deploy workflows.
Summary by cubic
Adds a Notion trigger provider (kind: "notion") so automations can run on Notion data‑source updates and comments. Previously Notion events were unsupported; now we handle rows changed, comment created, and comments that mention a user, with OAuth connection and a verified webhook.
- Events and filters:
data_source.content_updated,comment.created(filters: data sources · optional pages · actor), andcomment.mentioned(derived fromcomment.createdby scanning rich text; filters: data sources · optional pages · mentioned user). Resolvesmeviauser_identitiesfor providernotion. - Webhook ingestion:
/api/integrations/notion/webhookverifiesX-Notion-Signature(HMAC‑SHA256 withNOTION_WEBHOOK_VERIFICATION_TOKEN), handles the one‑time verification handshake (logs full token only while unset; otherwise a fingerprint), applies 15s timeouts and URI‑encodes ids, fetches the referenced entity (comment → page → parent data source, or the data source), dedupes per Notion event id per connection, acknowledges permanent Notion API errors (400/401/403/404) as skipped, and records/dispatches automation events. - Matching and schema in
@superset/shared: addsnotionTriggerConfigSchema,automation-matching/notion.ts, and acase "notion"intriggerMatches. - OAuth connection:
/api/integrations/notion/{connect,callback}completes public‑integration OAuth (sends Notion‑Version, survives fetch failures), upsertsintegration_connections(externalOrgId= workspace id) and auser_identitiesrow for the authorizing member;getConnectionignores disconnected rows. - tRPC in
@superset/trpc:integration.notion.{getConnection, disconnect, listDataSources, listUsers}; lists are bounded (up to 5×100) and return empty on permanent capability errors. - UI: Desktop trigger editor adds Notion with sentence grammar and chips; triggers must select at least one data source to save. Web adds
/integrations/notionwith connect/disconnect and error handling. - Env vars (optional until provisioned):
NOTION_CLIENT_ID,NOTION_CLIENT_SECRET,NOTION_WEBHOOK_VERIFICATION_TOKEN. Notion routes return 503 until set. No DB migration.
Rollout
- Register the Notion public integration with capabilities read content, read comments, read user info; set redirect URI to
<API_URL>/api/integrations/notion/callback. - Create the webhook subscription to
<API_URL>/api/integrations/notion/webhookforcomment.createdanddata_source.content_updated. Paste the logged handshake token intoNOTION_WEBHOOK_VERIFICATION_TOKEN. - Set
NOTION_CLIENT_ID,NOTION_CLIENT_SECRET, andNOTION_WEBHOOK_VERIFICATION_TOKENin deployment.
Summary by CodeRabbit
- New Features
- Added Notion integration with secure connection and disconnection controls.
- View connected workspace details and select Notion data sources and users.
- Create automations triggered by data-source updates, comments, and mentions.
- Added optional filters for pages, actors, and mentioned users.
- Notion webhook events are processed to trigger automations automatically.
- Improvements
- Added clear connection and authorization error messages.
- Added support for retrieving Notion pages, comments, data sources, and workspace users.