我得到的错误 这是我得到的唯一错误,它会登录 firebase。它并没有告诉我太多,所以我发送了我得到的错误的屏幕截图。
Error: Query.once failed: First argument must be a valid event type = "value", "child_added", "child_removed", "child_changed", or "child_moved".
at validateEventType (/user_code/node_modules/firebase-admin/node_modules/@firebase/database/dist/index.node.cjs.js:1593:19)
at Reference.Query.once (/user_code/node_modules/firebase-admin/node_modules/@firebase/database/dist/index.node.cjs.js:4825:9)
at This (/user_code/index.js:40:5)
at WebhookClient.handleRequest (/user_code/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:303:44)
at exports.dialogflowFirebaseFulfillment.functions.https.onRequest (/user_code/index.js:88:9)
at cloudFunction (/user_code/node_modules/firebase-functions/lib/providers/https.js:57:9)
at /var/tmp/worker/worker.js:724:7
at /var/tmp/worker/worker.js:707:11
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickDomainCallback (internal/process/next_tick.js:128:9)
请求正文
Dialogflow 请求正文:
{
"responseId": "6c61001c-7b4c-4d1d-9790-6774dde5a821",
"queryResult": {
"queryText": "what is the number",
"action": "This",
"parameters": {
"number": "number"
},
"allRequiredParamsPresent": true,
"fulfillmentMessages": [
{
"text": {
"text": [
""
]
}
}
],
"intent": {
"name": "projects/bot-tmnvld/agent/intents/0f19a151-afbb-4c28-b948-ced1f3b56d6e",
"displayName": "This"
},
"intentDetectionConfidence": 1,
"languageCode": "en-us"
},
"originalDetectIntentRequest": {
"source": "GOOGLE_TELEPHONY",
"payload": {
"telephony": {
"caller_id": "REDACTED_IN_STANDARD_TIER_AGENT"
}
}
},
"session": "projects/bot-tmnvld/agent/sessions/doP4-dClQBiAl_WDixhMkg",
"alternativeQueryResults": [
{
"queryText": "what is the number",
"languageCode": "en-us"
}
]
}
代码:
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const firebase = require("firebase-admin");
//const serviceAccount = require("path/to/serviceAccountKey.json");
firebase.initializeApp();
process.env.GCLOUD_PROJECT;
process.env.FIREBASE_CONFIG;
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 Data(agent){
const allParam = agent.parameters.all;
const all = allParam.replace(/\+/g, "").replace(/-/g,'').replace(/ /g,'');
//agent.add(number + number + number);
return firebase.database().ref('/all').push({all: all}).then((snapshot) => {
console.log('database write successful: ' + snapshot.ref.toString());
});
}
函数这个(代理){
const db = firebase.database();
const ref = db.ref("my/database/my/data");
return ref.once("value")
.then( snapshot => {
console.log(snapshot.val());
// Don't forget to return something to Dialogflow
},
ref.once('unhandledRejection', err => {
console.log('Unhandled rejection:', err);
}));
}
let intentMap = new Map();
//intentMap.set('Default Intent', welcome);
// intentMap.set('Default Fallback Intent', fallback);
intentMap.set('Data', Data);
intentMap.set('This', This);
agent.handleRequest(intentMap);
});