我有一个名为 Users 的 firestore 集合,并试图通过履行在集合中编写文档。我正在通过对话流代理获取用户的姓名和他的位置,并尝试将其插入到集合中。但是文档没有被插入。
1)从代理获取数据:
名称=代理.参数.名称;
位置=代理.参数.位置;
2)写入firestore集合用户
db.collection("Users").doc("101").set({ name: name, location:location});
该函数已执行,但文档未插入到 firestore 集合中。我错过了什么?
'use strict';
const functions = require('firebase-functions');
const { WebhookClient } = require('dialogflow-fulfillment');
const { Card, Suggestion } = require('dialogflow-fulfillment');
const admin = require('firebase-admin');
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));
var name='';
var location='';
admin.initializeApp(functions.config().firebase);
const db = admin.firestore();
function getUserDetails(agent)
{
name= agent.parameters.name;
location=agent.parameters.location;
console.log("buyer name is " + name);
db.collection("Users").doc("101").set({
name: name,
location:location});
agent.add(`User has been inserted`);
}
intentMap.set('Buy Car', getUserDetails);
agent.handleRequest(intentMap);
})