A versatile chatbot system that can be used both locally via Flask/Streamlit and through WhatsApp integration.
.
├── cp_flask/ # Core Flask application for local bot
│ ├── agent.py # Main agent logic and conversation handling
│ ├── app.py # Flask application setup
│ ├── schemas.py # Data schemas
│ └── __init__.py
├── data/ # JSON data files
│ ├── doctors.json
│ ├── locations.json
│ ├── services.json
│ └── slots.json
├── wa_cp_flask/ # WhatsApp integration components
│ ├── bot_handler.py # WhatsApp message handler
│ ├── send_whatsapp.py # WhatsApp message sender
│ ├── history.py # Conversation history management
│ └── __init__.py
├── requirements.txt # Project dependencies
├── streamlit_chat.py # Streamlit interface for local testing
└── webhook.py # WhatsApp webhook handler
The bot can be used in two different ways:
This mode uses the following files:
cp_flask/directory: Contains the core Flask application and agent logicstreamlit_chat.py: Provides a web interface for local testingdata/directory: Contains all the necessary JSON data files
To run the local chatbot:
- Start the Flask server:
python cp_flask/app.py- In a separate terminal, start the Streamlit interface:
streamlit run streamlit_chat.py- Access the chat interface at
http://localhost:8501
This mode uses the following files:
wa_cp_flask/directory: Contains WhatsApp-specific handlers and utilitieswebhook.py: Handles incoming WhatsApp messagescp_flask/agent.py: Reuses the core agent logic for WhatsApp conversations
To run the WhatsApp bot:
- Start the webhook server:
python webhook.py- Start ngrok to expose your local server:
ngrok http 3000- Configure Meta Developer Account:
- Go to Meta Developer Console
- Set up a WhatsApp Business API
- Configure webhook URL with your ngrok URL +
/webhook - Set the verify token as "12345" (or update it in webhook.py)
You can test if your webhook is properly configured using curl commands:
- Test the verification token (should return the challenge value):
curl -X GET "http://localhost:3000/webhook?hub.mode=subscribe&hub.verify_token=12345&hub.challenge=CHALLENGE_ACCEPTED"- Test with invalid token (should return 403):
curl -X GET "http://localhost:3000/webhook?hub.mode=subscribe&hub.verify_token=wrong_token&hub.challenge=CHALLENGE_ACCEPTED"- Test webhook with sample message (should return 200):
curl -X POST "http://localhost:3000/webhook" \
-H "Content-Type: application/json" \
-d '{
"object": "whatsapp_business_account",
"entry": [{
"id": "WHATSAPP_BUSINESS_ACCOUNT_ID",
"changes": [{
"value": {
"messaging_product": "whatsapp",
"metadata": {
"display_phone_number": "PHONE_NUMBER",
"phone_number_id": "PHONE_NUMBER_ID"
},
"contacts": [{
"profile": {
"name": "NAME"
},
"wa_id": "WHATSAPP_ID"
}],
"messages": [{
"from": "WHATSAPP_ID",
"id": "MESSAGE_ID",
"timestamp": "TIMESTAMP",
"text": {
"body": "Hello!"
},
"type": "text"
}]
},
"field": "messages"
}]
}]
}'Expected responses:
- Verification test: Should return the challenge value
- Invalid token test: Should return "Verification token mismatch"
- Message test: Should return a 200 status code
- Python 3.8+
- Meta Developer Account (for WhatsApp integration)
- ngrok (for WhatsApp webhook)
- Clone the repository:
git clone <repository-url>
cd <repository-name>- Install dependencies:
pip install -r requirements.txt- Create a
.envfile in the root directory with the following variables:
GROQ_API_KEY="your_grok_api_key"
ACCESS_TOKEN="access token"
APP_ID="facebook developer app id"
APP_SECRET="facebook developer app secret"
RECIPIENT_WAID="+phone number" # Your WhatsApp number with country code (e.g., +31612345678)
VERSION="v23.0"
PHONE_NUMBER_ID="whatsapp phone number id"
VERIFY_TOKEN="12345"
FLASK_ENV="development"
FLASK_APP="app.py"
- Local chat interface using Streamlit
- WhatsApp integration for mobile messaging
- Intelligent conversation handling with OpenAI GPT
- Appointment booking system
- Doctor and service information lookup
- Location-based hospital search
- Open the Streamlit interface
- Start chatting with the bot
- The bot can help with:
- Booking appointments
- Finding doctors
- Locating hospitals
- Answering healthcare queries
- Send a message to your WhatsApp Business number
- The bot will respond automatically
- Follow the conversation flow for booking appointments or getting information
- Never commit the
.envfile - Keep your API keys secure
- Update the webhook verification token in production
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
[Add your license here]

