为什么Dialogflow的此实现代码不起作用?

时间:2019-08-20 05:12:09

标签: dialogflow

我在玩Dialogflow。当我试图找出响应中的选项时,我还想测试Dialogflow是否具有动态响应。例如,从数据库(Firebase数据库或MongoDB)中获取数据并将其显示为响应,而不是对每个响应进行硬编码。

我了解到履行可以做到这一点。当我在Dialogflow的实现中启用内联编辑器时,它已经有一些代码要部署。我想只是为了进行测试,我会在实现中编写一些非常基本的功能,然后看看它是否有效。

// See https://github.com/dialogflow/dialogflow-fulfillment-nodejs
// for Dialogflow fulfillment library docs, samples, and to report issues
'use strict';

const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = 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 welcome(agent) {
    agent.add(`Welcome to my agent!`);
  }

  function fallback(agent) {
    agent.add(`I didn't understand`);
    agent.add(`I'm sorry, can you try again?`);
  }
  function test(agent){
  agent.add('test confirmed!');
  }
  // // Uncomment and edit to make your own intent handler
  // // uncomment `intentMap.set('your intent name here', yourFunctionHandler);`
  // // below to get this function to be run when a Dialogflow intent is matched
  // function yourFunctionHandler(agent) {
  //   agent.add(`This message is from Dialogflow's Cloud Functions for Firebase editor!`);
  //   agent.add(new Card({
  //       title: `Title: this is a card title`,
  //       imageUrl: 'https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png',
  //       text: `This is the body text of a card.  You can even use line\n  breaks and emoji! ?`,
  //       buttonText: 'This is a button',
  //       buttonUrl: 'https://assistant.google.com/'
  //     })
  //   );
  //   agent.add(new Suggestion(`Quick Reply`));
  //   agent.add(new Suggestion(`Suggestion`));
  //   agent.setContext({ name: 'weather', lifespan: 2, parameters: { city: 'Rome' }});
  // }

  // // Uncomment and edit to make your own Google Assistant intent handler
  // // uncomment `intentMap.set('your intent name here', googleAssistantHandler);`
  // // below to get this function to be run when a Dialogflow intent is matched
  // function googleAssistantHandler(agent) {
  //   let conv = agent.conv(); // Get Actions on Google library conv instance
  //   conv.ask('Hello from the Actions on Google client library!') // Use Actions on Google library
  //   agent.add(conv); // Add Actions on Google library responses to your agent's response
  // }
  // // See https://github.com/dialogflow/dialogflow-fulfillment-nodejs/tree/master/samples/actions-on-google
  // // for a complete Dialogflow fulfillment library Actions on Google client library v2 integration sample

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

函数 test 是我与 intentMap.set('test-intent',test); 一起添加到已经存在的代码中的唯一内容。

我的意图如下:

{
  "id": "3fea3cec-d3f0-4d4e-a838-b4134894ea05",
  "name": "test-intent",
  "auto": true,
  "contexts": [],
  "responses": [
    {
      "resetContexts": false,
      "affectedContexts": [],
      "parameters": [
        {
          "id": "de3d79b3-b062-445a-8c55-d499a2d7b12d",
          "required": false,
          "dataType": "",
          "name": "sample",
          "value": "1",
          "promptMessages": [],
          "noMatchPromptMessages": [],
          "noInputPromptMessages": [],
          "outputDialogContexts": [],
          "isList": false
        }
      ],
      "messages": [
        {
          "type": "simple_response",
          "platform": "google",
          "textToSpeech": "t",
          "ssml": "",
          "displayText": ""
        }
      ],
      "defaultResponsePlatforms": {},
      "speech": []
    }
  ],
  "priority": 500000,
  "webhookUsed": false,
  "webhookForSlotFilling": false,
  "fallbackIntent": false,
  "events": [],
  "userSays": [
    {
      "id": "d8aee895-8326-4454-b0f4-c2237984d968",
      "data": [
        {
          "text": "testing...",
          "userDefined": false
        }
      ],
      "isTemplate": false,
      "count": 0,
      "updated": 0,
      "isAuto": false
    }
  ],
  "followUpIntents": [],
  "liveAgentHandoff": false,
  "endInteraction": false,
  "templates": []
}

那是虚无的骨头。我只想在 Google上的操作 中测试响应。

我只会收到我在 Google上的操作 中的“ 测试意图”中手动输入的回复。.

我在做什么错了?

1 个答案:

答案 0 :(得分:1)

在发布此问题之前,当我查看 testing-intent 的json时,我已经弄清楚了我遇到的问题。为此,我必须启用webhook调用。

  1. 转到您要启用“实现”的所选意图页面的底部
  2. 点击实现以展开它。
  3. 点击为此意图启用网络通话呼叫