Sync your Notion knowledge base to OpenAI every night

By General Input

Every night at 2am, we refresh your OpenAI knowledge base with the Notion pages your team edited that day, so your AI assistants and Slack bots stay accurate.

Integrations

  • Notion
  • OpenAI
  • Slack Bot

Type

Deterministic Code

Categories

  • Operations
  • Engineering

Build a code workflow that runs every night at 2am and keeps a company OpenAI vector store in sync with our Notion knowledge base, so downstream RAG workflows (a Slack bot, an in-app helper, an agent) always have fresh content.

This is a code workflow, not an agent. Every step is a known operation with structured inputs and outputs; there is no open-ended reasoning.

Trigger: cron, every day at 02:00 in the workspace's timezone (make the time configurable).

Configurable inputs I want to set at install time:

1) A list of Notion parent page IDs (or workspace scope) to watch. 2) The target OpenAI vector store name, defaulting to 'company-kb'. 3) The Slack channel to post the nightly summary in, e.g. #ops-kb-sync.

Steps:

1. Use Notion 'Search by Title' scoped to the configured parent pages, and filter results to pages whose last_edited_time is within the last 24 hours. Paginate until done.

2. For each matching page, call Notion 'Retrieve Page as Markdown' to grab the current content.

3. Maintain a persistent mapping of Notion pageId to OpenAI fileId in the workflow's state (keyed off the vector store name so multiple stores can coexist). Before uploading, if the page already has a saved fileId, call OpenAI 'Delete Vector Store File' to detach the previous version so we do not stack duplicates.

4. Write the markdown to a temporary file (name it after the page title so the file is human-readable in the OpenAI dashboard) and call OpenAI 'Upload File' with purpose 'assistants'.

5. Call OpenAI 'Create Vector Store File' to attach the new uploaded file to the configured vector store. If the vector store does not yet exist, create it once by name and cache its ID in state.

6. Update the pageId to fileId mapping in state so tomorrow's run can find the previous file if the page changes again.

7. After the batch is processed, call OpenAI 'List Vector Store Files' on the target vector store to get the current file count (across all pages in the store).

8. Post exactly one Slack Bot 'Send a Message' summary to the configured channel with: number of pages added or refreshed, number of pages that failed (with the page title and a short reason for each failure, up to say 10 listed), and the current total file count in the vector store. If zero pages changed, post a lightweight 'no changes tonight' note instead.

Robustness notes: if a single page errors out (unshared with the integration, markdown too large, upload failed, whatever), capture the error and keep going so one bad page never sinks the whole batch. Respect Notion and OpenAI rate limits by honoring their retry-after headers. The pageId to fileId mapping is the only piece of state you need to persist across runs; store it under a stable key so re-syncing the same page always replaces its previous upload rather than adding a new one.

Related prompts

Explore more prompts
A brand asset library your marketing team actually searchesTurn Mailjet email clicks into ranked HubSpot follow-upsClean out the Looker dashboards and Looks nobody opensLiveKit live operations console for room moderationWake up dormant Keap leads with a researched reasonLiveChat coverage board for planning next week's shiftsPhone routing control panel for LiveKit voice agentsLinkedIn Ads budget pacing dashboard for every client accountGive your team Looker numbers without buying more seatsPause marketing emails to escalated customers, then restore them