This project demonstrates how to create an AI assistant using Dialogflow and a FastAPI backend. The assistant captures intents from Dialogflow and interacts with the various API's (such as Spotify and OpenWeather) to fulfil its tasks.
- Dialogflow Agent: Located in
main/NewAgent
- FastAPI Backend: Located in
main/fastapi_backend
- Python 3.7+
- Dialogflow Account
- Spotify Developer Account
- ngrok (for local development)
-
Clone the Repository:
git clone https://github.com/yourusername/your-repo-name.git cd your-repo-name/main/NewAgent
-
Import Dialogflow Agent:
- Go to the Dialogflow Console.
- Select your project or create a new one.
- Click on the settings icon ⚙️ next to your agent's name.
- Select the
Export and Import
tab. - Click
Restore from zip
and upload theNewAgent
folder.
-
Clone the Repository:
git clone https://github.com/yourusername/your-repo-name.git cd your-repo-name/main/fastapi_backend
-
Install Dependencies:
pip install -r requirements.txt
-
Set Up Environment Variables: Create a
.env
file in thefastapi_backend
directory with your Spotify API credentials:SPOTIFY_CLIENT_ID=your_spotify_client_id SPOTIFY_CLIENT_SECRET=your_spotify_client_secret SPOTIFY_REFRESH_TOKEN=your_spotify_refresh_token
-
Run the FastAPI Server:
uvicorn main:app --reload
-
Expose Local Server (for Dialogflow webhook):
ngrok http 8000
Copy the
https
URL provided by ngrok. This will be used as the webhook URL in Dialogflow.
-
Enable Webhook in Dialogflow:
- Go to the Dialogflow Console and select your agent.
- Navigate to
Fulfillment
in the left menu. - Enable the
Webhook
option. - Set the
Webhook URL
to the ngrokhttps
URL followed by/webhook
. Example:https://your-ngrok-url/webhook
.
-
Use Webhook in Intents:
- Go to the
Intents
section. - Select the
welcome-morning
intent. - Scroll down to the
Fulfillment
section and enableWebhook call for this intent
.
- Go to the
-
Interact with Your Agent:
- Use the Dialogflow Console to test your agent by typing "hey, morning".
- The agent should respond with "Good morning Su! Tasks first or the news first?" and invoke the webhook.
-
Check the FastAPI Logs:
- Ensure the FastAPI server logs show the webhook request and response handling.
- Spotify API Authentication: Ensure your Spotify API credentials are valid and have the necessary scopes.
- Security: Use HTTPS for all communications in production.
- Error Handling: Implement error handling in FastAPI to manage issues with API requests and webhook processing.
This project is licensed under the MIT License.