【问题标题】:dialogflow webhook fulfilment code failsdialogflow webhook 实现代码失败
【发布时间】:2018-11-21 19:23:31
【问题描述】:

我正在尝试将 Alexa 与 Dialogflow 集成并使用 Dialogflow 来满足意图请求。对于静态意图响应,我能够正确获得响应,但是当我尝试集成 webhook 以实现完整时,我遇到了异常对话框流:

TypeError:无法读取未定义的属性“源” 在 V2Agent.processRequest_ (/user_code/node_modules/dialogflow-fulfillment/src/v2-agent.js:108:86) 在新的 WebhookClient (/user_code/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:193:17) 在exports.dialogflowFirebaseFulfillment.functions.https.onRequest (/user_code/index.js:26:18) 在 cloudFunction (/user_code/node_modules/firebase-functions/lib/providers/https.js:26:47) 在 /var/tmp/worker/worker.js:684:7 在 /var/tmp/worker/worker.js:668:9 在 _combinedTickCallback (内部/进程/next_tick.js:73:7) 在 process._tickDomainCallback (internal/process/next_tick.js:128:9)

以下是我用于实现 webhook 的代码:

'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 orcacall () {
      response.setHeader('Content-Type','application/json');
      response.send(JSON.stringify({'speech':'myMessage','displayText':'myMessage','data':[],'contextOut':[]}));


  }
let intentMap = new Map();
  intentMap.set('Orca', orcacall);
  agent.handleRequest(intentMap);
});

【问题讨论】:

  • 请添加您尝试过的代码sn -p。仅仅堆栈跟踪是不够的
  • 抱歉,添加代码
  • 您使用的库版本是什么。因为有类似问题的修复 github.com/dialogflow/dialogflow-fulfillment-nodejs/pull/51 。尝试更新到最新版本的 dialogflow-fulillment 。
  • 感谢@Himanshu,更新到最新版本的 dialogflow-fullfilment 就像一个魅力

标签: node.js alexa dialogflow-es


【解决方案1】:

抱歉,我发了我的答案后才发现你已经从 cmets 那里得到了答案。

您的 orcaCall 函数需要一个 agent 参数。改成这样:

function orcacall (agent) {
  response.setHeader('Content-Type','application/json');
  response.send(JSON.stringify({'speech':'myMessage','displayText':'myMessage','data':[],'contextOut':[]}));  }

【讨论】:

    【解决方案2】:

    现在发布可能为时已晚

    你的orcacall() 函数需要一个参数agent 所以把它改成

    console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
    
      function orcacall (agent) { //Here agent is added
          response.setHeader('Content-Type','application/json');
    

    此参数在使用参数和发布响应时很有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-14
      • 1970-01-01
      相关资源
      最近更新 更多