A beginner-friendly Telegram chatbot that uses OpenAI to provide symptom analysis and health information. This bot demonstrates three key concepts: API calling, custom tools, and function calling.
- Symptom Analysis: Describe your symptoms and get possible conditions
- Health Recommendations: Receive general health advice and when to see a doctor
- Emergency Detection: Automatically detect symptoms that may require immediate attention
- Symptom Categories: Browse common symptom categories
- Educational Focus: Provides information for educational purposes only
- What it is: Making HTTP requests to external services (like OpenAI)
- Example in this bot:
client.chat.completions.create()to get AI responses - Why it's important: Allows your bot to access powerful AI capabilities
- What it is: Functions that extend your bot's capabilities beyond just chat
- Examples in this bot:
get_emergency_guidance()- Detects emergency symptomsget_severity_assessment()- Assesses symptom severity
- Why it's important: Gives your bot specialized functionality
- What it is: AI can automatically decide when to use specific tools
- How it works: AI analyzes user input and calls appropriate functions
- Example: User mentions "chest pain" → AI calls
get_emergency_guidance() - Why it's important: Makes your bot more intelligent and responsive
symptom-diagnostic-bot/
├── bot.py # Main bot logic (Telegram handlers)
├── utils.py # OpenAI API calls and custom tools
├── requirements.txt # Python dependencies
├── .env # Environment variables (create this)
└── README.md # This file
- Message @BotFather on Telegram
- Send
/newbotand follow instructions - Save your bot token
- Go to OpenAI Platform
- Create account and get API key
- Save your API key
# Create project directory
mkdir symptom-diagnostic-bot
cd symptom-diagnostic-bot
# Create virtual environment
python -m venv bot-venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Create .env file
echo "TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here" > .env
echo "OPENAI_API_KEY=your_openai_api_key_here" >> .envpython bot.py- Start the bot: Send
/startto your bot - Get diagnosis: Use
/diagnoseand describe your symptoms - Browse symptoms: Use
/symptomsto see common categories - Get help: Use
/helpfor command list
- Educational Purpose Only: This bot provides general health information for educational purposes
- Not Medical Advice: Always consult healthcare professionals for proper diagnosis
- No Emergency Service: For emergencies, call emergency services immediately
- AI Limitations: AI responses may not always be accurate or complete
# Making OpenAI API call
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "Analyze these symptoms"}],
temperature=0.3
)def get_emergency_guidance(symptoms: str) -> str:
emergency_keywords = ['chest pain', 'difficulty breathing']
# Check for emergency symptoms
# Return appropriate guidance# Define tools for AI to use
tools = [
{
"type": "function",
"function": {
"name": "get_emergency_guidance",
"description": "Check for emergency symptoms"
}
}
]The bot includes advanced function calling capabilities in utils.py:
- Emergency symptom detection
- Severity assessment
- Structured JSON responses
- Error handling and fallbacks
Feel free to improve this bot by:
- Adding more custom tools
- Enhancing error handling
- Improving the UI/UX
- Adding more health-related features
This project is for educational purposes. Please ensure compliance with OpenAI's terms of service and Telegram's bot policies.