实现对话流中的一个index.js文件,具有多个函数/触发器到firestore#AskFirebase



我在对话框流中有下面的代码("firebase函数":"^3.7.0&">和节点:10(DialogFlow index.js有问题DialogFlow 中的照片项目

  1. 我有四个意图:Ligar,Desligar,Abrir e Fechar(所有都启用了实现(

  2. 我在部署或执行(记录云函数(中没有问题,但唯一有效的函数是getLigar((如何解决?

'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);
});

答案是:在问题中提到的4个函数之前,我需要async,并将wait放在正确的位置。下面我举了一个用于4个功能中的第一个的例子:

async function getLigar(agent) {
return await db.collection('xxxxx').doc('yyyyy').get()

相关内容

  • 没有找到相关文章

最新更新