使用无服务器创建dialogflow v2项目 [英] creating dialogflow v2 project with serverless
问题描述
尝试运行新的AWS/Serverless/Dialogflow项目时出现问题.我确信这只是我看不到的简单事情.
Having issues trying to run a new AWS/Serverless/Dialogflow project. I am sure it is something simple that I am just not seeing.
-
使用以下内容创建初始项目:
serverless create --template aws-nodejs-typescript
将 handler.js 移至 src/&更新了 serverless.yml
moved handler.js to src/ & updated serverless.yml
按照 google-actions 的示例进行更新 src/handler.js
import { dialogflow, Image } from 'actions-on-google';
const app = dialogflow({debug: true});
app.intent("test.intent", (conv) => {
conv.ask("Hi, how is it going?");
conv.ask("Here is a picture of a cat!");
conv.ask(new Image({
url: "https://developers.google.com/web/fundamentals/accessibility/semantics-builtin/imgs/160204193356-01-cat-500.jpg",
alt: "A fluffy cat!"
}));
});
exports.fulfillment = app;
还更新了 tsconfig.json 以匹配另一个Typescript项目
also updated tsconfig.json to match another Typescript project
{
"compilerOptions": {
"sourceMap": true,
"target": "es6",
"allowJs": true,
"module": "commonjs"
},
"exclude": [
"node_modules"
],
"include": [
"./src/**/*"
]
}
为了完整起见,这是我的 serverless.yml . (我手动创建了API网关,因为无服务器创建了lambda-proxy,并且我没有研究其他配置.)
For thoroughness here is my serverless.yml. (I manually created the API Gateway because serverless creates the lambda-proxy and I haven't looked into the other config.)
service:
name: test-lambda
# Add the serverless-webpack plugin
plugins:
- serverless-webpack
provider:
name: aws
runtime: nodejs6.10
functions:
fulfillment:
handler: src/handler.fulfillment
# events:
# - http:
# method: get
# path: hello
错误
项目成功编译并部署,但是当调用lambda时,我一直在获取
Error
The project compiles and deploys successfully but when the lambda is called I keep getting
(node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot convert undefined or null to object
P.S.示例源选择了使用猫!
P.S. the example source chose to use a cat!
推荐答案
Finally had some time to circle back to this problem and came across this git issue.
基本上,dialogflow
实例需要由lambda封装.
Essentially the dialogflow
instance needed to be encapsulated by the lambda.
exports.fulfillment = function(event, context, callback) {
app.handler(event, {})
.then((res) => {
if (res.status != 200) {
callback(null, {
"fulfillmentText": `I got status code: ${res.status}`
});
} else {
callback(null, res.body);
}
}).catch((e) => {
callback(null, {
"fulfillmentText": `There was an error\n${e}`
});
});
};
这篇关于使用无服务器创建dialogflow v2项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!