Skip to content

feat(notion): add Notion comments adapter#689

Open
bensabic wants to merge 5 commits into
mainfrom
feat/notion
Open

feat(notion): add Notion comments adapter#689
bensabic wants to merge 5 commits into
mainfrom
feat/notion

Conversation

@bensabic

@bensabic bensabic commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Adds @chat-adapter/notion, an official adapter that lets a Chat SDK bot take part in Notion comment discussions (page-level and block/discussion threads) with the same handler code used for Slack, Linear, GitHub, etc. Inbound events arrive via Notion webhooks (comment.created) with HMAC signature verification; outbound actions use the Comments REST API. Because Notion lets a connection edit its own comments, the adapter supports Post+Edit streaming.

Highlights

  • Webhookscomment.created verified with X-Notion-Signature HMAC over the raw body (timing-safe), plus the one-time verification_token handshake. Returns a fast 200 with idempotent, state-backed dedupe.
  • Post+Edit streaming — posts the first chunk, then PATCHes the comment as tokens arrive, throttled to Notion's ~3 req/s limit (global token bucket, Retry-After aware). Long bodies are split into sequential comments to stay under the 2000-char rich-text cap.
  • Mentions — three modes: mention (default; plain-text @userName / @botUserId), all-comments, and keyword.
  • message.subject — resolves the parent page via the Pages API (title, url, archived status, author).
  • File uploads — up to 3 native attachments via the File Uploads API (binary single_part; public URLs via external_url with bounded polling); overflow and failures fall back to markdown links.
  • HistoryfetchMessages over list-comments (open comments only), direction-aware.
  • Cards render as markdown fallback; reactions / typing / DMs are typed no-ops or errors. Registered in the chat/adapters catalog and the create-chat-sdk scaffold; pinned to Notion-Version: 2026-03-11.

Usage

// lib/bot.ts
import { Chat } from "chat";
import { createNotionAdapter } from "@chat-adapter/notion";
import { createRedisState } from "@chat-adapter/state-redis";

export const bot = new Chat({
  userName: "notion-bot",
  adapters: { notion: createNotionAdapter() }, // reads NOTION_TOKEN + NOTION_VERIFICATION_TOKEN
  state: createRedisState(),
});

bot.onNewMention(async (thread, message) => {
  const subject = await message.subject; // parent page metadata (title, url, …)
  await thread.post(`Thanks for the mention on **${subject?.title ?? "this page"}**!`);
});
// app/api/webhooks/notion/route.ts
import { bot } from "@/lib/bot";

export const POST = (request: Request): Promise<Response> => bot.webhooks.notion(request);

Configuration

Auto-detects NOTION_TOKEN and NOTION_VERIFICATION_TOKEN, plus optional NOTION_BOT_USERNAME, NOTION_MENTION_MODE, NOTION_KEYWORDS, and NOTION_VERSION; everything is overridable via createNotionAdapter({ … }). The docs page covers the full connection + webhook setup (capabilities, content access, and the webhook-URL-lock warning).

Changeset bumps @chat-adapter/notion, chat, and create-chat-sdk (minor). Layered as four commits: feat (adapter + catalog/scaffold/emoji), docs, test, chore(example).

bensabic added 4 commits July 9, 2026 21:57
Adds @chat-adapter/notion for Notion page and block comment discussions: webhook HMAC verification, Post+Edit streaming with markdown chunking, conversation history, message.subject page metadata, plain-text @userName/@botUserId mention detection, and File Uploads (up to 3 native attachments). Registers the adapter in the chat/adapters catalog and create-chat-sdk scaffold, and adds Notion emoji platform support.

Signed-off-by: Ben Sabic <bensabic@users.noreply.github.com>
Signed-off-by: Ben Sabic <bensabic@users.noreply.github.com>
Signed-off-by: Ben Sabic <bensabic@users.noreply.github.com>
Signed-off-by: Ben Sabic <bensabic@users.noreply.github.com>
@bensabic bensabic requested a review from a team as a code owner July 9, 2026 12:03
@vercel

vercel Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
chat Ready Ready Preview, Comment, Open in v0 Jul 9, 2026 12:14pm
chat-sdk-nextjs-chat Ready Ready Preview, Comment, Open in v0 Jul 9, 2026 12:14pm

Comment thread packages/adapter-notion/src/markdown.ts Dismissed
The table-separator pattern had `|` in the character class immediately followed by a `\|` literal; on a line with many spaces the engine backtracked over the class trying to place the trailing pipe. Drop the trailing literal (the `^...$` anchored single-quantifier class is enough to match separator rows), keeping behavior while removing the super-linear path.

Signed-off-by: Ben Sabic <bensabic@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants