A Telegram bot that provides AI-powered medical consultation using OpenAI's GPT-4. Patients can register their medical history, receive symptom-based follow-up questions, and get filtered medication recommendations β all within Telegram. Built under the guidance of a certified doctor.
- Conversational AI β Powered by GPT-4, acting as a personal medical assistant named "Maya"
- Patient registration β Collects age, gender, allergies, current medications, surgeries, medical conditions, and pregnancy status
- Symptom detection β Automatically detects when a message indicates a medical concern and routes to a structured diagnosis flow
- Prescription filtering β Medication recommendations are filtered against each patient's profile (allergies, conditions, medications, demographics)
- Message streaming β Real-time response delivery via Telegram with typing indicators
- Appointment booking β cal.com integration allows booking with a specialist directly from the bot
- Access control β Optionally restrict the bot to a list of allowed Telegram usernames/user IDs
- Conversation history β Dialog stored in MySQL with automatic context pruning when token limits are approached; sessions reset after a configurable timeout
| Command | Description |
|---|---|
/start |
Initialize the bot |
/help |
Show available commands |
/register |
Register as a patient (collects medical history) |
/diagnose |
Start a structured disease diagnosis flow |
/choose |
Select a concern that best fits your query |
/call |
Book an appointment with a recommended doctor |
/new |
Start a fresh conversation |
/retry |
Regenerate the last bot response |
/cancel |
Cancel the current conversation or task |
- Language: Python 3.8+
- Telegram:
python-telegram-bot20.x - AI: OpenAI API (
gpt-4) viaopenai0.27.x - Database: MySQL via SQLAlchemy ORM
- Async:
aiohttp,aiolimiter - Config: YAML +
.env - Deployment: Docker & Docker Compose
- External: AWS Lambda for cal.com webhook handling
- Docker and Docker Compose
- An OpenAI API key
- A Telegram bot token from @BotFather
- A running MySQL instance
1. Clone the repository
git clone https://github.com/gargmegham/MedicalGPT.git
cd MedicalGPT2. Create configuration files
mv config/config.example.yml config/config.yml
mv config/config.example.env config/config.env3. Edit config/config.yml
telegram_token: "" # From @BotFather
openai_api_key: "" # From OpenAI
use_chatgpt_api: true
allowed_telegram_usernames: [] # Leave empty for public access, or list usernames/user IDs
new_dialog_timeout: 600 # Seconds of inactivity before a new dialog starts
developer_telegram_chatid: "" # Your Telegram chat ID β receives error notifications
admin_telegram_username: "" # Admin username4. Edit config/config.env
MYSQL_USER=
MYSQL_PASSWORD=
MYSQL_HOST=
MYSQL_PORT=
MYSQL_DATABASE=chatgpt5. Run with Docker Compose
docker-compose --env-file config/config.env up --build -dpip install -r requirements.txt
python3 bot/bot.pyPubMedGPT/
βββ bot/
β βββ bot.py # Entry point, bot initialization
β βββ config.py # Config loader
β βββ medicalgpt.py # GPT interaction and token management
β βββ mysql.py # Database operations and prescription logic
β βββ tables.py # SQLAlchemy table definitions
β βββ filters.py # Custom Telegram message filters
β βββ utils.py # Utility helpers
β βββ handlers/
β βββ commands.py # Command handlers (/start, /help, etc.)
β βββ disease.py # Disease diagnosis conversation flow
β βββ message.py # Message streaming handler
β βββ registeration.py # Patient registration conversation flow
βββ config/
β βββ config.example.yml # YAML config template
β βββ config.example.env # ENV config template
β βββ chat_modes.yml # System prompts for different chat modes
βββ lambda_cal.com/
β βββ lambda_function.py # AWS Lambda for cal.com booking webhooks
βββ training_data/ # Disease-specific JSONL training datasets
βββ Dockerfile
βββ docker-compose.yml
βββ requirements.txt
| Table | Purpose |
|---|---|
user |
Patient profiles β demographics, medical history |
dialog |
Conversation history stored as JSON |
disease / disease_question |
Structured diagnosis questions per disease |
medicine |
Medication database with eligibility filters |
disposition |
Prescriptions issued per patient/disease |
booking |
Appointment records from cal.com |
The lambda_cal.com/ directory contains an AWS Lambda function that handles cal.com webhook events (BOOKING_CREATED, BOOKING_CANCELLED). It records bookings in the database and can notify the patient via Telegram.
Booking link template: https://cal.com/<your-username>/telegram-medicalgpt
- Invoicing and payment gateway integration
- PDF prescription generation with certified professional sign-off after case review
This bot is intended as an informational aid and does not replace professional medical advice, diagnosis, or treatment. Always consult a qualified healthcare provider for medical decisions.
