因此,我最近开始着手构建一些Firebase Cloud功能以实现Dialogflow代理。我在Firebase项目中实现了入职功能,但是在尝试与Firestore交互时出现错误。
我已仔细检查以确保我的package.json和本地开发环境相同,但仍然会看到此错误。
感谢您的帮助。如果使用测试Dialogflow控制台或Twilio,似乎没有关系,我会遇到相同的异常。不知何故,诺言有误。 liceRef.get()
返回的承诺肯定正在发生,但是我不知道为什么。
'use strict';
const firefunc = require('firebase-functions');
const admin = require('firebase-admin');
const {WebhookClient} = require('dialogflow-fulfillment');
const serviceAccount = require('./service_account.json');
process.env.DEBUG = 'dialogflow:debug';
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
const db = admin.firestore();
const settings = {timestampsInSnapshots: true};
db.settings(settings);
exports.dfWebhook = firefunc.https.onRequest(async (request, response) => {
const agent = new WebhookClient({ request, response });
var uid;
if(agent.requestSource === 'twilio') {
uid = request.body.originalDetectIntentRequest.payload.data.From;
} else {
uid = 'TESTER';
}
console.log("USER ID : ", uid);
async function onboarding(agent) {
const { name, email, license } = agent.parameters;
console.log("-----STARTING ONBOARDING FUNCTION-----");
try {
const liceRef = db.collection('license').doc(license);
const getLice = await liceRef.get();
if(!getLice.exists) {
agent.add("I'm sorry, this license does not exist. blah blah");
} else {
if (getLice.data().uid !== uid && getLice.data().uid) {
agent.add("This license has already been activated for another user etc...");
} else {
await liceRef.set({
name: name,
email: email,
uid: uid
});
agent.add("blah blah success message");
}
}
} catch (err) {
console.error(err);
agent.add("I'm sorry, an error occured and I wasn't able to activate your license. Please try again later or contact support.");
}
}
... INTENT HANDLING CODE ETC ...
}
如果没有失败,我在日志语句后会收到此错误:
8:11:13.748 AM - dfWebhook - Unhandled rejection
8:11:13.748 AM - dfWebhook - Error: No responses defined for platform: twilio
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:303:38)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:229:7)
我唯一能想到的是Firebase配置之间一定存在差异,也许Enterprise Google Cloud / Firebase与Personal不同? 老实说,我很茫然。我或者丢失了一些显而易见的疯狂的东西,或者还有其他事情正在发生,但是看起来这段代码应该可以工作。
预先感谢您的帮助。