I would like to know the best practice to parse the response of detectIntent of dialogflow v2.
The response of dialogflow v2 includes struct object which is defined in Protocol Buffer. For example, parameters in queryResult.
I know it is possible to parse it by using structToJson which is included in dialogflow v2 SDK for Node.js as sample code. So the my current code is looks like this.
const dialogflow = require("dialogflow");
const structjson = require("./dialogflow/structjson");
identify_intent(sentence, options){
const session_path = this._sessions_client.sessionPath(this._project_id, options.session_id);
// The text query request.
const request = {
session: session_path,
queryInput: {
text: {
text: sentence,
languageCode: this._language
}
}
};
// Send request and log result
return this._sessions_client.detectIntent(request).then(responses => {
let result = responses[0].queryResult;
if (result.parameters){
result.parameters = structjson.structProtoToJson(result.parameters);
}
return result;
});
}
I'm parsing the response manually by using structProtoToJson() following the sample code but it is not practical since I have to do it not only for parameters but also fo fulfillment and other object as well which is formatted in struct.
I'm wondering what is the best practice to parse the response from detectIntent in Node.js app.