简体   繁体   English

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

[英]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”和节点:10DialogFlow index.js 与 DialogFlow 中的问题照片项目

  1. I have four intents: Ligar, Desligar, Abrir e Fechar (all with fulfillment enabled)我有四个意图:Ligar、Desligar、Abrir e Fechar(都启用了履行)

  2. 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.

相关问题 如何在 index.js 文件中没有触发函数的情况下从 firestore 数据库中读取数据? - How to read data from firestore database without trigger functions in index.js file? 为什么 index.js 实现的动态部分不起作用? - Why the dynamic part of the fulfillment from index.js is not working? Dialogflow 实现以触发另一个意图 - Dialogflow fulfillment to trigger another intent 来自index.js的单元测试功能 - Unit testing functions from index.js 如何将 lib.js 文件中的 Discord.js 函数调用到 index.js 中? - How can I call Discord.js functions from a lib.js file into index.js? 我无法从我的 node.js firebase 函数 index.js 文件中验证大查询 - Im failing to authenticate Big query from my node.js firebase functions index.js file 无法将类导入 index.js 文件 - Cannot import class into index.js file 如何通过单个index.js文件正确渲染多个React组件? - How to render multiple React components through a single index.js file correctly? Cypress 在文件预处理器上的 plugins/index.js 上添加多个函数/事件 - Cypress Add multiple function/event on plugins/index.js on file preprocessor 如何将多个插件添加到 cypress/plugins/index.js 文件? - How do your add multiple plugins to cypress/plugins/index.js file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM