Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7e90259
feat(notion): init notion action
mvriu5 Sep 14, 2026
a32d63a
feat(notion): migrate to @notionhq/client v5 and data sources API
mvriu5 Nov 22, 2026
7e88176
feat(notion): type response timestamps as DATE
mvriu5 Nov 22, 2026
79a8eeb
fix(notion): treat null optional arguments as unset
mvriu5 Nov 24, 2026
2399681
refactor(notion): drop the notion_version config
mvriu5 Nov 24, 2026
6871710
feat(notion): add notionCreateBlock builder
mvriu5 Nov 24, 2026
b7271db
Update README.md
mvriu5 Nov 24, 2026
d2e5d5c
feat(notion): add notionSetProperty and improve builder parameters
mvriu5 Nov 24, 2026
ac02bb9
refactor(notion): format block text in notionCreateBlock, drop
mvriu5 Nov 24, 2026
797b1ac
fix(notion): catch pages created in the activation minute and speed up
mvriu5 Nov 24, 2026
75a22ef
feat(notion): configure the poll interval per project
mvriu5 Nov 24, 2026
e7074ec
feat(notion): take the integration token per flow instead of a project
mvriu5 Nov 26, 2026
609e22c
feat(notion): create page content from Markdown and split
mvriu5 Nov 27, 2026
d721523
docs(notion): drop block writing from the action descriptions
mvriu5 Nov 27, 2026
558cd10
feat(notion): take properties as a plain object and the token as text
mvriu5 Nov 27, 2026
8f94abf
Update README.md
mvriu5 Nov 27, 2026
64b99f2
feat(notion): return the page content as Markdown from notionGetPage
mvriu5 Nov 27, 2026
b2838ac
query notion database - zweiten sort rausnehmen und stattdessen standard
mvriu5 Nov 28, 2026
5777052
feat(notion): readable parameter labels and clearer ID descriptions
mvriu5 Nov 28, 2026
69d2393
feat(notion): sort database queries by a column and direction field
mvriu5 Nov 28, 2026
0d55d85
feat(notion): create and update pages by title and Markdown content
mvriu5 Nov 28, 2026
e70868e
feat(notion): create pages under a database or a parent page
mvriu5 Nov 28, 2026
67bb994
feat(notion): remove database queries and the search filter
mvriu5 Nov 28, 2026
1c45bc8
Update README.md
mvriu5 Nov 28, 2026
5ec219b
Merge branch 'main' into feat/notion
mvriu5 Nov 29, 2026
a859911
fix(notion): change content (markdown description to content
mvriu5 Nov 30, 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
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ include:
- github-action
- ai-action
- discord-action
- notion-action

.rust-actions:
- cron-action
Expand Down
6 changes: 6 additions & 0 deletions actions/notion-action/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
dist
.env
.env.*
src/tests
coverage
7 changes: 7 additions & 0 deletions actions/notion-action/.example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
HERCULES_AUTH_TOKEN=
HERCULES_AQUILA_URL=localhost:50051
HERCULES_ACTION_ID=notion-action
HERCULES_SDK_VERSION=1.0.0
# Optional: default poll interval for the triggers in milliseconds (default 60000, minimum 10000).
# Each trigger can override it with its pollIntervalSeconds setting.
NOTION_POLL_INTERVAL_MS=
16 changes: 16 additions & 0 deletions actions/notion-action/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:24.10.0-alpine AS build
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY tsconfig.json vite.config.ts ./
COPY src ./src
RUN npm run build

FROM node:24.10.0-alpine
WORKDIR /app
ENV NODE_ENV=production
COPY package.json package-lock.json ./
RUN npm ci --omit=dev
COPY --from=build /app/dist ./dist
USER node
CMD ["node", "dist/index.js"]
85 changes: 85 additions & 0 deletions actions/notion-action/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Notion action

Read and write Notion pages, use databases as a backing store, and start Hercules flows when database entries change.

## Setup

Use Node.js 24 (matching the other action containers).

```sh
npm ci
cp .example.env .env
# Fill in the Hercules connection settings.
npm run dev
```

On PowerShell, use `Copy-Item .example.env .env`. The dev/start scripts load `.env` if present. For a compiled process, run `npm run build` followed by `npm start`.

Create a Notion internal integration with read, insert and update content capabilities. Share each target database/page with that integration via **Add connections**. An integration token alone does not grant access to all workspace content.

The action has no project configuration. Every function and every trigger takes the integration token it works with as its first parameter, a plain text value, so one running action serves as many Notion integrations as its flows use. Tokens are never cached globally and never put in exported module defaults; an empty token is rejected.

Each trigger additionally has an optional **Poll interval (seconds)** setting (`pollIntervalSeconds`, minimum 10 seconds). Without it the trigger uses `NOTION_POLL_INTERVAL_MS` of the action process (default 60 seconds).

Shared environment variables: `HERCULES_AUTH_TOKEN`, `HERCULES_AQUILA_URL` (default `localhost:50051`), `HERCULES_ACTION_ID` (default `notion-action`), `HERCULES_SDK_VERSION` (default `1.0.0`, used as the module version like the other actions).

## Functions

| Identifier | Parameters | Result |
| --- | --- | --- |
| `notionCreatePage` | `integrationToken, parentId, title, markdown?` | `NOTION_PAGE` |
| `notionUpdatePage` | `integrationToken, pageId, title?, markdown?` | `NOTION_PAGE` |
| `notionGetPage` | `integrationToken, pageId` | `NOTION_PAGE` |
| `notionArchivePage` | `integrationToken, pageId` | `boolean` (Hercules BOOLEAN) |
| `notionSearch` | `integrationToken, query` | `NOTION_SEARCH_RESULT` |

Create adds a page with a title and optional content under `parentId`: a database ID makes it a new entry, a page ID a subpage. The action first looks the ID up as a database; if Notion answers 400 or 404 (e.g. because it is a page), it creates the page under a parent page instead. Update changes the title and/or replaces the whole content; an empty title or content stays unchanged. The title is written by the property ID `title`, so the name of a database's title column (usually Name) does not matter; other columns are not written. Get retrieves the page with its properties and its content as Notion-flavored Markdown in `markdown` (two parallel requests: the page and `GET /pages/{id}/markdown` with `markdown_version: "v2"`). `markdown` is an optional field of `NOTION_PAGE` that Get and an update with content fill in; other functions and the triggers return pages without content. Archive moves the page to the trash (`in_trash`) and returns the state confirmed by Notion.

Search collects **all pages** of results into one response (`has_more: false`, `next_cursor: null`); large workspaces consume corresponding time and memory. It matches page and database titles, not full page text; an empty search text lists everything the integration can access.

Create and update take page content as Markdown (`markdown`), sent as [Notion-flavored Markdown](https://developers.notion.com/guides/data-apis/migrate-to-notion-flavored-markdown) (`markdown_version: "v2"`); Notion converts it into blocks such as headings, lists, to-dos (`- [ ]`), quotes, code blocks and links. Update replaces the content (`PATCH /pages/{id}/markdown`, `replace_content`) without allowing Notion to delete child pages or databases. Without content, create makes an empty page. API calls time out after 30 seconds. HTTP 429 is retried at most twice using `Retry-After` (up to 60 seconds); ambiguous network failures on writes are not automatically retried.

## Polling events

| Event | Settings | Flow input |
| --- | --- | --- |
| `NotionDatabaseItemCreated` | `integrationToken, databaseId, pollIntervalSeconds?` | The new `NOTION_PAGE` |
| `NotionDatabaseItemUpdated` | `integrationToken, databaseId, pollIntervalSeconds?` | The edited `NOTION_PAGE` |
| `NotionPagePropertyChanged` | `integrationToken, databaseId, propertyName, pollIntervalSeconds?` | The changed `NOTION_PAGE` |

Hercules registers each class as a RuntimeEvent **and** its matching Event definition. The poller reads the token, database and interval from Aquila's flow settings. It calls `action.fire(flowId, page)` only for the matching flow; it does not broadcast to every flow of that event type.

- Polling runs immediately after connection. Each flow is then polled every `pollIntervalSeconds` of its own settings (minimum 10 seconds), falling back to `NOTION_POLL_INTERVAL_MS` of the action process (default 60 seconds); a base timer checks every 10 seconds which flows are due. Poll cycles do not overlap. After a flow establishes its baseline, one extra poll follows after 10 seconds so a first change shows up quickly. Changing the interval keeps the baseline. Each poll is one Notion API request per watched flow, so keep intervals and the number of flows per integration within Notion's rate limit (about three requests per second). API calls and flow acknowledgements can make a cycle take longer.
- Notion rounds `created_time` down to the minute; item-created watches therefore count pages from the start of the activation minute.
- The first successful, fully paginated query establishes a baseline and emits no historical pages. Created detects newly observed pages whose creation time is at or after watch activation; moving an old page into a database is not a creation event.
- Updated detects increasing `last_edited_time`. A newly observed page that has already been edited can also trigger it. A new, unedited page is handled by Created.
- PropertyChanged compares the exact, case-sensitive property's API value against the previous snapshot. Other property edits do not trigger it. The first observation of a page establishes its property baseline. Removing/clearing a previously present value also triggers it. The payload is the current page, not a before/after diff.
- Subsequent queries use an inclusive `last_edited_time` cursor with a 60-second overlap. Per-page snapshots suppress repeats, including timestamp ties. This covers short indexing delays, not arbitrarily delayed updates.
- Pagination failures do not commit a new cursor. Delivery failures retry without refiring already acknowledged pages in that batch. A missing acknowledgement times out after 60 seconds. Delivery is **at least once**: a flow may have run even if its acknowledgement was lost, so downstream side effects should be idempotent.
- Checkpoints and property snapshots are **in memory**. Restart/reconnect, changed credentials, or changed watch settings establish a new baseline. Changes during downtime are not replayed. Use one action process for a given set of flows; this action has no distributed lock or shared durable checkpoint.
- Polling observes states, not every intermediate edit. A value changed and reverted between polls is not detectable. Archived/deleted pages disappear from database queries and do not emit a deletion event. Large/truncated relation or rollup properties are limited to what Notion returns in page properties.

No inbound HTTP server, public webhook URL or cron-action dependency is required.

## Data types and compatibility

Each data type has its own file under `src/data_types/`. Zod schemas describe common fields and preserve additional Notion fields. They are deliberately extensible, not exhaustive validators for every Notion block or property subtype. No `z.custom()` schemas are used. Zod is pinned to `4.4.3`, the version Hercules' embedded schema exporter is built against.

Points in time in responses (`created_time`, `last_edited_time`, file `expiry_time`, calendar `start_time`/`end_time`) are `DATE` values, i.e. Unix microseconds (UTC); the client converts Notion's ISO 8601 strings before validating a response. The triggers' query filters send timestamps to Notion as ISO 8601 text.

The API is pinned to [`2025-09-03`](https://developers.notion.com/guides/get-started/upgrade-guide-2025-09-03), where a database is a container of one or more data sources and pages live in a data source. Functions and triggers keep taking a `databaseId`: the action resolves the database's data source (`GET /databases/{id}`) and then queries or creates pages in it. Databases with several data sources are ambiguous and fail with `NOTION_MULTIPLE_DATA_SOURCES`; the triggers resolve the data source once per watch.

Notion now also supports [native webhooks](https://developers.notion.com/reference/webhooks). This action intentionally implements the requested polling triggers.

## Verification and container

```sh
npm run typecheck
npm test
npm run build
npx hercules export dist/index.js --compact
docker build -t notion-action .
docker run --env-file .env notion-action
```

Tests live under `src/tests/`. They use mocked HTTP calls and flow dispatch, covering request mapping, pagination, retries, builders, polling state and actual Hercules module registration. No live Notion or Aquila credentials are required. A live end-to-end test requires a shared Notion database and a configured Aquila instance.
10 changes: 10 additions & 0 deletions actions/notion-action/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "notion",
"identifier": "notion-action",
"description": "Notion integration: read and write pages, query databases, search, and poll for changes.",
"deployment": {
"docker": {
"image": "ghcr.io/code0-tech/centaurus/ci-builds/notion-action"
}
}
}
Loading