Dialogflow Webhook实现未返回响应

时间:2018-09-04 16:00:12

标签: javascript firebase google-cloud-functions dialogflow

我正在构建一个聊天机器人,并且我想对地址进行一些验证(荷兰的邮政编码必须写为[1234XX]。但是在我的意图和Webhook被调用之后,对话什么也没有返回。它只是说“空响应”

在Firebase中,出现以下错误:

Error: No handler for requested intent
    at WebhookClient.handleRequest (/user_code/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:287:29)
    at exports.dialogflowFirebaseFulfillment.functions.https.onRequest (/user_code/index.js:49:9)
    at cloudFunction (/user_code/node_modules/firebase-functions/lib/providers/https.js:26:47)
    at /var/tmp/worker/worker.js:689:7
    at /var/tmp/worker/worker.js:673:9
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickDomainCallback (internal/process/next_tick.js:128:9)

我正在运行的代码如下:

'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
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 woningwaarde_instant_function (agent) {
    // get the employee ID parameter from the request header received from Dialogflow
    let zipcode = agent.parameters.zipcode;
    if (zipcode.length === 6) { 
        agent.add(`The length of the Employee ID should be six characters. Please enter the correct ID.`); 
    } else { agent.add('lengte van postcode == 6'); }
  }

  function welcome (agent) {
    agent.add(`Welcome to my agent!`);
    agent.add(agent.request_.body.queryResult.fulfillmentText);
  }

  function fallback (agent) {
    agent.add(`I didn't understand`);
    agent.add(`I'm sorry, can you try again?`);
  }

  // Run the proper function handler based on the matched Dialogflow intent name
  let intentMap = new Map();
  intentMap.set('woningwaarde_instant', woningwaarde_instant_function);
  intentMap.set('Default Welcome Intent', welcome);
  intentMap.set('Default Fallback Intent', fallback);
  agent.handleRequest(intentMap);
});

好像     agent.handleRequest(intentMap); 不满意,但我不知道如何解决此问题,我一直在努力尝试整天都能在网上找到的一切...

enter image description here

1 个答案:

答案 0 :(得分:0)

我认为您的welcome函数处理程序带有下划线,其中不应有下划线,而应为:

    agent.add(request.body.queryResult.fulfillmentText);