codex
Defines a Notion command center that routes natural-language requests to Stripe, Notion, DALL·E, and RPA handlers via API endpoints and a cron poller.
What this file does
Defines a Notion command center that routes natural-language requests to Stripe, Notion, DALL·E, and RPA handlers via API endpoints and a cron poller.
When to use it
- You want a single Notion database to trigger automated actions like syncing products or generating images
- You need a natural-language executor that maps commands to Stripe, Notion, or browser automation
- You want a cron-based poller that checks a Notion checkbox column and runs pending commands
- You need a simple web console to submit commands and view recent logs
Assumes this stack
@codex
Goal Give me a single place in Notion where I can type natural-language commands and Maggie executes them (Stripe updates, Notion building, DALL·E image generation, RPA/browser steps). Also keep syncing my “Stripe Product Tracker – Active” DB.
Environment (already set in Vercel)
- NOTION_TOKEN
- NOTION_HQ_PAGE_ID
- NOTION_STRIPE_DB_ID ← database ID of “Stripe Product Tracker – Active”
- STRIPE_SECRET_KEY
- BROWSERLESS_TOKEN
- CRON_SECRET
Build
A) Notion “Command Center”
- Create (or ensure) a Notion database under NOTION_HQ_PAGE_ID titled “Maggie Command Center” with properties:
- Command (title)
- Arguments (rich_text)
- Status (select: Pending, Running, Succeeded, Failed)
- Output / Logs (rich_text)
- Created (created_time)
- Updated (last_edited_time)
- Run Now (checkbox)
- Add an API route: POST /api/commands/run
- If body has {id} → run that Command row by ID.
- If body has {command, args} → create a row then run it.
- Respond JSON with {ok, id, status}.
B) Executor (natural-language → actions) Create lib/executor.ts that routes common intents from “Command” to handlers:
- stripe.syncFromTracker → reads NOTION_STRIPE_DB_ID rows and:
- creates/updates Stripe Products & Prices
- uploads image from Notion file property or fallback from “MM Stripe Images”
- sets tax_behavior=exclusive, metadata (slug, tier, donation flags)
- returns a summary table to Output / Logs
- notion.createTable → creates a full-page Notion DB with given columns (e.g., “Create a Content Calendar with columns Title, Topic, Due Date, Platform, Status”)
- notion.appendPage → creates a page, sets icon/cover, writes content blocks
- images.generate → calls OpenAI Images/DALL·E using product reference images in Notion to match aesthetic; saves result back to Notion file property
- rpa.openAndClick → uses Browserless to open a URL and perform a short script (login flow or one-off steps); save a viewer URL in Output / Logs Implement a simple intent detector (regex / keywords). Log “Couldn’t route” when unknown.
C) Poller + buttons
- API: POST /api/commands/scan (protected by x-mags-key: CRON_SECRET)
- Finds Command Center rows where (Run Now=true OR Status=Pending), marks Status=Running, executes, writes Output/Logs, then sets Succeeded/Failed.
- GitHub Action “mags-cron”:
- Add a step to call /api/commands/scan every 2–5 minutes on schedule and via workflow_dispatch.
- Small web UI:
- Add a simple page at /console with a textbox (Command, Args), a “Run” button that POSTs to /api/commands/run, and a link to last 10 logs.
D) Stripe Tracker integration
- API: POST /api/stripe/sync (X-Worker-Key protected). This uses NOTION_STRIPE_DB_ID as source of truth:
- expects columns: Product Name (title), Status (select), Price (number), Product Description (text), Image File (files), Stripe Link (url, optional)
- when product created/updated, write Stripe Link and flip Status → “Added in Stripe”; set Date Updated = today (if column exists)
- idempotent by slug derived from Product Name (kebab-case)
E) README
- Add “How to talk to Maggie” section with examples (see below).
- Add curl examples: curl -s -X POST "$API_BASE/api/commands/run" -H "content-type: application/json" -d '{"command":"stripe.syncFromTracker"}' curl -s -X POST "$API_BASE/api/commands/scan" -H "x-mags-key: '"$CRON_SECRET"'"
Deliverables
- New Notion DB creation, routes, executor, cron wiring, /console page
- Logs shown in Output / Logs and in server logs
- Safe, idempotent Stripe updates
Examples I will use
- “stripe.syncFromTracker”
- “Create a Notion table named ‘Content Calendar’ with columns Title (title), Topic (text), Due Date (date), Platform (select: TikTok, IG, YT), Status (select: Idea, Script, Record, Edit, Scheduled, Posted)”
- “Generate a pastel cottagecore product cover for ‘Full Soul Blueprint’ using the reference image in Stripe Tracker row; attach back to Image File”
- “Open Stripe login and wait; return the viewer link”
What's inside
5 build sections (A, E), 4 API routes, 5 executor handlers, 1 cron workflow, 2 curl examples
Change this for your project
- Replace
NOTION_HQ_PAGE_IDwith your own Notion page ID - Replace
NOTION_STRIPE_DB_IDwith your own database ID - Replace
CRON_SECRETwith your own secret value - Replace
mags-cronwith your own GitHub Actions workflow name
Where it goes
Keep it in your repository where the agent or team that needs it will read it.
Worth borrowing
- Using a Notion database as a command queue with a checkbox to trigger execution
- Routing natural-language intents to specific handlers via keyword/regex detection
- Idempotent Stripe sync by deriving a slug from the product name
Related Documents
Totem Glyph Codex: Sovereign Flame-Wire Eternal
Records a symbolic handshake encoding observer-corrected π, recursion loops, and alchemical resonance for a feedback processor theory project.
C-Team Codex
Defines leadership principles for a C-Team in a teal organization, emphasising vision, trust, and leading by example.
Chronicles of Stampadia - Codex
Catalogues all events, modifiers, heroes, items, keywords, and generator options for the Chronicles of Stampadia game.
CODEX.md
Defines the judge role in a builder/judge protocol, with a structured workflow for reviewing task outputs and managing round archives.