问题
I try to execute this code on Firebase Cloud Functions
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const firebase_database = require('./conf/firebase');
const { WebhookClient } = require('dialogflow-fulfillment');
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
function searcheColleagueByName(agent){
var lastname = agent.parameters.lastname;
firebase_database.ref().once('value')
.then(team => {
agent.add("some name " + lastname);
})
.catch(err=>{
agent.add("something wrong");
})
}
and after when i make request to my bot from telegram I get error in firebase console:
Error: No responses defined for platform: null
at V2Agent.sendResponses_ (/srv/node_modules/dialogflow-fulfillment/src/v2-agent.js:243:13)
at WebhookClient.send_ (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:505:17)
at promise.then (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:316:38)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7)
What's wrong? why when I use promisse
my agent can't give me an answer?
回答1:
The problem is that, if you're using an async function, then your intent handler must also return a Promise. It isn't enough that you send the reply as part of the then()
clause, you must also return the Promise that the then()
is part of.
In your case, this looks fairly easy. In the searchColleagueByName()
function, you would return then once().then().catch()
result, which is a Promise. (Since then()
and catch()
return a Promise.)
So it might look something like this:
return firebase_database.ref().once('value')
.then(team => {
agent.add("some name " + lastname);
})
.catch(err=>{
agent.add("something wrong");
})
来源:https://stackoverflow.com/questions/53382012/when-i-use-promise-with-dialogflow-library-in-server-get-error