# Sync your Notion knowledge base to OpenAI every night

> 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.

- Workflow type: code
- Services: Notion, OpenAI, Slack Bot
- Categories: Operations, Engineering
- Published: 2026-07-08

## What it does

- Finds every Notion page your team touched in the last 24 hours across the parent pages you want to sync.
- Uploads the fresh content to your OpenAI knowledge base so AI assistants stop giving stale answers.
- Replaces the previous copy of any updated page instead of piling on duplicates, using a saved mapping between Notion pages and OpenAI files.
- Posts a single Slack summary each morning with how many pages synced, how many failed, and how big the knowledge base is now.

## What you'll need

- A Notion workspace and an internal connection shared with the pages you want to sync.
- An OpenAI account with an existing knowledge base, or willingness to let us create one called 'company-kb'.
- A Slack workspace and the channel where the nightly summary should be posted.

## Prompt

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.

## How to customize

- Change the sync time from 2am to any hour that fits your team's timezone.
- Point the workflow at any set of parent Notion pages, so you can sync a single wiki, a handbook, or your whole workspace.
- Rename the OpenAI knowledge base or change the Slack channel that receives the nightly summary.

## FAQ

### Will this create duplicate copies of my Notion pages in OpenAI?

No. The workflow remembers which Notion page maps to which uploaded file, so when a page changes we replace the old copy instead of stacking a second one.

### Do I need Pinecone or another vector database?

No. This workflow uses OpenAI's built in knowledge base, so you don't need to run any separate vector database.

### What happens if one page fails to sync?

The workflow logs the failure, keeps going with the rest of the batch, and includes the failure count in the Slack summary so you know to check on it.

### Can I use this to power a Slack RAG bot or a help center assistant?

Yes. Once your knowledge base is refreshed nightly, any assistant that reads from it will answer with today's content instead of last month's.

### Does this sync every page in Notion or only the ones that changed?

Only pages edited in the last 24 hours, so the nightly job stays fast and cheap even if your workspace is huge.

Use this prompt in General Input: https://www.generalinput.com/prompts/sync-your-notion-knowledge-base-to-openai-every-night