我正在使用对话流程实现,Google上的操作来创建聊天机器人,并将其托管在AWS Lambda中。我正在尝试请求用户权限,但是当我尝试添加一些Google动作(例如权限)时遇到问题。
我尝试了对话框流程示例在这里所做的事情:
https://github.com/dialogflow/fulfillment-actions-library-nodejs/blob/master/functions/index.js
但是,由于我使用的是AWS Lambda,因此我没有遵循确切的代码,也许我缺少了一些东西。
router.post('/', (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 welcome(agent) {
agent.add(`Welcome to the webhook`);
}
function fallback(agent) {
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}
function locationIntent(agent) {
let conv = agent.conv();
conv.ask(new Permission({
context: 'To give results in your area',
permissions: 'DEVICE_PRECISE_LOCATION',
}))
agent.add(conv);
}
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
if (agent.requestSource === agent.ACTIONS_ON_GOOGLE) {
intentMap.set('location', locationIntent);
} else {
intentMap.set(null, other);
}
agent.handleRequest(intentMap);
});
app.use('/', router);
module.exports = app;
我已经用过了
const { WebhookClient} = require('dialogflow-fulfillment');
const { dialogflow,
SimpleResponse,
BasicCard,
Suggestions,
Permission,
UpdatePermission,
RegisterUpdate,
Carousel,
} = require('actions-on-google');
我的依赖项是:
"dependencies": {
"actions-on-google": "^2.5.0",
"aws-serverless-express": "^3.3.5",
"body-parser": "^1.18.3",
"compression": "^1.7.3",
"cors": "^2.8.5",
"dialogflow": "^4.0.3",
"dialogflow-fulfillment": "^0.6.1",
"express": "^4.16.4",
"googleapis": "^27.0.0"
}
我从dialogflow博客的这篇文章中获得许可意图: https://blog.dialogflow.com/post/fulfillment-library-beta/
我检查了aws-lambda中的日志,发现了这一点:
TypeError:无法在读取未定义的属性'forEach' V2Agent.addActionsOnGoogle _
这发生在我做agent.add(conv)
时。如果我这样做,agent.add("This is location permission intent");
可以工作。我希望获得许可,以后再用于一些坐标
我正在使用节点v10.15.0
aws-lambda中的Stracktrace:
2019-01-24T12:42:52.013Z 2531e964-1f94-4f41-997a-a4ef14cb55da TypeError: Cannot read property 'forEach' of undefined
at V2Agent.addActionsOnGoogle_ (/var/task/node_modules/dialogflow-fulfillment/src/v2-agent.js:313:29)
at WebhookClient.addResponse_ (/var/task/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:269:19)
at WebhookClient.add (/var/task/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:245:12)
at locationIntent (/var/task/app.js:75:11)
at WebhookClient.handleRequest (/var/task/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:303:44)
at router.post (/var/task/app.js:156:9)
at Layer.handle [as handle_request] (/var/task/node_modules/express/lib/router/layer.js:95:5)
at next (/var/task/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/var/task/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/var/task/node_modules/express/lib/router/layer.js:95:5)
注意:我已经尝试使用Google上的其他元素,例如轮播,但失败了。这使我觉得agent.add
或conv
答案 0 :(得分:0)
这强烈表明,尽管列出了相关性,但您使用的是dialogflow-fulfillment
库的旧版本。确保您安装了最新版本
npm update