This repo watches a Notion database for rows whose Status is set to Needs draft, looks up similar Approved bricks, generates a draft via OpenAI, and writes results back to Notion.
For each row where Status = Needs draft:
- Finds approved candidates with the same Component type and Component slot.
- Picks the top few closest matches.
- Generates 2 variants (max) and marks one as recommended.
- Writes to:
Matched approvedAI draftAI notes
- Sets Status to
Needs review(or whatever you configure).
By default it won't overwrite AI draft if it already has content.
In your Notion database, make sure these properties exist:
- Status (select)
- Component type (select or text)
- Component slot (select or text)
- Approved copy (text)
- Matched approved (text)
- AI draft (text)
- AI notes (text)
Property names can be customised via env vars (see below).
- Go to Notion: Settings → Connections → Develop or manage integrations.
- Create a new integration, copy the Internal Integration Token.
- Share your database with the integration (via the database Share menu).
You will also need the database ID (from the database URL).
In your GitHub repo: Settings → Secrets and variables → Actions → New repository secret.
NOTION_TOKENNOTION_DATABASE_IDOPENAI_API_KEY
OPENAI_MODEL(default in code isgpt-4o-mini)
If you leave these empty, the script uses the defaults shown:
PROP_TITLE(default:Name)PROP_STATUS(default:Status)PROP_COMPONENT_TYPE(default:Component type)PROP_COMPONENT_SLOT(default:Component slot)PROP_APPROVED_COPY(default:Approved copy)PROP_MATCHED_APPROVED(default:Matched approved)PROP_AI_DRAFT(default:AI draft)PROP_AI_NOTES(default:AI notes)
STATUS_NEEDS_DRAFT(default:Needs draft)STATUS_APPROVED(default:Approved)STATUS_AFTER(default:Needs review)
MAX_ITEMS_PER_RUN(default:10)MAX_CANDIDATES(default:25)OVERWRITE_EXISTING(default:0)DRY_RUN(default:0)
The workflow is in .github/workflows/run.yml and runs every 10 minutes, plus manual trigger.
- In Notion, set a row's Status to
Needs draft. - In GitHub: Actions → "UX Content Bricks Automation" → Run workflow.
- Confirm the row gets filled.
- This is intended to assist drafting, not to mark anything as Approved automatically.
- Keep your human review step.
- If you change property names in Notion, update secrets (or change defaults in
automation.py).
- 401/403 from Notion: integration token wrong, or database not shared with the integration.
- 400 from Notion query: property type mismatch; set the
PROP_*secrets to the correct property names. - OpenAI errors: check API key, model name, and account access.