我需要在fireflow数据库中存储一些在Dialogflow中输入的详细信息,但是我遇到了以上错误。
index.js:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const parameters = request.body.result.parameters;
let action = request.body.result.action;
var Name = request.body.result.parameters.Name;
var Answer1 = request.body.result.parameters.Answer1;
let query = request.body.result.resolvedQuery;
const inputContexts = request.body.result.contexts;
admin.firestore().collection('users').doc('Details').collection('Myuser1').set({
name : Name ,
answer1 : Answer1
}).then(ref => {
console.log('Added new user');
console.log('name' +Name);
console.log('Answer1 is :' +Answer1);
});
});
我能够成功地将名称添加到集合中,但是当我尝试在同一documentID下将“ answer1”添加到数据库中时,出现以下错误:
错误:
Error: Invalid use of type "undefined" as a Firestore argument.
at Object.exports.customObjectError.val [as customObjectError] (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/validate.js:164:14)
at Function.encodeValue (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/document.js:813:20)
at Function.encodeFields (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/document.js:683:36)
at Function.fromObject (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/document.js:223:55)
at WriteBatch.create (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/write-batch.js:195:39)
at DocumentReference.create (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/reference.js:354:8)
at CollectionReference.add (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/reference.js:2150:24)
at exports.dialogflowFirebaseFulfillment.functions.https.onRequest (/user_code/index.js:12:76)
at cloudFunction (/user_code/node_modules/firebase-functions/lib/providers/https.js:37:41)
at /var/tmp/worker/worker.js:684:7