/alexa_tutorial

Here is the code and instructional content you need to create your first Alexa skill.

Primary LanguageJavaScript

ALEXA TUTORIAL

Here is the code and instructional content you need to create your first Alexa skill.

Prerequisites

  • An Amazon developer account.
  • An Amazon Web Services account.
  • AWS Lambda
  • Knowledge of Node.js and JSON.

For more information visit: https://developer.amazon.com/docs/ask-overviews/requirements-to-build-a-skill.html

Alexa skills

  • Intents: An intent represents an action that fulfils a user's spoken request. Intents can optionally have arguments called slots.
  • Sample utterances: A set of likely spoken phrases mapped to the intents. This should include as many representative phrases as possible.
  • AWS Lambda is a compute service that lets you run code without provisioning or managing servers. AWS Lambda executes your code only when needed and scales automatically, from a few requests per day to thousands per second. You pay only for the compute time you consume - there is no charge when your code is not running.

Table 1

Intent Sample utterances
FirstIntent * First intent
* Tell me about first intent
* Activate first intent
SecondIntent * Second intent
* Tell me about second intent
* Activate second intent
ThirdIntent * Third intent
* Tell me about third intent
* Activate third intent

Creating a new skill

To create your Alexa skill model, complete the following steps:

  1. Navigate to https://developer.amazon.com/home.html.
  2. Log on.
  3. Navigate to the Alexa tab and click Alexa Skills Kit.
  4. Click Create skill.
  5. Enter your skill's name in the Skill name field.
  6. Select Custom.
  7. Click Create skill.
  8. Select Start from scratch.
  9. Click Choose.

Creating an invocation name

When you say a skill's invocation name you begin an interaction with a particular custom skill. For example, if the invocation name is Chatter bot, users can say: "Alexa, ask Chatter bot."

  1. In the CUSTOM menu, navigate to Invocation.
  2. Enter your Skill Invocation Name.
  3. Click Save Model

Creating intents

You must create intents to represent a user's spoken request. To create your intents, complete the following steps:

  1. In the CUSTOM menu, navigate to Intents.
  2. Click Add.
  3. Click Add intent.
  4. Click Create custom intent.
  5. In the Create custom intent field enter the following name: FirstIntent.
  6. Fill in the sample utterances for FirstIntent listed in Table 1.
  7. Click Save Model.
  8. Repeat steps 1 - 7 for SecondIntent and ThirdIntent.
  9. Click Build Model.

Setting up your Endpoint

To set up your Endpoint to receive POST requests when a user interacts with your Alexa Skill, complete the following steps:

  1. Navigate to Service Endpoint Type and click AWS Lambda ARN.
  2. Navigate to Your Skill ID and copy it to your clipboard.
  3. Do not close your developer console.

Setting up Lambda

To set up your Lamda function, complete the following steps:

  1. Open a new tab and navigate to https://console.aws.amazon.com/.
  2. Navigate to the AWS Services tab and click Lambda.
  3. Click Create function.
  4. Select Author from scratch.
  5. Enter your Function name.
  6. In the Runtime drop-down menu, select Node.js 10.x.
  7. Click Create function.
  8. Click Add trigger and select Alexa Skills Kit from the drop-down menu.
  9. Add the Skill ID that you copied from the developer console.
  10. Click Add.
  11. Click Save.
  12. Copy the ARN number on the top right corner of your window.
  13. Navigate to the developer console in your browser tab.
  14. Enter the ARN number in the Default Region field.
  15. Click Save Endpoints.
  16. Navigate to AWS and click on your function name.
  17. In the Function code window, add the index.js and messageResponses.js files to your folder.
  18. Click Save.

Building your model

To build your model, complete the following steps:

  1. Navigate to the developer console.
  2. In your skill, navigate to the CUSTOM menu and click Intents.
  3. Click Build Model.

Testing your new Intent

  1. In the Amazon developer console navigate to the Test tab.
  2. If the test section is grayed out, navigate to Test is disabled for this skill click Off and select Development.
  3. Where it says Type or click and hold the mic type Alexa ask + (Your skill name) and press Enter, then type “Ask (Your skill name) to (utterance)”.
  4. If the outputs are: "This is your invocation message" and "This is your (intent)" you are successful.