A modern, async Python bot that connects Notion to OpenAI's ChatGPT, automating Q&A, research, and documentation directly in your Notion workspace.
- Seamless Notion
↔️ ChatGPT integration - Async worker: Fast, scalable, and configurable polling
- Web dashboard: Monitor status via FastAPI (
app.py) - Automatic code extraction: Stores code blocks separately
- Contextual memory: Remembers previous prompts for better answers
- Persistent storage: Uses SQLite for all prompt/response history
- Easy search & reset: CLI tools to view, search, or reset memory
- Auto-reset on inactivity: Memory can be reset automatically after a configurable period of inactivity
- Clone the repo
- Set up your Notion database (see setup guide)
- Create a
.envfile with your API keys (see below) - Install dependencies
pip install -r requirements.txt
- Run the worker
python main.py
- (Optional) Run the web dashboard
python app.py
NOTION_DB_ID— Your Notion database IDNOTION_API_KEY— Your Notion integration tokenOPENAI_API_KEY— Your OpenAI API keyFAST_MODE— (optional) Set to1for instant responseCONTEXT_WINDOW— (optional) Number of previous prompts to use as context (default: 5)INACTIVITY_RESET_HOURS— (optional) Number of hours of inactivity before memory is automatically reset (default: 24)
- Add prompts to your Notion database (Status: Pending)
- The worker processes them and writes responses back to Notion
- Monitor via the web dashboard (optional)
- View memory:
python main.py memory
- Search memory:
python main.py search <query>
- Reset memory:
python main.py reset
You can use the Railway CLI to link your local project to your Railway service and run commands in the Railway environment.
npm install -g railwayrailway loginIn your project directory:
railway linkFollow the prompts to select your Railway project.
You can now run commands in your Railway service environment using:
railway run python main.py memory
railway run python main.py search <query>
railway run python main.py resetThis will use your Railway environment variables and database, just like in production.
- Railway/Render: Deploy
main.pyas a worker andapp.pyas a web service - Add environment variables to both services
- (Optional) Use persistent volumes for long-term memory retention
- See DEPLOYMENT_GUIDE.md for details
- All prompts and responses are stored in a local SQLite database (
notion_bot_memory.db) - The bot uses the last N prompt/response pairs as context for ChatGPT (configurable via
CONTEXT_WINDOW) - Automatic memory reset: If no prompt is processed for a configurable period (
INACTIVITY_RESET_HOURS), the memory is reset automatically. - For a full technical explanation, see MEMORY_SYSTEM.md
notion-ai-bot/
├── main.py # Worker: Notion processor
├── app.py # Web dashboard
├── memory_db.py # SQLite memory system
├── extract_code.py # Code extraction utility
├── requirements.txt # Python dependencies
├── NOTION_SETUP.md # Notion setup guide
├── DEPLOYMENT_GUIDE.md # Deployment instructions
├── MEMORY_SYSTEM.md # Memory system details
└── ...
© 2025 Germaine Luah