I am having trouble getting the value returned by my https.get function inside the my Dialogflow intent to close the conversation. Regardless whether I execute this call in the app.intent or pass it one to an external function, it fails. I new to node.js but have used angular.js and javascript before but not having success in being able to close the conversation with a response. Google Actions emulator gives me the error
MalformedResponse expected_inputs[0].input_prompt.rich_initial_prompt: 'rich_response' must contain at least one item.
Below is my code:
app.intent('mywebhook', (conv, params) => {
const stateName = params['geo-state-us'];
console.log("My State is " + stateName);
var pathString = 'api path' + encodeURIComponent(stateName);
var request = https.get({
host: 'www.mydomainame.com',
path: pathString
}, function (response){
var json = "";
response.on('data', function(chunk) {
json += chunk;
});
response.on('end', function(){
var jsonData = JSON.parse(json);
var myfirstvar = jsonData[0].firstvar;
var chat = "the value of first var is " + chat;
console.log(chat); // this works fine
conv.close(chat);
});
}).on('error', (e) => {
console.error(e);
});
}
I even tried doing conv.close(chat) outside and JSON.stringify(request) to get the value of myfirstvar but nothing worked. Spent a whole day trying different things but no avail.