我创建了一个Dialogflow聊天机器人 . 我在其中创建了一个webhook,将其与firebase集成 . 当用户从内部对话框聊天框(聊天窗口)向机器人提问时,聊天机器人和webhook正常工作 .
我想创建自定义聊天窗口 . 所以我使用Angular 6创建了一个 . 使用dialogflow聊天代理集成了我的Angular前端 . 对于这个Angular聊天窗口对话框,chatbot可以正常处理静态问题,但是当我查询使用webhook的意图时,我在日志中遇到以下错误:
TypeError:无法在新的WebhookClient上读取V2Agent.processRequest_(/user_code/node_modules/dialogflow-fulfillment/src/v2-agent.js:108:86)中未定义的属性'source'(/ user_code / node_modules / dialogflow-fulfillment / src / dialogflow-fulfillment.js:201:17)在cloudFunction的exports.dialogflowFirebaseFulfillment.functions.https.onRequest(/user_code/index.js:14:17)(/ user_code / node_modules / firebase-functions / lib / providers /) https.js:26:47)/var/tmp/worker/worker.js:714:7 at /var/tmp/worker/worker.js:697:11 at _combinedTickCallback(internal / process / next_tick.js:73 :7)at process._tickDomainCallback(internal / process / next_tick.js:128:9)
下面是我的 index.js 文件(网络履行)
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);
});
package.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 回答
我得到了上述问题的解决方案 . 我更新了对话框实现(内联编辑器)的 package.json 文件中的2个属性:
Old Values :
New Values :