官术网_书友最值得收藏!

Creating a Lambda to handle the request

To handle the intents inside our new Alexa Skill, we need to create a Lambda function. This will contain all of the logic we need to understand the intent and send a reply to the user.

To create a Lambda, we can use any of the methods described in Chapter 2, Getting Started with AWS and Amazon CLI, but we're going to be using our local development setup. Navigate to your base Lambda folder and create a new folder called hello-alexa-skill. Inside that folder, we need to create a new index.js file and open it to create our function.

To start, we need to require in the alexa-sdk, which makes creating the logic for Alexa a lot easier:

const Alexa = require('alexa-sdk');

Because we are requiring it, we also need to make sure that we have it installed. In the command-line interface, navigate into your hello-alexa-skill folder and run the npm init command. This process creates a package information and allows you to install other packages in the folder. You can set the values as you go through the setup or use the defaults by hitting Enter. Once you've finished the setup, you'll have a file called package.json, which contains the configuration for this folder.

To install a new package and add it to our package.json file, we can run the npm install --save package-name command. We want to install ask-sdk, so we need to run npm install --save ask-sdk. When this command runs, you'll see a new folder is created, called node_modules, which contains all of the code in the installed npm packages.

主站蜘蛛池模板: 中牟县| 巴彦县| 海原县| 旬邑县| 石阡县| 阜阳市| 陕西省| 广丰县| 香港 | 济南市| 岳阳县| 响水县| 息烽县| 宁化县| 乌兰浩特市| 炉霍县| 陇南市| 舞阳县| 台东县| 林州市| 杨浦区| 长沙市| 古丈县| 神池县| 宜春市| 惠安县| 平度市| 亚东县| 建昌县| 靖远县| 镇安县| 石泉县| 惠安县| 咸阳市| 扶沟县| 中宁县| 海盐县| 闻喜县| 额济纳旗| 甘德县| 皋兰县|