Notion IM Helper
通过消息自动同步内容到 Notion。支持日记、笔记、待办、想法、问题、链接、摘抄 7 种类型。
Environment Variables
- -
NOTION_API_KEY - Notion Integration Token - INLINECODE1 - Target Notion Page ID (32 chars)
- INLINECODE2 (optional) - Separate page for quotes
Setup
- 1. INLINECODE3
- Set env vars:
NOTION_API_KEY and INLINECODE5 - Authorize integration on Notion page (··· > Connect to)
Usage
When the user sends a message matching a trigger pattern, execute the corresponding script:
CODEBLOCK0
Trigger Rules
Content types (prefix → type):
- -
日记: / 今天: / riji: / d → diary - INLINECODE10 /
学习: / note: / n → note - INLINECODE14 /
todo: / t → todo - INLINECODE17 /
完成: / √ → done - INLINECODE20 /
灵感: / idea: / flash: / 闪念: / i → idea - INLINECODE26 /
疑问: / q: → question - INLINECODE29 /
quote: / qu: / z → quote - INLINECODE33 /
link: / url: / l → link - INLINECODE37 /
photo: / img: / p → image
Formats:
- -
* text → H1 heading - INLINECODE42 → H2 heading
- INLINECODE43 → H3 heading
- INLINECODE44 → quote block
- INLINECODE45 → divider
- INLINECODE46 → bulleted list
- INLINECODE47 /
2. text etc → numbered list - INLINECODE49 + subsequent
- / -- / --- lines → toggle block
Commands:
- -
月报 / monthly → extract current month records for summary - INLINECODE55 /
随机摘抄 → random historical entry - INLINECODE57 /
search: xxx → search records by keyword - INLINECODE59 /
undo → delete last batch of blocks (within 5 min window) - INLINECODE61 /
check config → verify config
Smart detection (no prefix, AI infers):
- - Pure URL → link
- Starts with YYYY-MM-DD → diary
- Contains
[ ] or 【 】 → todo - Default → idea
Metadata
Scan the LAST line for metadata:
- -
#关键词 → tag - INLINECODE66 → project
- Remove metadata from content before passing to script
Batch & Undo
- - Multi-line messages: each format line (heading/quote/divider/list) becomes a separate block, sent in a single API call
- Undo within 5 minutes: deletes all blocks from the last batch
- Undo after 5 minutes: deletes only the last single block
- Day separator: a divider is auto-inserted when the last record is from a different day
Output Protocol
Scripts emit standardized output prefixes:
- -
OK|message → success, relay success message to user - INLINECODE68 → guide user to set up Notion integration
- INLINECODE69 → invalid API key or page not authorized
- INLINECODE70 → tell user to wait
- INLINECODE71 → tell user to retry later
Always run check_config.py first on first use. Never modify or delete existing Notion blocks.
Image Upload
- - Supports local file paths (e.g.,
C:\Users\photos\img.jpg) and HTTP URLs (e.g., https://example.com/photo.png) - Local files are uploaded to Notion servers via the File Upload API, then attached as image blocks
- URL images are referenced directly as external image blocks
- Optional
--caption flag to add caption text to the image - Max file size: 5MB (Notion API limit)
- Supported formats: jpg, jpeg, png, gif, webp, bmp, svg
Notion IM Helper
通过消息自动同步内容到 Notion。支持日记、笔记、待办、想法、问题、链接、摘抄 7 种类型。
环境变量
- - NOTIONAPIKEY - Notion 集成令牌
- NOTIONPARENTPAGEID - 目标 Notion 页面 ID(32 个字符)
- NOTIONQUOTESPAGEID(可选)- 摘抄专用页面
设置
- 1. pip install notion-client
- 设置环境变量:NOTIONAPIKEY 和 NOTIONPARENTPAGE_ID
- 在 Notion 页面上授权集成(··· > 连接到)
使用方法
当用户发送匹配触发模式的消息时,执行相应的脚本:
bash
python scripts/record.py record --type {类型} {内容}
python scripts/record.py heading --level {1|2|3} {文本}
python scripts/record.py divider
python scripts/record.py list --kind {bullet|number} {项目}
python scripts/record.py toggle {json}
python scripts/record.py image [--caption 文本] {文件路径或URL}
python scripts/record.py undo
python scripts/check_config.py
python scripts/summary.py {monthly|quote}
触发规则
内容类型(前缀 → 类型):
- - 日记: / 今天: / riji: / d → 日记
- 笔记: / 学习: / note: / n → 笔记
- 待办: / todo: / t → 待办
- done: / 完成: / √ → 已完成
- 想法: / 灵感: / idea: / flash: / 闪念: / i → 想法
- 问题: / 疑问: / q: → 问题
- 摘抄: / quote: / qu: / z → 摘抄
- 链接: / link: / url: / l → 链接
- 图片: / photo: / img: / p → 图片
格式:
- - 文本 → H1 标题
- 文本 → H2 标题
- 文本 → H3 标题
- > 文本 → 引用块
- --- → 分隔线
- - 文本 → 无序列表
- 1. 文本 / 2. 文本 等 → 有序列表
- toggle: 标题 + 后续 - / -- / --- 行 → 折叠块
命令:
- - 月报 / monthly → 提取当月记录生成摘要
- 摘抄 / 随机摘抄 → 随机历史条目
- 搜: xxx / search: xxx → 按关键词搜索记录
- 撤回 / undo → 删除上一批块(5 分钟内)
- 配置检查 / check config → 验证配置
智能检测(无前缀,AI 推断):
- - 纯 URL → 链接
- 以 YYYY-MM-DD 开头 → 日记
- 包含 [ ] 或 【 】 → 待办
- 默认 → 想法
元数据
扫描最后一行获取元数据:
- - #关键词 → 标签
- /p:项目名 → 项目
- 在传递给脚本前从内容中移除元数据
批量与撤回
- - 多行消息:每个格式行(标题/引用/分隔线/列表)成为单独的块,通过单次 API 调用发送
- 5 分钟内撤回:删除上一批的所有块
- 5 分钟后撤回:仅删除最后一个单独的块
- 日期分隔符:当最后一条记录来自不同日期时,自动插入分隔线
输出协议
脚本输出标准化前缀:
- - OK|消息 → 成功,向用户转发成功消息
- ERROR|CONFIG → 引导用户设置 Notion 集成
- ERROR|AUTH → API 密钥无效或页面未授权
- ERROR|RATE_LIMIT → 告知用户等待
- ERROR|NETWORK → 告知用户稍后重试
首次使用务必先运行 check_config.py。切勿修改或删除现有的 Notion 块。
图片上传
- - 支持本地文件路径(例如 C:\Users\photos\img.jpg)和 HTTP URL(例如 https://example.com/photo.png)
- 本地文件通过文件上传 API 上传到 Notion 服务器,然后作为图片块附加
- URL 图片直接作为外部图片块引用
- 可选 --caption 标志为图片添加说明文字
- 最大文件大小:5MB(Notion API 限制)
- 支持的格式:jpg, jpeg, png, gif, webp, bmp, svg