I have a dialogflow intent and I want to write a javascript code to get json response of this intent and show it in an html file. I used webhook fulfillment for this intent and now I want to show chat history between dialogflow and user in an html file. I used this javascript code to extract and have dialogflow response:
baseUrl = "https://api.dialogflow.com/v1/",
$.ajax({
type: "POST",
url: baseUrl + "query",
contentType: "application/json; charset=utf-8",
dataType: "json",
headers: {
"Authorization": "Bearer " + accessToken
},
data: JSON.stringify({query: text, lang: "en", sessionId: "b1973977-20be-4cdc-85a5-7f4225cfdb5a"}),
success: function(data) {
console.log("data",data);
prepareResponse(data);
},
error: function() {
respond(messageInternalError);
}
});
}
But the json it returns me is incorrect and has no fulfillment part in order to extract correct data and show response.
The returned json is :
id: "a0114c2a-afdb-415e-af08-e7a2c5b7d925"
lang: "en"
result: {…}
action: ""
metadata: Object { intentName: "Edit.Attributes", intentId: "9601923d-596b-44df-80de-92dff61869cf", webhookUsed: "true", … }
parameters: Object { VarName: […], percentage: "20%", currncy: "", … }
resolvedQuery: "Change the attribute vacancy rate to 20%"
score: 1
source: "agent"
speech: ""
__proto__: Object { … }
sessionId: "b1973977-20be-4cdc-85a5-7f4225cfdb5a"
status: Object { code: 200, errorType: "success", webhookTimedOut: false }
timestamp: "2018-01-24T12:35:46.342Z"
console.log('data',JSON.stringify(data,null,1))- Prisoner