Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用dialogflow将多个参数写入firestore数据库_Javascript_Node.js_Firebase_Google Cloud Firestore_Dialogflow Es - Fatal编程技术网

Javascript 使用dialogflow将多个参数写入firestore数据库

Javascript 使用dialogflow将多个参数写入firestore数据库,javascript,node.js,firebase,google-cloud-firestore,dialogflow-es,Javascript,Node.js,Firebase,Google Cloud Firestore,Dialogflow Es,我创建了一个dialogflow代理来注册用户的一些信息,我需要为每个用户将这些答案作为同一个文档来编写,但我编写的代码是将每个答案编写到单个文档中,而不是将所有答案都作为不同的文档来编写,日志没有显示任何错误,所以我想这是一个逻辑问题,我无法识别 index.js: 'use strict'; const functions = require('firebase-functions'); const {WebhookClient} = require('dialogflow-fulfill

我创建了一个dialogflow代理来注册用户的一些信息,我需要为每个用户将这些答案作为同一个文档来编写,但我编写的代码是将每个答案编写到单个文档中,而不是将所有答案都作为不同的文档来编写,日志没有显示任何错误,所以我想这是一个逻辑问题,我无法识别

index.js:

'use strict';

const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = 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 });
  console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
  console.log('Dialogflow Request body: ' + JSON.stringify(request.body));

  function cadastroHandler(agent) {
    let nome = agent.parameters.nome ;
    db.collection("cadastros").add({ nome: nome });

    let estado = agent.parameters.estado ;
    db.collection("cadastros").add({ estado: estado });

    let cidade = agent.parameters.cidade ;
    db.collection("cadastros").add({ cidade: cidade });

    let coord = agent.parameters.coord ;
    db.collection("cadastros").add({ coord: coord });

    let wppcoord = agent.parameters.wppcoord ;
    db.collection("cadastros").add({ wppcoord: wppcoord });

    let emailcoord = agent.parameters.emailcoord ;
    db.collection("cadastros").add({ emailcoord: emailcoord });

    let area = agent.parameters.area ;
    db.collection("cadastros").add({ area: area });

    agent.add(`cadastro concluido`);
  }

  function fallback(agent) {
    agent.add(`I didn't understand`);
    agent.add(`I'm sorry, can you try again?`);
  }


  let intentMap = new Map();
  intentMap.set('cadastro', cadastroHandler);
  intentMap.set('Default Fallback Intent', fallback);
  // intentMap.set('your intent name here', yourFunctionHandler);
  // intentMap.set('your intent name here', googleAssistantHandler);
  agent.handleRequest(intentMap);
});


每个参数都会以相同的“cadastro”意图顺序向用户询问,并作为单个参数登录

将您的功能更改为此

function cadastroHandler(agent) {
    let { nome, estado, cidade, coord, wppcoord, emailcoord, area } = agent.parameters;
    db.collection("cadastros").add({ 
       nome: nome,
       estado: estado,
       cidade: cidade,
       coord : coord ,
       wppcoord  : wppcoord  ,
       emailcoord: emailcoord ,
       area :area 
    });

    agent.add(`cadastro concluido`);
  }


把你的函数改成这个

function cadastroHandler(agent) {
    let { nome, estado, cidade, coord, wppcoord, emailcoord, area } = agent.parameters;
    db.collection("cadastros").add({ 
       nome: nome,
       estado: estado,
       cidade: cidade,
       coord : coord ,
       wppcoord  : wppcoord  ,
       emailcoord: emailcoord ,
       area :area 
    });

    agent.add(`cadastro concluido`);
  }