Reputation: 23
this is the code that is generating the error, the fullfillment response generated by this intent upon being called is "No response has been set. Is this being used in an async call that was not returned as a promise to the intent handler?" what should i do to correct it?
app.intent('getCrypto', (conv,{crypto="ethereum",cryptoactions="price"}) =>{
fetch('https://api.coinmarketcap.com/v1/ticker/').then(response => {
return response.json();
}).then(data => {
for (let i = 0; i < data.length - 1; i++) {
if (data[i].id === "bitcoin")
conv.data.price=data[i].price_usd;
conv.ask(`${conv.data.price} is the current value of ${crypto}`);
return response.json();
}
}).catch(err => {
return conv.ask(`${cryptoactions} of ${crypto} is not available. Would you like to know about another one?`);
});
});
Upvotes: 2
Views: 1404
Reputation: 7966
To avoid this issue in Dialogflow API version 2,
You must return Promise
, would you prefer to use these structures?
app.intent('getCrypto', conv => {
// I - MUST HAVE PROMISE IN HERE
return new Promise(function (resolve, reject) {
fetch('https://api.coinmarketcap.com/v1/ticker/')
.then(res => {
...
resolve();
})
.catch(error => {
console.log(error);
reject(error)
});
})
.then(function (result) {
console.log(result);
// II - MUST HAVE THIS RESPONSE
// conv.ask(new SimpleResponse("..."));
conv.close(new SimpleResponse(texts.goodbye));
}, function (error) {
});
})
Upvotes: 1
Reputation: 589
The error message describes the exact issue "Is this being used in an async call that was not returned as a promise to the intent handler?"
You should return an async call from your intent handler. So, adding a return
right before your call to fetch
should fix the issue.
Upvotes: 2