I found this example on the official site of DialogFlow using Node.js and it is working fine, but I dont know how do I integrate this into my web application.
Is it
The below snippet explains how we can communicate from a webapp to dialogflow NLU. To get access token we can make use of Google cloud SDK to obtain the token, but it has one hour validity so having this in a different service and obtain it before making call to dialogflow will give a workaround.
$(document).ready(function(){
$("button").click(function(){
$.ajax({
type: "POST",
url: "https://dialogflow.googleapis.com/v2/projects/YOUR-PROJECT-NAME/agent/sessions/SESSIONIDOFYOURCHOICE:detectIntent",
contentType: "application/json; charset=utf-8",
dataType: "json",
headers: {
"Authorization": "Bearer " + "YOUR ACCESS TOKEN GOES HERE",
},
data: JSON.stringify({ "queryInput":{
"text":{
"text":"YOUR QUERY TO NLU",
"languageCode":"en-US"
}
} }),
success: function(data) {
$("#div").html(data.queryResult.fulfillmentText);
},
error: function() {
console.log("Internal Server Error");
}
});
});
});