This program interacts with the Dialogflow API to process voice and text inputs and receive corresponding responses from the chatbot. A chatbot is a trained special NLP model using Vertex AI. Bot trained on this small data (just for example) IJRAR23C3149Published.pdf
The APIClient struct encapsulates the functionality for interacting with Google services. It handles authentication, token refreshing, and sending requests to the Dialogflow API.
The refresh_access_token()
method refreshes the access token using the provided refresh token.
It constructs a request to the OAuth2 token endpoint and updates the access token for subsequent requests.
The send_voice()
method sends audio input to Dialogflow.
It encodes the audio data into a Base64 string, constructs the request body, and sends a POST request to the Dialogflow API endpoint.
The send_text()
method sends text input to Dialogflow.
It constructs the request body for text input and sends a POST request to the Dialogflow API endpoint.
The main()
function serves as the entry point for the program.
It displays a menu for user interaction, allowing them to choose between voice and text input options.
Based on the user's selection, it prompts for input, sends the request to Dialogflow, and displays the responses.
For this demo, I've used serde
/serde_json
crates for API messages serialization and deserialization,
the base64
crate for encoding audio, the reqwest
crate for sending requests to the API
and tokio
for async runtime.
- Install Rust
- Run the app
cargo run --release
- Select an Option:
Upon running, the program will display a menu with options: Option 1: Send voice input. Option 2: Send text input. Option 3: Exit the program.
- Provide Input:
Choose an option by entering the corresponding number. Follow the prompts to provide either a path to an audio file (for voice input) or enter your question (for text input).
- View Responses:
After providing input, the program will send the request to Dialogflow. It will display the responses received from Dialogflow.