1

有问题的意图

我得到的错误 这是我得到的唯一错误,它会登录 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);
});
4

1 回答 1

0

错误消息表明您未能注册此 Intent 处理程序。使用 dialogflow-fulfillment 时,通常有这样的代码将 Intent 名称映射到要用作该 Intent 处理程序的函数:

  let intentMap = new Map();
  intentMap.set('IntentName', intentHandler);
  agent.handleRequest(intentMap);

看起来您需要为此功能添加这样的一行。

但是,您的处理程序还有其他问题:

  • 由于您正在执行异步函数(它具有回调),因此您需要返回一个 Promise。
  • on()当该函数可能更合适时,您也在使用该函数once()(您不想获取更新 - 您只需要数据的单个快照)。
  • 我也不确定你为什么使用“/all”作为第一个参数on(),因为它应该是一个事件类型,通常你使用“值”的类型。所以我不确定你认为它应该做什么。

幸运的是,once()如果您不使用回调,该命令会返回一个 Promise。像这样的东西可能更符合您的要求,但很难说:

return ref.once("value")
  .then( snapshot => {
    console.log(snapshot.val());
    // Don't forget to return something to Dialogflow
  })
  .catch( err => {
    console.log(err);
    // Dialogflow should say something went wrong
  });

更新:在您刚刚发布的错误消息中,关键行是

Query.once 失败:第一个参数必须是有效的事件类型 = “value”、“child_added”、“child_removed”、“child_changed”或“child_moved”。

您当前发布的代码看起来在语法上无效,但这一行肯定是错误的:

ref.once('unhandledRejection', err => {
    console.log('Unhandled rejection:', err);

})

我不确定那应该做什么(这应该是.catch()块吗?)但正如错误所暗示的那样,您几乎肯定希望您的调用与ref.once()ref.once('value')在上面的代码中说明的一样。

于 2018-12-04T11:37:22.837 回答