After the updating of the Dialogflow API v1 to API v2, it seems a lot of people are facing issues while integrating the API v2.
Here I am showing communication with Dialogflow API v2, with and Angular 5+.
- Detecting Intent
- Triggering Intent
To get more overview you can visit Dialogflow detectIntent
This are the major APIs lot of users are willing to integrate.
The Request needs Headers with authorization token and body in terms to get success response.
For authorization you will be needing the access token which you need to generate,
You can use, google-oauth-jwt to get the new access token every time.
You can come with any alternative ways to get new token when token expires or you can send request to get token on every API call.
Alternative like (try/catch, setInterval)
You will be needing your Project ID which you can easily get by Dialogflow Console.
One more thing you will be needing is sessionid which will be unique for your user or browser, you can store it in sessionstorage, localstorage or cookies.
- Download JSON file containing your Project Details.
2. Create one server to get authorization token.
You can host this small snippet on your server.
For now, http://localhost:4000/token will return me access token.
3. Call DF API From Frontend (angular)
Detect Intent API call,
Triggering Event API call
That’s all you need to do to interact with Dialogflow API v2.
Thanks for reading.
If you are dialogflow lover you can join us at, dialogflowcommunity