代码之家  ›  专栏  ›  技术社区  ›  Gaurav Jeswani

从外部聊天窗口调用Dialogflow Webhook时不工作

  •  0
  • Gaurav Jeswani  · 技术社区  · 6 年前

    我想创建我的自定义聊天窗口。所以我用Angular 6创建了一个。将Angular前端与dialogflow聊天代理集成。对于这个有角度的聊天窗口,dialogflow chatbot对于静态问题工作得很好,但是当我查询使用webhook的意图时,我在日志中得到以下错误:

    TypeError:无法读取未定义的属性“source” 在V2Agent.processRequest处(/user\u code/node\u modules/dialogflow fulfillment/src/v2 agent.js:108:86) 在新的WebhookClient(/user\u code/node\u modules/dialogflow fulfillment/src/dialogflow fulfillment.js:201:17) 在exports.dialogflowFirebaseFulfillment.functions.https.onRequest(/user\u code/index.js:14:17) 在cloudFunction(/user\u code/node\u modules/firebase functions/lib/providers/https.js:26:47) 在/var/tmp/worker/worker.js:714:7 在合并的tickCallback(internal/process/next-tick.js:73:7) 在进程中。\u tickDomainCallback(internal/process/next\u tick.js:128:9)

    下面是我的 文件(web实现)

    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);
    });
    

    包.json

    {
      "name": "dialogflowFirebaseFulfillment",
      "description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase",
      "version": "0.0.1",
      "private": true,
      "license": "Apache Version 2.0",
      "author": "Google Inc.",
      "engines": {
        "node": "~6.0"
      },
      "scripts": {
        "start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
        "deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
      },
      "dependencies": {
        "firebase-admin": "^4.2.1",
        "firebase-functions": "^0.5.7",
        "dialogflow": "^0.1.0",
        "dialogflow-fulfillment": "0.3.0-beta.3",
        "actions-on-google": "2.0.0-alpha.4"
      }
    }
    

    我读了那么多关于Github和StackOverFlow的文章,但没有一篇是有用的。

    1 回复  |  直到 6 年前
        1
  •  2
  •   Gaurav Jeswani    6 年前

    我得到了解决上述问题的决议。我在中更新了2个属性 包.json dialogflow实现文件(内联编辑器):

    "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"