This project is a FastAPI application designed to handle incoming webhooks from Twilio. It processes messages and responds with a formatted XML response.
- Validates incoming requests from Twilio.
- Processes user queries and generates responses.
- Returns responses in XML format suitable for Twilio.
- Python 3.7 or higher
- FastAPI
- Uvicorn (ASGI server)
- Ngrok (for exposing local server to the internet)
- Twilio account for testing webhooks
-
Clone the repository:
git clone https://github.com/yourusername/your-repo-name.git cd your-repo-name -
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
-
Environment Variables:
Create a
.envfile in the root directory and add your Twilio credentials and any other necessary configuration:TWILIO_ACCOUNT_SID=your_account_sid TWILIO_AUTH_TOKEN=your_auth_token -
Ngrok Setup:
Download and install Ngrok from ngrok.com. Use it to expose your local server to the internet:
ngrok http 8000
Note the forwarding URL provided by Ngrok (e.g.,
http://e868-2a09-bac0-1000-41c-00-238-2a.ngrok-free.app) and configure it in your Twilio webhook settings.
-
Start the FastAPI server:
uvicorn main:app --reload
This will start the server on
http://127.0.0.1:8000. -
Set up Twilio Webhook:
In your Twilio console, set the webhook URL to the Ngrok forwarding address followed by
/webhook/twilio.
-
Webhook Endpoint:
The main endpoint for Twilio webhooks is
/webhook/twilio. It expects POST requests from Twilio. -
Processing Logic:
The application processes incoming messages and generates a response based on the provided context.
-
Common Issues:
- Ensure Ngrok is running and the URL is correctly configured in Twilio.
- Check server logs for any errors or issues.
- Verify that all environment variables are set correctly.
Contributions are welcome! Please fork the repository and submit a pull request for any improvements or bug fixes.
This project is licensed under the MIT License. See the LICENSE file for details.