从外部Angular 6聊天窗口调用时Dialogflow Webhook不起作用

时间:2018-11-08 09:46:26

标签: angular firebase angular6 dialogflow

我创建了一个Dialogflow聊天机器人。在其中创建了一个Webhook,将其与Firebase集成。当用户从内部对话框流聊天框(聊天窗口)向机器人提问时,chatbot和webhook可以正常工作。

我想创建我的自定义聊天窗口。因此,我使用Angular 6创建了一个。将我的Angular前端与dialogflow聊天代理集成在一起。对于此Angular聊天窗口,dialogflow chatbot可以很好地解决静态问题,但是当我查询使用Webhook的意图时,日志中出现以下错误:

  

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:201:17)       在exports.dialogflowFirebaseFulfillment.functions.https.onRequest(/user_code/index.js:14:17)       在cloudFunction(/user_code/node_modules/firebase-functions/lib/providers/https.js:26:47)       在/var/tmp/worker/worker.js:714:7       在/var/tmp/worker/worker.js:697:11       在_combinedTickCallback(内部/进程/next_tick.js:73:7)       在process._tickDomainCallback(internal / process / next_tick.js:128:9)

下面是我的 index.js 文件(网络实现)

$('#calendar').fullCalendar({
        schedulerLicenseKey: 'GPL-My-Project-Is-Open-Source',
        scrollTime: '00:00',
        height: 'auto',
        contentHeight: 'auto',
        resourceAreaWidth: '15%',
        nowIndicator: true,
        resources: ?????

package.json

const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');

// initialise DB connection
const admin = require('firebase-admin');
admin.initializeApp({
  credential: admin.credential.applicationDefault(),
  databaseURL: 'XXXXXXXXXXXX',
});

process.env.DEBUG = 'dialogflow:debug';

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 handleAge(agent) {
    const name = agent.parameters.Name;

    agent.add('Thank you... ' + name);

    return admin.database().ref('ageInfo').once("value").then((snapshot) => {
      var averageAge = snapshot.child(name).val().Age;
      agent.add(`Our recorded age is ` + averageAge);
    });
  }

  // Run the proper function handler based on the matched Dialogflow intent name
  let intentMap = new Map();
  intentMap.set('AskAge', handleAge);
  agent.handleRequest(intentMap);
});

我浏览了很多有关Github和StackOverFlow的文章,但是没有用。

1 个答案:

答案 0 :(得分:1)

我已解决上述问题。我在对话框流实现的 package.json 文件(内联编辑器)中更新了2个属性:

旧值:

"dialogflow-fulfillment": "0.3.0-beta.3",

"actions-on-google": "2.0.0-alpha.4"

新值:

"dialogflow-fulfillment": "^0.4.1",

"actions-on-google": "^2.1.3"