【问题标题】:writing more than one parameter to a firestore database with dialogflow使用 dialogflow 将多个参数写入 Firestore 数据库
【发布时间】:2020-05-15 01:52:17
【问题描述】:

我创建了一个对话流代理来注册用户的一些信息,我需要将这些答案写成每个用户的同一个文档,但我所做的代码是将每个答案写到一个单独的文档而不是全部不同的是,日志没有显示任何错误,所以我想这是一个我无法识别的逻辑问题......

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

按照相同的“地籍”意图依次向用户询问每个参数,并作为单独的参数登录

【问题讨论】:

    标签: javascript node.js firebase google-cloud-firestore dialogflow-es


    【解决方案1】:

    把你的函数改成这个

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

    【讨论】:

      猜你喜欢
      • 2019-06-06
      • 1970-01-01
      • 1970-01-01
      • 2019-02-28
      • 1970-01-01
      • 2020-05-17
      • 1970-01-01
      • 2021-05-10
      • 2020-03-04
      相关资源
      最近更新 更多