Alexa Hello World 技能项目教程

Alexa Hello World 技能项目教程

skill-sample-nodejs-hello-world项目地址:https://gitcode.com/gh_mirrors/ski/skill-sample-nodejs-hello-world

1. 项目的目录结构及介绍

skill-sample-nodejs-hello-world/
├── ask/
│   ├── github/
│   └── hooks/
├── instructions/
├── lambda/
│   └── custom/
├── models/
├── .gitignore
├── LICENSE.txt
├── README.md
└── skill.json
  • ask/: 包含与 Alexa Skills Kit (ASK) CLI 相关的文件和配置。
  • instructions/: 包含项目的说明文档。
  • lambda/custom/: 包含技能的后端逻辑代码。
  • models/: 包含语音交互模型的定义。
  • .gitignore: 指定 Git 版本控制系统忽略的文件和目录。
  • LICENSE.txt: 项目的许可证文件。
  • README.md: 项目的介绍和使用说明。
  • skill.json: 技能的配置文件。

2. 项目的启动文件介绍

项目的启动文件位于 lambda/custom/ 目录下,通常是 index.jshandler.js。这个文件包含了技能的主要逻辑和处理函数。

// lambda/custom/index.js

const Alexa = require('ask-sdk-core');

const LaunchRequestHandler = {
  canHandle(handlerInput) {
    return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest';
  },
  handle(handlerInput) {
    const speakOutput = '欢迎使用 Hello World 技能!';
    return handlerInput.responseBuilder
      .speak(speakOutput)
      .getResponse();
  }
};

const HelpIntentHandler = {
  canHandle(handlerInput) {
    return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
      && Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.HelpIntent';
  },
  handle(handlerInput) {
    const speakOutput = '你可以问我你好吗?';
    return handlerInput.responseBuilder
      .speak(speakOutput)
      .reprompt(speakOutput)
      .getResponse();
  }
};

const skillBuilder = Alexa.SkillBuilders.custom();

exports.handler = skillBuilder
  .addRequestHandlers(
    LaunchRequestHandler,
    HelpIntentHandler
  )
  .lambda();

3. 项目的配置文件介绍

项目的配置文件是 skill.json,它定义了技能的基本信息和配置。

{
  "manifest": {
    "publishingInformation": {
      "locales": {
        "en-US": {
          "name": "Hello World Skill",
          "summary": "Sample Short Description",
          "description": "Sample Full Description",
          "examplePhrases": [
            "Alexa, open hello world",
            "Alexa, ask hello world to say hello",
            "Alexa, ask hello world to introduce itself"
          ],
          "keywords": [
            "sample",
            "example"
          ]
        }
      },
      "isAvailableWorldwide": true,
      "testingInstructions": "Sample Testing Instructions.",
      "category": "EDUCATION_AND_REFERENCE",
      "distributionCountries": []
    },
    "apis": {
      "custom": {}
    },
    "permissions": [],
    "privacyAndCompliance": {
      "allowsPurchases": false,
      "isExportCompliant": true,
      "containsAds": false,
      "isChildDirected": false,
      "usesPersonalInfo": false
    }
  }
}
  • publishingInformation: 包含技能的发布信息,如名称、描述、示例短语等。
  • apis: 定义技能使用的 API。
  • permissions: 定义技能需要的权限。
  • privacyAndCompliance: 包含技能的隐私和合规信息。

skill-sample-nodejs-hello-world项目地址:https://gitcode.com/gh_mirrors/ski/skill-sample-nodejs-hello-world

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

郁虹宝Lucille

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值