使用无服务器创建 dialogflow v2 项目
creating dialogflow v2 project with serverless
尝试 运行 新的 AWS/Serverless/Dialogflow 项目时遇到问题。我确信这很简单,我只是没有看到。
步骤
创建初始项目使用:serverless create --template aws-nodejs-typescript
将handler.js移动到src/并更新了serverless.yml
- 已安装 npm
actions-on-google
遵循 actions-on-google 示例并更新了 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 项目
{
"compilerOptions": {
"sourceMap": true,
"target": "es6",
"allowJs": true,
"module": "commonjs"
},
"exclude": [
"node_modules"
],
"include": [
"./src/**/*"
]
}
为了完整起见,这里是我的serverless.yml。 (我手动创建了 API 网关,因为无服务器创建了 lambda-proxy,我没有查看其他配置。)
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 时,我不断收到
(node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot convert undefined or null to object
P.S。示例源选择使用猫!
终于有时间回到这个问题并遇到这个 git issue。
本质上dialogflow
实例需要被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}`
});
});
};
尝试 运行 新的 AWS/Serverless/Dialogflow 项目时遇到问题。我确信这很简单,我只是没有看到。
步骤
创建初始项目使用:
serverless create --template aws-nodejs-typescript
将handler.js移动到src/并更新了serverless.yml
- 已安装 npm
actions-on-google
遵循 actions-on-google 示例并更新了 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 项目
{ "compilerOptions": { "sourceMap": true, "target": "es6", "allowJs": true, "module": "commonjs" }, "exclude": [ "node_modules" ], "include": [ "./src/**/*" ] }
为了完整起见,这里是我的serverless.yml。 (我手动创建了 API 网关,因为无服务器创建了 lambda-proxy,我没有查看其他配置。)
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 时,我不断收到
(node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot convert undefined or null to object
P.S。示例源选择使用猫!
终于有时间回到这个问题并遇到这个 git issue。
本质上dialogflow
实例需要被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}`
});
});
};