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

若昂·马科斯·佩雷拉·克

我创建了一个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`);
  }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法将数据写入数据库Firebase Firestore

无法将查询参数写入数据库

如何将多个DataFrame写入MySQL数据库?

spotfire:如何使用参数化信息链接将blob写入数据库?

Python脚本使用json数据库;是否可以将脚本的多个实例写入文件?

使用管道将表写入多个数据库连接

Firebase Functions将数据写入Cloud Firestore数据库时,写入次数是否计数?

使用foreach将数据写入Access数据库

在数据库的整数列中使用Nan将数据写入数据库

如何使用ODBC将多个命名参数传递给DB2数据库

使用 Firestore 数据库在地图上创建多个标记

使用Angular从Firestore数据库返回多个集合

无法使用 Azure 函数将值写入数据库

使用SSH将Pandas Dataframe写入MYSQL数据库

无法将数据写入数据库

使用列名参数将数据插入数据库表

将列表从数据库写入PDF

我如何使用 DialogFlow 从数据库 Firebase 读取多个子项?

从数据库表中读取(查找多个条件)记录,并使用匹配条件将其写入数据库表

如何将流查询的结果写入多个数据库表?

如何使用条件写入数据库?

无法使用 Azure 数据工厂的 ODBC 连接器将数据写入 Snowflake 数据库

无法在Firebase Realtime数据库中使用推送写入多个JSON记录

如何使用to_sql将pandas数据框写入oracle数据库?

使用 df.to_sql() 将数据块写入数据库时出现 Pandas 错误

使用循环将数据写入R中的oracle数据库

使用 java 将 Postgres 数据库收集的数据写入文本文件

如何将多个应用程序连接到Firestore数据库

如何将多个地图对象(JSON)添加到cloud-firestore数据库?