Notion 看板接 ResearchPipe webhook

VC 团队共享看板:触发 ResearchPipe 自动写入 Notion 页面。

场景

VC 同事在群里发了个公司名,自动触发 ResearchPipe 跑公司尽调,结果作为新 Notion 页面落到团队看板。

Step 1 - Notion 准备

  • 建一个 Database "Pipeline",字段:Company / Stage / Industry / Risks / Source
  • 拿 Notion API integration token + database_id

Step 2 - 一个 Python webhook server (FastAPI)

from fastapi import FastAPI, Request
from researchpipe import ResearchPipe
import httpx, os

app = FastAPI()
rp = ResearchPipe(api_key=os.environ["RESEARCHPIPE_KEY"])
NOTION_TOKEN = os.environ["NOTION_TOKEN"]
DB_ID = os.environ["NOTION_DB_ID"]

@app.post("/webhook")
async def webhook(req: Request):
    body = await req.json()
    company_name = body["company_name"]

    # 1) ResearchPipe 跑公司尽调(用 output_schema 拿结构化结果)
    SCHEMA = {
      "type": "object",
      "properties": {
        "latest_round": {"type": "string"},
        "sector": {"type": "string"},
        "red_flags": {"type": "array", "items": {"type": "string"}},
      },
    }
    r = rp.research(input=f"{company_name} 公司尽调,重点看红旗", output_schema=SCHEMA)
    fields = r.get("metadata", {}).get("structured") or {}

    # 2) 提炼字段
    page = {
        "parent": {"database_id": DB_ID},
        "properties": {
            "Company": {"title": [{"text": {"content": company_name}}]},
            "Stage": {"rich_text": [{"text": {"content": fields.get("latest_round", "?")}}]},
            "Industry": {"rich_text": [{"text": {"content": fields.get("sector", "?")}}]},
            "Risks": {"rich_text": [{"text": {"content": "\n".join(fields.get("red_flags", []))}}]},
        },
    }

    # 3) 写入 Notion
    async with httpx.AsyncClient() as cli:
        r = await cli.post(
            "https://api.notion.com/v1/pages",
            json=page,
            headers={
                "Authorization": f"Bearer {NOTION_TOKEN}",
                "Notion-Version": "2022-06-28",
                "Content-Type": "application/json",
            },
        )
    return {"notion_page_id": r.json().get("id"), "credits_used": result.get("metadata", {}).get("credits_charged")}

Step 3 - 部署

  • 简单:uvicorn webhook:app --host 0.0.0.0 --port 8000 + ngrok / cloudflare tunnel
  • 稳定:上 Vercel Edge Function 或 Cloudflare Worker

Step 4 - 触发

curl -X POST https://your-webhook.example/webhook \
  -H "Content-Type: application/json" \
  -d '{"company_name":"宁德时代"}'

成本

每个公司尽调 = 50 credits ≈ ¥0.30。VC 团队一周触发 20 次 ≈ ¥6/周。