[英]One index.js file in fulfillment dialogflow with multiple functions/trigger to firestore #AskFirebase
I have the code below in the dialogflow ("firebase-functions": "^ 3.7.0" and node: 10 ) DialogFlow index.js with issue Photos project in DialogFlow我在对话框流中有以下代码(“firebase-functions”: “^ 3.7.0”和节点:10 ) DialogFlow index.js 与 DialogFlow 中的问题照片项目
I have four intents: Ligar, Desligar, Abrir e Fechar (all with fulfillment enabled)我有四个意图:Ligar、Desligar、Abrir e Fechar(都启用了履行)
I not have issue in deploy or in execution(logs cloud functions), but the only function that works is getLigar().我在部署或执行中没有问题(记录云功能),但唯一有效的 function 是getLigar()。 How to solve this?
如何解决这个问题?
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({request, response});
function getLigar(agent) {
var gpioalarmstateb = agent.parameters;
return db.collection('xxxxx').doc('yyyyy').get()
.then(doc => {
const xalarmstate = doc.data().gpioalarmstate;
if (!xalarmstate) {
db.collection('xxxxx').doc('yyyyy').update({
gpioalarmstate: true
})
}
agent.add(`Gpioalarmstate is ${gpioalarmstateb} xalarmstate is ${xalarmstate}.`);
});
}
function getDesligar(agent) {
var gpioalarmstateb = agent.parameters;
return db.collection('xxxxx').doc('yyyyy').get()
.then(doc => {
const xalarmstateD = doc.data().gpioalarmstate;
if (xalarmstateD) {
db.collection('xxxxx').doc('yyyyy').update({
gpioalarmstate: false
})
}
agent.add(`Gpioalarmstate is ${gpioalarmstateb} xalarmstate is ${xalarmstateD}.`);
});
}
function getAbrirr(agent) {
var gpiogaragestateb = agent.parameters;
return db.collection('xxxxx').doc('yyyyy').get()
.then(doc => {
const xgaragestate = doc.data().gpiogaragestate;
if (!xgaragestate) {
db.collection('xxxxx').doc('yyyyy').update({
gpiogaragestate: true
})
}
agent.add(`Gpiogaragestate is ${gpiogaragestateb} xgaragestate is ${xgaragestate}.`);
});
}
function getFechar(agent) {
var gpiogaragestateb = agent.parameters;
return db.collection('xxxxx').doc('yyyyy').get()
.then(doc => {
const xgaragestateF = doc.data().gpiogaragestate;
if (xgaragestateF) {
db.collection('xxxxx').doc('yyyyy').update({
gpiogaragestate: false
})
}
agent.add(`Gpiogaragestate is ${gpiogaragestateb} xgaragestate is ${xgaragestateF}.`);
});
}
let intentMap = new Map();
intentMap.set('Ligar', getLigar);
intentMap.set('Desligar', getDesligar);
intentMap.set('Abrir', getAbrirr);
intentMap.set('Fechar', getFechar);
agent.handleRequest(intentMap);
});
The answer was: I needed async before the 4 functions mentioned in the question and put await in the right place.答案是:我需要在问题中提到的 4 个函数之前使用async并将await放在正确的位置。 Below I put an example that served for the first of the 4 functions:
下面我举了一个例子,它服务于 4 个函数中的第一个:
async function getLigar(agent) {
return await db.collection('xxxxx').doc('yyyyy').get()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.