A production-ready personal AI assistant with Telegram interface, powered by GPT-5, featuring project management, memory system, calendar integration, and file processing capabilities.
- GPT-5 Integration with tool calling and fallback support
- Semantic Memory System with 1536-dimensional vector embeddings
- Context-Aware Responses with conversation history retrieval
- Multi-Modal Processing (text, images, audio, PDFs, URLs)
- Projects & Tasks with priority and status tracking
- Time Tracking with automatic minute calculation
- Notes System for project documentation
- Today's Tasks with timezone awareness
- Google Calendar OAuth2 authentication
- Free Slot Detection algorithm
- Event Scheduling and rescheduling
- Timezone-Aware operations (Australia/Melbourne)
- URL Content Extraction with BeautifulSoup
- PDF Processing with OCR fallback
- Image OCR with Tesseract
- Audio Transcription with OpenAI Whisper
- Supabase Storage integration
- Backend: FastAPI with uvicorn
- AI: OpenAI GPT-5 with text-embedding-3-small
- Database: PostgreSQL with pgvector extension
- Storage: Supabase Storage
- UI: Telegram Bot API
- Deployment: Docker + Railway (recommended)
βββ main.py # FastAPI application
βββ config.py # Environment config & database clients
βββ openai_client.py # OpenAI integration with tool calling
βββ models.py # Pydantic schemas
βββ util.py # Utility functions
βββ telegram_api.py # Telegram Bot API helpers
βββ tools_pm.py # Project management tools
βββ tools_memory.py # Memory system & embeddings
βββ tools_calendar.py # Google Calendar integration
βββ tools_ingest.py # File processing (URL/PDF/Image/Audio)
βββ sql/
β βββ init.sql # Database schema with pgvector
βββ Dockerfile # Container configuration
βββ requirements.txt # Python dependencies
βββ .env.example # Environment variables template
βββ README.md # This file
- projects: Project management with status tracking
- tasks: Task management with priority and time tracking
- time_entries: Time tracking with automatic minute calculation
- notes: Project notes and profile information
- messages: Conversation history with vector embeddings
- docs: Document chunks with semantic search
- memory_events: System events and decisions
- 1536-dimensional embeddings using text-embedding-3-small
- IVFFlat indexes for efficient similarity search
- Cosine similarity for semantic retrieval
- Python 3.11+
- Docker
- PostgreSQL with pgvector extension
- Supabase account
- OpenAI API key
- Telegram Bot token
- Google Cloud credentials
# Copy environment template
cp .env.example .env
# Edit .env with your credentials
nano .env# Apply database schema
psql "$DATABASE_URL" -f sql/init.sql# Build and run with Docker
docker build -t ai-assistant .
docker run --rm -p 8080:8080 --env-file .env \
-v $(pwd)/credentials.json:/app/credentials.json \
-v $(pwd)/token.json:/app/token.json \
ai-assistant- Push code to GitHub
- Connect Railway to your GitHub repo
- Deploy pgvector template for database with vector extension
- Set environment variables in Railway dashboard
- Initialize database schema via
/init-dbendpoint - Set up Telegram webhook
- Deploy automatically
# OpenAI Configuration
OPENAI_API_KEY=sk-your-openai-api-key-here
OPENAI_MODEL=gpt-5
FALLBACK_MODEL=gpt-5-mini
# Telegram Bot Configuration
TELEGRAM_BOT_TOKEN=123456789:ABC-DEF1234ghIkl-zyx57W2v1u123456789
TELEGRAM_WEBHOOK_SECRET=your-random-secret-token-here
TELEGRAM_ALLOWED_CHAT_ID=123456789
# Database Configuration
DATABASE_URL=postgresql://user:password@host:port/database?sslmode=require
# Supabase Configuration
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_SERVICE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
# Google Calendar Configuration
GOOGLE_CREDENTIALS_PATH=/app/credentials.json
GOOGLE_CALENDAR_ID=primary
# Timezone Configuration
TZ=Australia/Melbourne- Message @BotFather on Telegram
- Create new bot with
/newbot - Get bot token and set in environment
# For local development (with ngrok)
curl -X POST "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/setWebhook" \
-H "Content-Type: application/json" \
-d '{"url":"https://YOUR_PUBLIC_URL/telegram/webhook","secret_token":"'$TELEGRAM_WEBHOOK_SECRET'"}'
# For Railway deployment (PowerShell)
Invoke-RestMethod -Uri "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/setWebhook" -Method POST -Body @{url='https://YOUR_RAILWAY_URL/telegram/webhook'; secret_token='$TELEGRAM_WEBHOOK_SECRET'} -ContentType 'application/x-www-form-urlencoded'
# For Railway deployment (Bash)
curl -X POST "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/setWebhook" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "url=https://YOUR_RAILWAY_URL/telegram/webhook&secret_token=$TELEGRAM_WEBHOOK_SECRET"- Go to Google Cloud Console
- Create new project or select existing
- Enable Google Calendar API
- Create OAuth2 credentials
- Download JSON file as
credentials.json
# Run OAuth flow to generate token.json
python -c "
from tools_calendar import _load_creds
from google.auth.transport.requests import Request
from google_auth_oauthlib.flow import InstalledAppFlow
SCOPES = ['https://www.googleapis.com/auth/calendar']
flow = InstalledAppFlow.from_client_secrets_file('credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
with open('token.json', 'w') as token:
token.write(creds.to_json())
"The AI assistant has access to 14 tools:
get_projects- List all projectscreate_project- Create new projectget_tasks- List tasks with filterscreate_task- Create new taskupdate_task- Update task propertiesadd_time_entry- Log time spentadd_note- Add project noteslist_today- Get today's tasks
search_memory- Semantic search conversationsshow_profile- Get user profileupdate_profile- Update user profile
find_free_slot- Find available timeschedule_event- Create calendar eventreschedule_event- Move existing event
- Input Validation with message length limits
- Chat Whitelisting via TELEGRAM_ALLOWED_CHAT_ID
- Webhook Secret validation
- Non-root Docker user
- Environment Variable protection
- Error Handling without information leakage
- Health Check endpoint at
/health - Debug Endpoint at
/debugfor environment verification - Vector Test endpoint at
/test-vectorfor database validation - Database Init endpoint at
/init-dbfor schema setup - Structured Logging with error tracking
- Database Connection monitoring
- OpenAI API fallback handling
- Free tier available
- Automatic HTTPS
- Easy environment management
- GitHub integration
- Create Railway Account and connect GitHub
- Deploy pgvector Template:
- Go to Railway Extensions
- Deploy "pgvector-pg17" template
- Note the new DATABASE_URL
- Deploy Main App:
- Connect your GitHub repository
- Set environment variables
- Deploy automatically
- Initialize Database:
- Call
/init-dbendpoint to set up schema - Verify with
/test-vectorendpoint
- Call
- Configure Telegram:
- Set webhook using PowerShell command
- Test bot functionality
- Production-ready container
- Health checks included
- Security best practices
- Multi-platform support
- Hot reload with uvicorn
- Environment file support
- Database connection pooling
- Fork the repository
- Create feature branch
- Make changes
- Test thoroughly
- Submit pull request
This project is for personal use. Please respect OpenAI's usage policies and terms of service.
Database Connection Errors
- Verify DATABASE_URL format
- Ensure pgvector extension is installed (use Railway pgvector template)
- Check database permissions
- Test vector extension with
/test-vectorendpoint - Initialize schema with
/init-dbendpoint
OpenAI API Errors
- Verify API key is valid
- Check rate limits
- Ensure sufficient credits
Telegram Webhook Issues
- Verify webhook URL is accessible
- Check secret token matches
- Ensure bot token is correct
- Test webhook with proper PowerShell syntax
- Check TELEGRAM_ALLOWED_CHAT_ID is set correctly
Calendar Integration Issues
- Verify credentials.json exists
- Check token.json is valid
- Ensure calendar API is enabled
Vector Search Issues
- Ensure pgvector extension is properly installed
- Check vector dimension matches (1536 for text-embedding-3-small)
- Verify SQL query uses proper type casting (
::vector) - Test with
/test-vectorendpoint
For issues and questions:
- Check the logs for error details
- Verify all environment variables
- Test individual components
- Check API service status
Built with β€οΈ for personal productivity and AI assistance.