A WhatsApp chatbot built with LangGraph, FastAPI, and Twilio that can handle both text and image responses.
- Python 3.10 or higher
- Docker and Docker Compose (for containerized setup)
- A Twilio account with WhatsApp enabled
- A Tavily API key
- An Ngrok account (for exposing your local server)
Create a .env file in the root directory with the following variables:
# Tavily API Key
TAVILY_API_KEY=your_tavily_api_key
# Ngrok Configuration
NGROK_AUTHTOKEN=your_ngrok_auth_token
HOST=your-reserved-domain.ngrok.io- Build and start the services:
docker-compose up --buildThis will start:
- MCP Server (port 8001)
- WhatsApp Bot (port 8000)
- Ngrok tunnel (port 4040)
- Install dependencies:
pip install -r requirements.txt- Start the MCP server:
python mcp_server.py- In a new terminal, start the WhatsApp bot:
python whatsapp_chatbot_client.py- In another terminal, start ngrok:
ngrok http 8000-
Configure your Twilio WhatsApp sandbox:
- Go to your Twilio Console
- Navigate to Messaging > Try it out > Send a WhatsApp message
- Set the webhook URL to your ngrok URL +
/whatsapp - Example:
https://your-domain.ngrok.io/whatsapp
-
Send a test message to your WhatsApp bot:
- Text: "Hello"
- The bot should respond with a message
.
├── docker-compose.yml # Docker services configuration
├── Dockerfile # Container definition
├── requirements.txt # Python dependencies
├── .env # Environment variables
├── mcp_server.py # MCP server implementation
├── whatsapp_chatbot_client.py # WhatsApp bot implementation
└── graph.py # LangGraph agent configuration
- WhatsApp integration via Twilio
- LangGraph agent for intelligent responses
- Support for both text and image responses
- Docker containerization for easy deployment
- Ngrok integration for exposing local server
-
If you get authentication errors:
- Verify your Twilio credentials in the
.envfile - Check if your Twilio account is active
- Ensure your WhatsApp sandbox is properly configured
- Verify your Twilio credentials in the
-
If the bot doesn't respond:
- Check if all services are running
- Verify the ngrok tunnel is active
- Check the logs for any error messages
-
If Docker services fail to start:
- Ensure Docker and Docker Compose are installed
- Check if ports 8000, 8001, and 4040 are available
- Verify your
.envfile is properly configured
Feel free to submit issues and enhancement requests!