├── .gitignore
├── .ask
└── config
├── lambda
├── custom
│ ├── package.json
│ ├── package-lock.json
│ └── index.js
└── data
│ ├── facts-en-GB.js
│ ├── facts-en-US.js
│ └── facts-de-DE.js
├── InteractionModel.json
├── models
└── en-US.json
├── skill.json
├── instructions
├── 0-intro.md
├── 5-customization.md
├── 3-connect-vui-to-code.md
├── 2-lambda-function.md
├── 4-testing.md
├── 1-voice-user-interface.md
└── 6-publication.md
├── README.md
└── LICENSE.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | /lambda/custom/node_modules
--------------------------------------------------------------------------------
/.ask/config:
--------------------------------------------------------------------------------
1 | {
2 | "deploy_settings": {
3 | "default": {
4 | "skill_id": "",
5 | "was_cloned": false,
6 | "merge": {
7 | "skillManifest": {
8 | "apis": {
9 | "custom": {
10 | "endpoint": {
11 | "uri": "what_name_you_want_to_name_the_lambda"
12 | }
13 | }
14 | }
15 | }
16 | }
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/lambda/custom/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "skill-sample-nodejs-fact-i18n",
3 | "version": "1.0.0",
4 | "description": "I18n version of fact skill.",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "keywords": [
10 | "alexa",
11 | "skill",
12 | "fact"
13 | ],
14 | "author": "Amazon.com",
15 | "license": "Apache-2.0",
16 | "dependencies": {
17 | "alexa-sdk": "^1.0.12"
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/InteractionModel.json:
--------------------------------------------------------------------------------
1 | {
2 | "intents": [
3 | {
4 | "name": "AMAZON.CancelIntent",
5 | "samples": []
6 | },
7 | {
8 | "name": "AMAZON.HelpIntent",
9 | "samples": []
10 | },
11 | {
12 | "name": "AMAZON.StopIntent",
13 | "samples": []
14 | },
15 | {
16 | "name": "GetNewFactIntent",
17 | "samples": [
18 | "a fact",
19 | "a space fact",
20 | "tell me a fact",
21 | "tell me a space fact",
22 | "give me a fact",
23 | "give me a space fact",
24 | "tell me trivia",
25 | "tell me a space trivia",
26 | "give me trivia",
27 | "give me a space trivia",
28 | "give me some information",
29 | "give me some space information",
30 | "tell me something",
31 | "give me something"
32 | ],
33 | "slots": []
34 | }
35 | ]
36 | }
37 |
--------------------------------------------------------------------------------
/models/en-US.json:
--------------------------------------------------------------------------------
1 | {
2 | "interactionModel": {
3 | "languageModel": {
4 | "invocationName": "space facts",
5 | "intents": [
6 | {
7 | "name": "AMAZON.CancelIntent",
8 | "samples": []
9 | },
10 | {
11 | "name": "AMAZON.HelpIntent",
12 | "samples": []
13 | },
14 | {
15 | "name": "AMAZON.StopIntent",
16 | "samples": []
17 | },
18 | {
19 | "name": "GetNewFactIntent",
20 | "samples": [
21 | "a fact",
22 | "a space fact",
23 | "tell me a fact",
24 | "tell me a space fact",
25 | "give me a fact",
26 | "give me a space fact",
27 | "tell me trivia",
28 | "tell me a space trivia",
29 | "give me trivia",
30 | "give me a space trivia",
31 | "give me some information",
32 | "give me some space information",
33 | "tell me something",
34 | "give me something"
35 | ],
36 | "slots": []
37 | }
38 | ]
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/lambda/data/facts-en-GB.js:
--------------------------------------------------------------------------------
1 | var data = [
2 | "A year on Mercury is just 88 days long.",
3 | "Despite being farther from the Sun, Venus experiences higher temperatures than Mercury.",
4 | "Venus rotates counter-clockwise, possibly because of a collision in the past with an asteroid.",
5 | "On Mars, the Sun appears about half the size as it does on Earth.",
6 | "Earth is the only planet not named after a god.",
7 | "Jupiter has the shortest day of all the planets.",
8 | "The Milky Way galaxy will collide with the Andromeda Galaxy in about 5 billion years.",
9 | "The Sun contains 99.86% of the mass in the Solar System.",
10 | "The Sun is an almost perfect sphere.",
11 | "A total solar eclipse can happen once every 1 to 2 years. This makes them a rare event.",
12 | "Saturn radiates two and a half times more energy into space than it receives from the sun.",
13 | "The temperature inside the Sun can reach 15 million degrees Celsius.",
14 | "The Moon is moving approximately 3.8 cm away from our planet every year."
15 | ];
16 |
17 | var SKILL_NAME = "British Space Facts";
18 | var GET_FACT_MESSAGE = "Here's your fact: ";
19 | var HELP_MESSAGE = "You can say tell me a space fact, or, you can say exit... What can I help you with?";
20 | var HELP_REPROMPT = "What can I help you with?";
21 | var STOP_MESSAGE = "Goodbye!";
--------------------------------------------------------------------------------
/lambda/data/facts-en-US.js:
--------------------------------------------------------------------------------
1 | var data = [
2 | "A year on Mercury is just 88 days long.",
3 | "Despite being farther from the Sun, Venus experiences higher temperatures than Mercury.",
4 | "Venus rotates counter-clockwise, possibly because of a collision in the past with an asteroid.",
5 | "On Mars, the Sun appears about half the size as it does on Earth.",
6 | "Earth is the only planet not named after a god.",
7 | "Jupiter has the shortest day of all the planets.",
8 | "The Milky Way galaxy will collide with the Andromeda Galaxy in about 5 billion years.",
9 | "The Sun contains 99.86% of the mass in the Solar System.",
10 | "The Sun is an almost perfect sphere.",
11 | "A total solar eclipse can happen once every 1 to 2 years. This makes them a rare event.",
12 | "Saturn radiates two and a half times more energy into space than it receives from the sun.",
13 | "The temperature inside the Sun can reach 15 million degrees Celsius.",
14 | "The Moon is moving approximately 3.8 cm away from our planet every year."
15 | ];
16 |
17 | var SKILL_NAME = "American Space Facts";
18 | var GET_FACT_MESSAGE = "Here's your fact: ";
19 | var HELP_MESSAGE = "You can say tell me a space fact, or, you can say exit... What can I help you with?";
20 | var HELP_REPROMPT = "What can I help you with?";
21 | var STOP_MESSAGE = "Goodbye!";
--------------------------------------------------------------------------------
/lambda/data/facts-de-DE.js:
--------------------------------------------------------------------------------
1 | var data = [
2 | "Ein Jahr dauert auf dem Merkur nur 88 Tage.",
3 | "Die Venus ist zwar weiter von der Sonne entfernt, hat aber höhere Temperaturen als Merkur.",
4 | "Venus dreht sich entgegen dem Uhrzeigersinn, möglicherweise aufgrund eines früheren Zusammenstoßes mit einem Asteroiden.",
5 | "Auf dem Mars erscheint die Sonne nur halb so groß wie auf der Erde.",
6 | "Die Erde ist der einzige Planet, der nicht nach einem Gott benannt ist.",
7 | "Jupiter hat den kürzesten Tag aller Planeten.",
8 | "Die Milchstraßengalaxis wird in etwa 5 Milliarden Jahren mit der Andromeda-Galaxis zusammenstoßen.",
9 | "Die Sonne macht rund 99,86 % der Masse im Sonnensystem aus.",
10 | "Die Sonne ist eine fast perfekte Kugel.",
11 | "Eine Sonnenfinsternis kann alle ein bis zwei Jahre eintreten. Sie ist daher ein seltenes Ereignis.",
12 | "Der Saturn strahlt zweieinhalb mal mehr Energie in den Weltraum aus als er von der Sonne erhält.",
13 | "Die Temperatur in der Sonne kann 15 Millionen Grad Celsius erreichen.",
14 | "Der Mond entfernt sich von unserem Planeten etwa 3,8 cm pro Jahr."
15 | ];
16 |
17 | var SKILL_NAME = "Weltraumwissen auf Deutsch";
18 | var GET_FACT_MESSAGE = "Hier sind deine Fakten: ";
19 | var HELP_MESSAGE = "Du kannst sagen, „Nenne mir einen Fakt über den Weltraum“, oder du kannst „Beenden“ sagen... Wie kann ich dir helfen?";
20 | var HELP_REPROMPT = "Wie kann ich dir helfen?";
21 | var STOP_MESSAGE = "Auf Wiedersehen!";
22 |
23 |
--------------------------------------------------------------------------------
/skill.json:
--------------------------------------------------------------------------------
1 | {
2 | "skillManifest": {
3 | "publishingInformation": {
4 | "locales": {
5 | "en-US": {
6 | "summary": "Learn fun facts about space.",
7 | "examplePhrases": [
8 | "Alexa open space facts",
9 | "Alexa ask space facts for a fact",
10 | "Alexa tell space facts to tell me trivia"
11 | ],
12 | "keywords": [
13 | "space",
14 | "facts",
15 | "trivia"
16 | ],
17 | "name": "Space Facts",
18 | "description": "Ask for Space Facts, and learn about what really matters, like dark matter.\n\nSpace Facts provides fun the whole family can enjoy and is guaranteed to make you smarter.\n\nTo start, just say \"Alexa, launch Space Facts\" or \"Alexa, open Space Facts\" to get a fact\".\n\nAt anytime, you can stop by saying \"Alexa, stop\""
19 | },
20 | "en-GB": {
21 | "summary": "Listen to My Radio, less bla bla bla, more la la la.",
22 | "examplePhrases": [
23 | "Alexa, open My Radio",
24 | "Alexa, play My Radio",
25 | "Alexa, ask My Radio to play"
26 | ],
27 | "keywords": [
28 | "music",
29 | "streaming",
30 | "radio"
31 | ],
32 | "name": "My Radio",
33 | "description": "Listen to My Radio, with less bla bla bla, and more la la la.\n\nMy Radio provides a high quality sound 24/7 with the best music.\n\nTo start, just say \"Alexa, launch My Radio\" or \"Alexa, play my radio\" to start the radio\".\n\nAt anytime, you can stop the radio by saying \"Alexa, stop\""
34 | }
35 | },
36 | "isAvailableWorldwide": true,
37 | "testingInstructions": "Sample Testing Instructions.",
38 | "category": "EDUCATION_AND_REFERENCE",
39 | "distributionCountries": []
40 | },
41 | "apis": {
42 | "custom": {
43 | "endpoint": {
44 | "sourceDir": "lambda/custom"
45 | }
46 | }
47 | },
48 | "manifestVersion": "1.0"
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/instructions/0-intro.md:
--------------------------------------------------------------------------------
1 | # Build An Alexa Fact Skill
2 |
3 |
4 | [](1-voice-user-interface.md)[](2-lambda-function.md)[](3-connect-vui-to-code.md)[](4-testing.md)[](5-customization.md)[](6-publication.md)
5 |
6 | ## What You Will Learn
7 | * AWS Lambda
8 | * Alexa Skills Kit (ASK)
9 | * Skill Builder
10 | * Voice User Interface (VUI) Design
11 | * Skill Certification
12 |
13 | ## What You Will Need
14 | * [Amazon Developer Portal Account](http://developer.amazon.com)
15 | * [Amazon Web Services Account](http://aws.amazon.com/)
16 | * The sample code on [GitHub](https://github.com/alexa/skill-sample-nodejs-fact).
17 | * Simple graphical editing tool
18 | * At least 25 facts about your favorite topic.
19 |
20 | ## What Your Skill Will Do
21 | A fact skill for Alexa is a "Hello, World" example. You provide a list of interesting facts about a topic, and Alexa will read one of those facts to your user when they start your skill. The purpose of building this skill is to teach you how the different pieces of the Alexa development process fit together, while still producing an interesting, useful skill that others can enjoy.
22 |
23 | This Alexa skill template helps you create your first fact skill. Your users will be able to say things like:
24 |
25 | * "Alexa, ask Superhero Facts for a new fact."
26 | * "Alexa, start Baseball Facts."
27 | * "Alexa, ask Titanic Facts to give me another fact."
28 |
29 | Alexa will respond to all of these requests with responses like these:
30 |
31 | * "Here's your superhero fact: Iron Man's armor used to include roller skates."
32 | * "Here's your baseball fact: Ralph Kiner is the only player ever to lead the league in homers for seven years in a row — his first seven years as a major league player."
33 | * "Here's your Titanic fact: The ship burned around 600 tons of coal a day – hand shoveled into its furnaces by a team of 176 men. Almost 100 tons of ash were ejected into the sea each day."
34 |
35 | If you would like to see an example of this skill in action, you can enable the [Gloucester Facts](https://www.amazon.com/Robert-McCauley-Gloucester-Facts/dp/B01I5MOIA2/) from the [Alexa Skill Store](http://amazon.com/skills).
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/instructions/5-customization.md:
--------------------------------------------------------------------------------
1 | # Build An Alexa Fact Skill
2 | [](./1-voice-user-interface.md)[](./2-lambda-function.md)[](./3-connect-vui-to-code.md)[](./4-testing.md)[](./5-customization.md)[](./6-publication.md)
3 |
4 | ## Customize the Skill to be Yours
5 |
6 | At this point, you should have a working copy of our Fact skill. In order to make it your own, you will need to customize it with data and responses that you create. Here are the things you will need to change:
7 |
8 | 1. **New data.** You will need to provide a set of facts for your topic. We recommend a minimum of 25, but a total closer to 100 offers a better experience.
9 |
10 | 1. **Open a copy of index.js.** If you haven't already downloaded the code for this project, [you can find a copy of index.js here on GitHub](https://github.com/alexa/skill-sample-nodejs-fact/blob/en-US/lambda/custom/index.js). You can use a simple, lightweight code editor like [Atom](http://atom.io), [Sublime Text](http://sublimetext.com), or [VSCode](http://code.visualstudio.com), but you also have the option to edit the code directly in your Lambda function.
11 |
12 | 2. **Search for the comment "TODO: Replace this data with your own."** This is the data for our skill. You can see that it is a simple list of facts.
13 |
14 | 3. **When you have replaced the data in index.js, copy the contents of your file to your Lambda function.** This should be as simple as copying the text, and pasting it into the code box for your Lambda.
15 |
16 |
17 |
18 | 2. **New sentences to respond to your users.** There are several sentences and responses that you will want to customize for your skill.
19 |
20 | 1. **Go back to your copy of [index.js]((https://github.com/alexa/skill-sample-nodejs-fact/blob/en-US/lambda/custom/index.js)).**
21 |
22 | 2. **Look for the comment "TODO: The items below this comment need your attention."** This is the beginning of the section where you need to customize several text strings for your skill.
23 |
24 | 3. **Continue through index.js until you reach the bottom of the file.** This will ensure that you cover each of the values that you need to update.
25 |
26 | 3. **New language.** If you are creating this skill for another language other than English, you will need to make sure Alexa's responses are also in that language.
27 |
28 | * For example, if you are creating your skill in German, every single response that Alexa makes has to be in German. You can't use English responses or your skill will fail certification.
29 |
30 | 4. **Once you have made the updates listed on this page, you can click "Next" to move on to Publishing and Certification of your skill.**
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/instructions/3-connect-vui-to-code.md:
--------------------------------------------------------------------------------
1 | # Build An Alexa Fact Skill
2 | [](./1-voice-user-interface.md)[](./2-lambda-function.md)[](./3-connect-vui-to-code.md)[](./4-testing.md)[](./5-customization.md)[](./6-publication.md)
3 |
4 | ## Connecting Your Voice User Interface To Your Lambda Function
5 |
6 | On [page #1](./1-voice-user-interface.md) of this guide, we created a voice user interface for the intents and utterances we expect from our users. On [page #2](./2-lambda-function.md), we created a Lambda function that contains all of our logic for the skill. On this page, we need to connect those two pieces together.
7 |
8 | 1. **Go back to the [Amazon Developer Portal](https://developer.amazon.com/edw/home.html#/skills/list) and select your skill from the list.** You may still have a browser tab open if you started at the beginning of this tutorial.
9 |
10 | 2. **Open the "Configuration" tab on the left side.**
11 |
12 |
13 |
14 | 3. **Select the "AWS Lambda ARN" option for your endpoint.** You have the ability to host your code anywhere that you would like, but for the purposes of simplicity and frugality, we are using AWS Lambda. ([Read more about Hosting Your Own Custom Skill Web Service](https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/developing-an-alexa-skill-as-a-web-service).) With the AWS Free Tier, you get 1,000,000 free requests per month, up to 3.2 million seconds of compute time per month. Learn more at https://aws.amazon.com/free/. In addition, Amazon now offers [AWS Promotional Credits for developers who have live Alexa skills that incur costs on AWS related to those skills](https://developer.amazon.com/alexa-skills-kit/alexa-aws-credits).
15 |
16 |
17 |
18 | 4. **Select "North America" or "Europe" as your geographical region.** IMPORTANT: Make sure you select the same region that you created your Lambda in. Remember, Alexa skills using AWS Lambda can only run in N. Virginia (North America) and Ireland (Europe).
19 |
20 |
21 |
22 | 5. **Paste your Lambda's ARN (Amazon Resource Name) into the textbox provided.** It should look similar to the screenshot above.
23 |
24 | 6. **Leave "Account Linking" set to "No."** For this skill, we won't be using Account Linking, but you can learn more about [Linking an Alexa User with a User in Your System.](https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/linking-an-alexa-user-with-a-user-in-your-system)
25 |
26 | 7. **Click the "Next" button to continue to page #4 of this guide.**
27 |
28 | [](./4-testing.md)
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/lambda/custom/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "skill-sample-nodejs-fact-i18n",
3 | "version": "1.0.0",
4 | "lockfileVersion": 1,
5 | "dependencies": {
6 | "alexa-sdk": {
7 | "version": "1.0.12",
8 | "resolved": "https://registry.npmjs.org/alexa-sdk/-/alexa-sdk-1.0.12.tgz",
9 | "integrity": "sha1-9+OBOPzVehfIikiVpVf/Tr2vuck="
10 | },
11 | "aws-sdk": {
12 | "version": "2.101.0",
13 | "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.101.0.tgz",
14 | "integrity": "sha1-ElLDZLhA66GuC4zYwazPeL+hTZY="
15 | },
16 | "base64-js": {
17 | "version": "1.2.1",
18 | "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.2.1.tgz",
19 | "integrity": "sha512-dwVUVIXsBZXwTuwnXI9RK8sBmgq09NDHzyR9SAph9eqk76gKK2JSQmZARC2zRC81JC2QTtxD0ARU5qTS25gIGw=="
20 | },
21 | "buffer": {
22 | "version": "4.9.1",
23 | "resolved": "https://registry.npmjs.org/buffer/-/buffer-4.9.1.tgz",
24 | "integrity": "sha1-bRu2AbB6TvztlwlBMgkwJ8lbwpg="
25 | },
26 | "crypto-browserify": {
27 | "version": "1.0.9",
28 | "resolved": "https://registry.npmjs.org/crypto-browserify/-/crypto-browserify-1.0.9.tgz",
29 | "integrity": "sha1-zFRJaF37hesRyYKKzHy4erW7/MA="
30 | },
31 | "events": {
32 | "version": "1.1.1",
33 | "resolved": "https://registry.npmjs.org/events/-/events-1.1.1.tgz",
34 | "integrity": "sha1-nr23Y1rQmccNzEwqH1AEKI6L2SQ="
35 | },
36 | "i18next": {
37 | "version": "3.5.2",
38 | "resolved": "https://registry.npmjs.org/i18next/-/i18next-3.5.2.tgz",
39 | "integrity": "sha1-kwOQ1cMYzqpIWLUt0OQOayA/n0E="
40 | },
41 | "i18next-sprintf-postprocessor": {
42 | "version": "0.2.2",
43 | "resolved": "https://registry.npmjs.org/i18next-sprintf-postprocessor/-/i18next-sprintf-postprocessor-0.2.2.tgz",
44 | "integrity": "sha1-LkCfEENXk4Jpi2otpwzapVHWfqQ="
45 | },
46 | "ieee754": {
47 | "version": "1.1.8",
48 | "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.8.tgz",
49 | "integrity": "sha1-vjPUCsEO8ZJnAfbwii2G+/0a0+Q="
50 | },
51 | "isarray": {
52 | "version": "1.0.0",
53 | "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
54 | "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
55 | },
56 | "jmespath": {
57 | "version": "0.15.0",
58 | "resolved": "https://registry.npmjs.org/jmespath/-/jmespath-0.15.0.tgz",
59 | "integrity": "sha1-o/Iiqarp+Wb10nx5ZRDigJF2Qhc="
60 | },
61 | "lodash": {
62 | "version": "4.17.4",
63 | "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz",
64 | "integrity": "sha1-eCA6TRwyiuHYbcpkYONptX9AVa4="
65 | },
66 | "punycode": {
67 | "version": "1.3.2",
68 | "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.3.2.tgz",
69 | "integrity": "sha1-llOgNvt8HuQjQvIyXM7v6jkmxI0="
70 | },
71 | "querystring": {
72 | "version": "0.2.0",
73 | "resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz",
74 | "integrity": "sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA="
75 | },
76 | "sax": {
77 | "version": "1.2.1",
78 | "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.1.tgz",
79 | "integrity": "sha1-e45lYZCyKOgaZq6nSEgNgozS03o="
80 | },
81 | "url": {
82 | "version": "0.10.3",
83 | "resolved": "https://registry.npmjs.org/url/-/url-0.10.3.tgz",
84 | "integrity": "sha1-Ah5NnHcF8hu/N9A861h2dAJ3TGQ="
85 | },
86 | "uuid": {
87 | "version": "3.0.1",
88 | "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.0.1.tgz",
89 | "integrity": "sha1-ZUS7ot/ajBzxfmKaOjBeK7H+5sE="
90 | },
91 | "xml2js": {
92 | "version": "0.4.17",
93 | "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.17.tgz",
94 | "integrity": "sha1-F76T6q4/O3eTWceVtBlwWogX6Gg="
95 | },
96 | "xmlbuilder": {
97 | "version": "4.2.1",
98 | "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-4.2.1.tgz",
99 | "integrity": "sha1-qlijBBoGb5DqoWwvU4n/GfP0YaU="
100 | }
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/lambda/custom/index.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable func-names */
2 | /* eslint quote-props: ["error", "consistent"]*/
3 | /**
4 | * This sample demonstrates a simple skill built with the Amazon Alexa Skills
5 | * nodejs skill development kit.
6 | * This sample supports multiple lauguages. (en-US, en-GB, de-DE).
7 | * The Intent Schema, Custom Slots and Sample Utterances for this skill, as well
8 | * as testing instructions are located at https://github.com/alexa/skill-sample-nodejs-fact
9 | **/
10 |
11 | 'use strict';
12 | const Alexa = require('alexa-sdk');
13 |
14 | //=========================================================================================================================================
15 | //TODO: The items below this comment need your attention.
16 | //=========================================================================================================================================
17 |
18 | //Replace with your app ID (OPTIONAL). You can find this value at the top of your skill's page on http://developer.amazon.com.
19 | //Make sure to enclose your value in quotes, like this: const APP_ID = 'amzn1.ask.skill.bb4045e6-b3e8-4133-b650-72923c5980f1';
20 | const APP_ID = undefined;
21 |
22 | const SKILL_NAME = 'Space Facts';
23 | const GET_FACT_MESSAGE = "Here's your fact: ";
24 | const HELP_MESSAGE = 'You can say tell me a space fact, or, you can say exit... What can I help you with?';
25 | const HELP_REPROMPT = 'What can I help you with?';
26 | const STOP_MESSAGE = 'Goodbye!';
27 |
28 | //=========================================================================================================================================
29 | //TODO: Replace this data with your own. You can find translations of this data at http://github.com/alexa/skill-sample-node-js-fact/lambda/data
30 | //=========================================================================================================================================
31 | const data = [
32 | 'A year on Mercury is just 88 days long.',
33 | 'Despite being farther from the Sun, Venus experiences higher temperatures than Mercury.',
34 | 'Venus rotates counter-clockwise, possibly because of a collision in the past with an asteroid.',
35 | 'On Mars, the Sun appears about half the size as it does on Earth.',
36 | 'Earth is the only planet not named after a god.',
37 | 'Jupiter has the shortest day of all the planets.',
38 | 'The Milky Way galaxy will collide with the Andromeda Galaxy in about 5 billion years.',
39 | 'The Sun contains 99.86% of the mass in the Solar System.',
40 | 'The Sun is an almost perfect sphere.',
41 | 'A total solar eclipse can happen once every 1 to 2 years. This makes them a rare event.',
42 | 'Saturn radiates two and a half times more energy into space than it receives from the sun.',
43 | 'The temperature inside the Sun can reach 15 million degrees Celsius.',
44 | 'The Moon is moving approximately 3.8 cm away from our planet every year.',
45 | ];
46 |
47 | //=========================================================================================================================================
48 | //Editing anything below this line might break your skill.
49 | //=========================================================================================================================================
50 |
51 | exports.handler = function(event, context, callback) {
52 | var alexa = Alexa.handler(event, context);
53 | alexa.appId = APP_ID;
54 | alexa.registerHandlers(handlers);
55 | alexa.execute();
56 | };
57 |
58 | const handlers = {
59 | 'LaunchRequest': function () {
60 | this.emit('GetNewFactIntent');
61 | },
62 | 'GetNewFactIntent': function () {
63 | const factArr = data;
64 | const factIndex = Math.floor(Math.random() * factArr.length);
65 | const randomFact = factArr[factIndex];
66 | const speechOutput = GET_FACT_MESSAGE + randomFact;
67 |
68 | this.response.cardRenderer(SKILL_NAME, randomFact);
69 | this.response.speak(speechOutput);
70 | this.emit(':responseReady');
71 | },
72 | 'AMAZON.HelpIntent': function () {
73 | const speechOutput = HELP_MESSAGE;
74 | const reprompt = HELP_REPROMPT;
75 |
76 | this.response.speak(speechOutput).listen(reprompt);
77 | this.emit(':responseReady');
78 | },
79 | 'AMAZON.CancelIntent': function () {
80 | this.response.speak(STOP_MESSAGE);
81 | this.emit(':responseReady');
82 | },
83 | 'AMAZON.StopIntent': function () {
84 | this.response.speak(STOP_MESSAGE);
85 | this.emit(':responseReady');
86 | },
87 | };
88 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Regions: [🇯🇵](../../tree/ja-JP)
2 |
3 |
4 |
5 | # Build An Alexa Fact Skill 🇺🇸
6 |
7 |
8 |
9 | This Alexa sample skill is a template for a basic fact skill. Provided a list of interesting facts about a topic, Alexa will select a fact at random and tell it to the user when the skill is invoked.
10 |
11 | If you would like to see an example of this skill in action, you can enable the [Gloucester Facts](https://www.amazon.com/Robert-McCauley-Gloucester-Facts/dp/B01I5MOIA2/) from the [Alexa Skill Store](http://amazon.com/skills).
12 |
13 |
14 |
15 | If this is your first time here, you're new to Alexa Skills Development, or you're looking for more detailed instructions, click the **Get Started** button below:
16 |
17 |
11 |
12 | 2. **Click "Services" at the top of the screen, and type "Lambda" in the search box.** You can also find Lambda in the list of services. It is in the "Compute" section.
13 |
14 |
15 |
16 | 3. **Check your AWS region.** AWS Lambda only works with the Alexa Skills Kit in two regions: US East (N. Virginia) and EU (Ireland). Make sure you choose the region closest to your customers.
17 |
18 |
19 |
20 | 4. **Click the "Create a Lambda function" button.** It should be near the top of your screen. (If you don't see this button, it is because you haven't created a Lambda function before. Click the blue "Get Started" button near the center of your screen.)
21 |
22 |
23 |
24 | 5. **There are two boxes labeled "Author from scratch" and "Blueprints". Click the radio button in the box titled "Blueprints" then choose the blueprint named "alexa-skill-kit-sdk-factskill".** We have created a blueprint as a shortcut to getting everything set up for your skill. You can search for a blueprint using the provided search box. This blueprint adds the alexa-sdk to your Lambda function so that you don't have to upload it yourself.
25 |
26 |
27 |
28 | 6. **Configure your function.** This screen is where we will enter the important parts of our Lambda function. These values will only ever be visible to you, but make sure that you name your function something meaningful. "SpaceFacts" is sufficient if you don't have another idea for a name.
29 |
30 |
31 |
32 | 7. **Set up your Lambda function role.** If you haven't done this before, we have a [detailed walkthrough for setting up your first role for Lambda](https://github.com/alexa/alexa-cookbook/tree/master/aws/lambda-role.md). If you have done this before, set your **Existing role** value to "lambda_basic_execution."
33 |
34 |
35 |
36 | 8. **Click Create Function in the bottom right corner.** You will need to scroll down to find **Create Function.**
37 |
38 |
39 |
40 | 9. **After you create the function, the ARN value appears in the top right corner. Copy this value for use in the next section of the guide.**
41 |
42 |
43 |
44 | 10. **Configure your trigger.** Look at the column on the left called "Add triggers", and select Alexa Skills Kit from the list. If you don't see Alexa Skills Kit in the list, jump back to step #3 on this page.
45 |
46 |
47 |
48 | Once you have selected Alexa Skills Kit, scroll down and click the **Add** button. Then click the **Save** button in the top right. You should see a green success message at the top of your screen. Now, click the box that has the Lambda icon followed by the name of your function (SpaceFacts if you used our suggestion) and scroll down to the field called "Function code".
49 |
50 | 7. **Copy and paste the [provided code](https://github.com/alexa/skill-sample-nodejs-fact/blob/en-US/lambda/custom/index.js) into the Lambda function code box.** We have provided the code for this skill on [GitHub](https://github.com/alexa/skill-sample-nodejs-fact/blob/en-US/lambda/custom/index.js). Delete the contents of the code box, and paste the contents of the new code.
51 | Click "Save".
52 |
53 |
55 |
56 |
13 |
14 | 3. **Understand the voice simulator.** While it's not specific to your skill, the Voice Simulator is a valuable testing tool for every skill. Type a word into the box, and click the "Listen" button to hear how Alexa will
15 | pronounce it. To make changes to her pronunciation, use Speech Synthesis Markup Language [(SSML)](https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/speech-synthesis-markup-language-ssml-reference) to modify how Alexa will interpret text to speech. Try these examples:
16 |
17 | ```html
18 |
30 |
31 | Return to the Voice Simulator as needed to ensure that Alexa says words and phrases as you would expect.
32 |
33 | 4. **Test your skill with the Service Simulator.** To validate that your skill is working as expected, use the Service Simulator. In the **Enter Utterance** text box, type "open reindeer trivia"
34 |
35 |
36 |
37 | ### Service Simulator Tips
38 | * After you click the "Ask [Your Skill Name]" button, you should see the **Lambda Request** and **Lambda Response** boxes get populated with JSON data like in the screenshot above.
39 | * Click the **Listen** button in the bottom right corner to hear Alexa read the response.
40 |
41 | * If you receive a response that reads: *"The remote endpoint could not be called, or the response it returned was invalid,"* this is an indication that something is broken. AWS Lambda offers an additional testing tool to help you troubleshoot your skill.
42 |
43 | 5. **Configure a test event in AWS Lambda.** Now that you are familiar with the **request** and **response** boxes in the Service Simulator, it's important for you to know that you can use your **requests** to directly test your Lambda function every time you update it. To do this:
44 | 1. Enter an utterance in the service simulator, and copy the generated Lambda Request for the next step.
45 |
46 | 2. **Open your Lambda function in AWS, open the Actions menu, and select "Configure test events."**
47 |
48 |
49 |
50 | 3. **Select "Create New Test Event". Choose "Alexa Start Session" as the Event Template from the dropdown list.** You can choose any test event in the list, as they are just templated event requests, but using "Alexa Start Session" is an easy one to remember.
51 |
52 |
53 |
54 | 4. **Type in an Event Name into the Event Name Dialog box. Delete the contents of the code editor, and paste the Lambda request you copied above into the code editor.** The Event Name is only visible to you. Name your test event something descriptive and memorable. For our example, we entered an event name as "startSession". Additionally, by copying and pasting your Lambda Request from the service simulator, you can test different utterances and skill events beyond the pre-populated templates in Lambda.
55 |
56 |
57 |
58 | 5. **Click the "Create" button.** This will save your test event and bring you back to the main configuration for your lambda function.
59 |
60 | 6. **Click the "Test" button to execute the "startSession" test event.**
61 |
62 |
63 |
64 | This gives you visibility into four things:
65 |
66 | * **Your response, listed in the "Execution Result."**
67 |
68 |
69 |
70 | * **A Summary of the statistics for your request.** This includes things like duration, resources, and memory used.
71 |
72 |
73 |
74 | * **Log output.** By effectively using console.log() statements in your Lambda code, you can track what is happening inside your function, and help to figure out what is happening when something goes wrong. You will find the log to be incredibly valuable as you move into more advanced skills.
75 |
76 |
77 |
78 | * **A link to your [CloudWatch](https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#logs:) logs for this function.** This will show you **all** of the responses and log statements from every user interaction. This is very useful, especially when you are testing your skill from a device with your voice. (It is the "[Click here](https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#logs:)" link in the Log Output description.)
79 |
80 | 6. **Other testing methods to consider:**
81 |
82 | * [Echosim.io](https://echosim.io) - a browser-based Alexa skill testing tool that makes it easy to test your skills without carrying a physical device everywhere you go.
83 | * [Unit Testing with Alexa](https://github.com/alexa/alexa-cookbook/tree/master/testing/postman/README.md) - a modern approach to unit testing your Alexa skills with [Postman](http://getpostman.com) and [Amazon API Gateway](http://aws.amazon.com/apigateway).
84 |
85 | 7. **If your sample skill is working properly, you can now customize your skill.**
86 |
87 |
89 |
90 |
11 |
12 | 2. **Once you have signed in, click the Alexa button at the top of the screen.**
13 |
14 |
15 |
16 | 3. **On the Alexa page, choose the "Get Started" button for the Alexa Skills Kit.**
17 |
18 |
19 |
20 | 4. **Select "Add A New Skill."** This will get you to the first page of your new Alexa skill.
21 |
22 |
23 |
24 | 5. **Fill out the Skill Information screen.** Make sure to review the tips we provide below the screenshot.
25 |
26 |
27 |
28 | ### Skill Information Tips
29 | 1. **Skill Type** For this skill, we are creating a skill using the Custom Interaction Model. This is the default choice.
30 |
31 | 2. **Language** Choose the first language you want to support. You can add additional languages in the future, but we need to start with one. (This guide is using U.S. English to start.)
32 |
33 | 3. **Name** This is the name that will be shown in the Alexa Skills Store, and the name your users will refer to.
34 |
35 | 4. **Invocation Name** This is the name that your users will need to say to start your skill. We have provided some common issues developers encounter in the list below, but you should also review the entire [Invocation Name Requirements](https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/choosing-the-invocation-name-for-an-alexa-skill).
36 |
37 | | Invocation Name Requirements | Examples of incorrect invocation names |
38 | | ---------------------------- | -------------------------------------- |
39 | | The skill invocation name must not infringe upon the intellectual property rights of an entity or person. | korean air; septa check |
40 | | Invocation names should be more than one word (unless it is a brand or intellectual property), and must not be a name or place | horoscope; trivia; guide; new york |
41 | | Two word invocation names are not allowed when one of the words is a definite article, indefinite article, or a preposition | any poet; the bookie; the fool |
42 | | The invocation name must not contain any of the Alexa skill launch phrases and connecting words. Launch phrase examples include "launch," "ask," "tell," "load," and "begin." Connecting word examples include "to," "from," "by," "if," "and," "whether." | trivia game for star wars; better with bacon |
43 | | The invocation name must not contain the wake words "Alexa," "Amazon," "Echo," or the words "skill" or "app." | hackster initial skill; word skills |
44 | | The invocation name must be written in each language you choose to support. For example, the German version of your skill must have an invocation name written in German, while the English (US) version must have an invocation name written in English. | kitchen stories (German skill) |
45 |
46 | 5. **Audio Player** For this Fact skill, we won't be using any audio files, so you can select No for this option. If you would like to learn more about adding audio to your skills, please check out our [Audio Player Guide](https://github.com/alexa/skill-sample-nodejs-audio-player).
47 |
48 | 6. **Click the Next button to move to the Interaction Model.**
49 |
50 |
51 |
52 | 7. Click on the **Launch Skill Builder** (Beta) button . This will launch the new Skill Builder Dashboard.
53 |
54 | 
55 |
56 | 8. Click on the "Code Editor" item under **Dashboard** on the top left side of the skill builder.
57 |
58 | 9. In the textfield provided, replace any existing code with the code provided in the [Interaction Model](../InteractionModel.json), then click "Apply Changes" or "Save Model".
59 |
60 | 10. Click on the "Dashboard" button.
61 |
62 | 11. Add some more sample utterances for your newly generated intents. Think of all the different ways that a user could request to make a specific intent happen. Here are a few examples for DescriptionIntent:
63 |
64 | * Give me a fact
65 | * Tell me a fact
66 | * Tell me something
67 | * Tell me a space fact
68 |
69 | 
70 |
71 | 11. Click on the **Save Model** button, and then click on the **Build Model** button.
72 |
73 | 
74 |
75 |
117 |
118 | 12. If your interaction model builds successfully, click on **Configuration button** to move on to Configuration. In our next step of this guide, we will be creating our Lambda function in the AWS developer console, but keep this browser tab open, because we will be returning here on [Page #3: Connect VUI to Code](./3-connect-vui-to-code.md).
119 | 
120 |
121 | If you get an error from your interaction model, check through this list:
122 |
123 | * **Did you copy & paste the provided code into the appropriate boxes?**
124 | * **Did you accidentally add any characters to the Interaction Model or Sample Utterances?**
125 |
126 |
128 |
129 |
11 |
12 | 2. **Complete the Global Fields data.** These fields apply across all of the languges that your skill supports.
13 |
14 |
15 |
16 | * **For Category, we are building a fact skill, so select "Games, Trivia, and Accessories."** You will also be presented with a **Sub-Category** option. For this skill, choose "Knowledge and Trivia."
17 |
18 | * **Provide testing instructions.** Testing instructions give you an opportunity to explain your skill, and any special or possibly confusing features, to the certification team. A value is required in this box.
19 |
20 | * Since you are using our Fact Sample, make sure to add this sentence to your Testing Instructions:
21 |
22 | ```
23 | This was built using the Fact Sample.
24 | ```
25 |
26 | This will let the testing team understand what you're providing them, and should decrease the testing time required.
27 |
28 | * **Countries and Region can be for "all countries", unless you have a specific reason to exclude a specific location.** This gives Amazon the ability to distribute your skill globally. Remember that you will need to create additional versions of your skill in the other available languages before they will be available in those countries.
29 |
30 | 3. **Write your skill descriptions.**
31 |
32 |
33 |
34 | * **Spend some time coming up with an enticing, succinct description.** This is one of the few places you have an opportunity to attract new users, so make the most of it! These descriptions show up in the list of skills available in the [Alexa app](http://alexa.amazon.com/spa/index.html#skills).
35 |
36 | 4. **For your example phrases, come up with the three most exciting ways a user can talk to your skill.**
37 |
38 |
39 |
40 | * **Make sure that each of your example phrases are a perfect match with one of your Sample Utterances.** Incorrect example phrases are one of the most common reasons that skills fail certification, so we have provided a short list of things to consider as you write your example phrases:
41 |
42 | | Common Failure Points for Example Phrases |
43 | | ----------------------------------------- |
44 | | Example phrases **must** adhere to the [supported phrases](https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/supported-phrases-to-begin-a-conversation). |
45 | | Example phrases **must** be based on sample utterances specified in your Intent Schema. |
46 | | Your first example phrase **must** include a wake word and your invocation name. |
47 | | Example phrases **must** provide a contextual response. |
48 |
49 | * **Choose three example phrases that are likely to be the most common ways that users will attempt to interact with your skill.** Make sure that each of them works well, and provides an excellent user experience.
50 |
51 | 5. **Provide a comprehensive list of keywords for users that are searching for new skills.** This is an optional field, and searching the [Alexa app](http://alexa.amazon.com) will also find the words in your Skill Name and descriptions, so you don't need to overdo it. That being said, if there are words that you want users to find your skill with, you should include them here. Separate the keywords with commas.
52 |
53 |
54 |
55 | 6. **Create your skill's icons.** You need two sizes of your icon: 108x108px and 512x512px.
56 |
57 |
81 |
82 | 8. **Answer each of the Global Fields questions using the guidance below.** These fields also apply across all of the languages that your skill supports.
83 |
84 |
85 |
86 | * **Does this skill allow users to make purchases or spend real money?** For this fact skill, the answer is no. For future skills, make sure you answer this appropriately.
87 |
88 | * **Does this Alexa skill collect users' personal information?** Again, for this fact skill, the answer is no. If you do collect information about a user, such as names, email addresses, phone numbers, and so forth, ensure that you answer Yes to this question.
89 | * Answering "yes" to this question will also require you to provide a link to your Privacy Policy at the bottom of the page.
90 |
91 | * **Is your skill directed to children under the age of 13?** Because you customized this skill with data you provided, it is possible that you created a skill that targets children under the age of 13. For this fact skill, the answer is **no** because it doesn't target a specific age group.
92 | * Factors to consider in determining if this skill is directed to children under 13 include:
93 | * Subject matter of the skill
94 | * Presence of child-oriented activities and incentives
95 | * Type of language used in the skill
96 | * Music and other audio content in the skill
97 | * How the skill is described and marketed
98 | * Intended audience for the skill
99 |
100 | If you're not sure, please see the [FTC's COPPA Guidance and FAQ](https://www.ftc.gov/tips-advice/business-center/guidance/complying-coppa-frequently-asked-questions) for more information.
101 |
102 | 9. **Export Compliance.** Be certain that you agree with all of the conditions. If you do, make sure to check this box, as Amazon requires this permission to distribute your skill around the globe.
103 |
104 | 10. **Privacy Policy URL.** This is an optional field, and should not be required for this Fact skill sample. You can leave it blank.
105 |
106 | 11. **Terms of Use URL.** This is also optional, and you can leave it blank.
107 |
108 | 12. **Click the Save button at the bottom of the page.**
109 |
110 |
111 |
112 | 13. **Each checkmark should be green, as shown.**
113 |
114 |
115 |
116 | 14. **If you feel that your skill is ready for certification, click the "Submit for Certification" button at the bottom of the page.**
117 |
118 |
119 |
120 | 15. **You're done with your submission!** Here are a few things you might need to know:
121 |
122 | * **Certification can take several days to complete.** Please be patient. It takes time because we want to get it right.
123 |
124 | * **Did something go wrong?** Our team of evangelists run [online office hours every Tuesday from 1-2pm Pacific Time](https://attendee.gotowebinar.com/rt/8389200425172113931). They can help answer any questions you might have.
125 |
126 | * **Want the coolest t-shirt you've ever seen?** Every month, we create a brand-new Alexa Developer t-shirt or hoodie, and send them out to developers that published a skill that month. [You can get yours here if you live in the US](https://developer.amazon.com/alexa-skills-kit/alexa-developer-skill-promotion), [here for the UK](https://developer.amazon.com/en-gb/alexa-skills-kit/alexa-developer-skill-promotion), and [here for Germany](https://developer.amazon.com/de-de/alexa-skills-kit/alexa-developer-skill-promotion).
127 |
128 |