I'm trying to create a chatbot in DialogFlow that checks the status of your insurance claim.
I have set up a call to an external API (mock), and I use a promise to wait for the response and then return it. However, I consistently get [empty response]
from DF, despite getting the correct data from the mock API. Is it just taking too long?
Below is the relevant code:
var callClaimsApi = new Promise((resolve, reject)=>{
try{
https.get('https://MOCKAPIURL.COM', (res) => {
res.setEncoding('utf8');
let rawData = '';
res.on('data', (chunk) => { rawData += chunk; });
res.on('end', () => {
resolve(JSON.parse(rawData));
});
});} catch(e){reject(e.message);}
});
function checkClaims(agent){
callClaimsApi
.then(function(fulfillment){
console.log("fulfillment name: " + fulfillment.name);
agent.add("It looks like you want to find a claim for " + fulfillment.name);
})
.catch(function(error){console.log(error);});
}
intentMap.set('checkClaims', checkClaims);
here is the output from the logs: