dialogflow webhook履行代码失败

时间:2018-06-12 11:48:15

标签: node.js alexa dialogflow

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

  

TypeError:无法读取属性' source'未定义的       在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)       at 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       at _combinedTickCallback(internal / process / next_tick.js:73:7)       at 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);
});

2 个答案:

答案 0 :(得分:1)

对不起,只有在发布我的答案后,我才发现您已经从评论中得到答案。

您的orcaCall函数需要一个agent参数。更改为此:

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

答案 1 :(得分:0)

发布可能为时已晚

您的orcacall()函数需要一个参数agent,因此将其更改为

console.log('Dialogflow Request body: ' + JSON.stringify(request.body));

  function orcacall (agent) { //Here agent is added
      response.setHeader('Content-Type','application/json');

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