开源项目 skill-sample-nodejs-howto
使用教程
1. 项目的目录结构及介绍
skill-sample-nodejs-howto/
├── lambda/
│ ├── custom/
│ │ ├── index.js
│ │ ├── package.json
│ │ ├── util.js
│ │ └── test/
│ └── event-samples/
├── models/
│ ├── en-US.json
│ └── es-ES.json
├── skill.json
└── README.md
-
lambda/: 包含项目的核心代码和测试文件。
- custom/: 包含主要的业务逻辑代码。
- index.js: 项目的入口文件,处理主要的业务逻辑。
- package.json: 项目的依赖管理文件。
- util.js: 包含一些通用的工具函数。
- test/: 包含项目的测试文件。
- event-samples/: 包含用于测试的事件样本。
- custom/: 包含主要的业务逻辑代码。
-
models/: 包含不同语言的语音模型文件。
- en-US.json: 英语(美国)的语音模型文件。
- es-ES.json: 西班牙语(西班牙)的语音模型文件。
-
skill.json: 项目的配置文件,定义了技能的基本信息和配置。
-
README.md: 项目的说明文档。
2. 项目的启动文件介绍
项目的启动文件是 lambda/custom/index.js
。该文件是整个项目的入口点,负责处理用户的请求并返回相应的响应。以下是 index.js
的主要内容:
const Alexa = require('ask-sdk-core');
const handlers = require('./handlers');
exports.handler = Alexa.SkillBuilders.custom()
.addRequestHandlers(
handlers.LaunchRequestHandler,
handlers.HelloWorldIntentHandler,
handlers.HelpIntentHandler,
handlers.CancelAndStopIntentHandler,
handlers.SessionEndedRequestHandler
)
.lambda();
- Alexa: 引入了
ask-sdk-core
库,用于构建 Alexa 技能。 - handlers: 引入了
handlers.js
文件,其中定义了各种请求处理程序。 - exports.handler: 定义了 Lambda 函数的处理程序,将不同的请求处理程序注册到技能中。
3. 项目的配置文件介绍
项目的配置文件是 skill.json
。该文件定义了技能的基本信息、意图、槽位等配置。以下是 skill.json
的部分内容:
{
"manifest": {
"publishingInformation": {
"locales": {
"en-US": {
"summary": "Sample Short Description",
"examplePhrases": [
"Alexa open hello world",
"Alexa tell hello world hello",
"Alexa ask hello world say hello"
],
"name": "helloWorld",
"description": "Sample Full Description"
}
},
"isAvailableWorldwide": true,
"testingInstructions": "Sample Testing Instructions.",
"category": "EDUCATION_AND_REFERENCE",
"distributionCountries": []
},
"apis": {
"custom": {}
},
"manifestVersion": "1.0"
}
}
- manifest: 包含技能的发布信息和 API 配置。
- publishingInformation: 包含技能的发布信息,如名称、描述、示例短语等。
- apis: 定义了技能的 API 配置。
- manifestVersion: 指定技能的清单版本。
通过以上配置,开发者可以定义技能的行为和功能,使其能够响应用户的请求并提供相应的服务。