POC to learn more about how to build alexa skills.
Once you've installed this skill, you can say:
Alexa, inicie o Santa Cruz Notícias
The idea is to know the latest news regarding Santa Cruz soccer team. This repo contains three different layers and each one is explained below.
This is the first layer of the skill. In this file you're going to find the available keywords to trigger the skill.
The action GetFactIntent
will accept these values as valid entries: ultimas noticias
, novidades
or ultimas novidades
.
This is the second layer of the skill. Built using Fastify, it is responsible for start a nodejs server, fetch the content and then return a JSON with the following structure:
In order to fetch the latest news regarding the soccer team, we exposed /news
endpoint.
{
"path": "news",
"payload": {
"content": "Here is the news formatted to speech.",
"contentMapped": [{ "date": "02/09", "text": "Here is the news title" }],
"length": 1
}
}
This is the third layer of the skill. Built using Alexa-hosted (Node.js), it is responsible for communicating with the API and speaking the data.
The method GetFactIntentHandler
was created to handle the intent (GetFactIntent
) of the first layer.
const GetFactIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'GetFactIntent';
},
async handle(handlerInput) {
const response = await httpGet(); // request to external API
const speakOutput = response.payload.content; // speak here
return handlerInput.responseBuilder
.speak(speakOutput)
.getResponse();
}
};
In order to communicate with the API layer using a hosted skill, you need to publish the API in a public domain. All files from lambda
path can be replaced by the files in your web console, and the files under intents
path, can be replaced by the file in intents web section.
This file will be used for intents web section.
- access your aws developer console
- click to edit your skill
- click on "Build" tab
In order to make it running on your local environment, move to the api
path and run:
To install all the dependencies:
$ npm install
To start a development server under http://localhost:3000
:
$ npm run start
An easy way to test your local API, interacting with the amazon hosted services is to expose a public tunnel using ngrok
.
Here are some useful commands:
$ heroku logs --tail --app=<app-name>
$ heroku buildpacks --app=<app-name>
$ heroku apps:info --app=<app-name>
This file will be used for code editor web section.
- access your aws developer console
- click to edit your skill
- click on "Code" tab
- https://www.sitepoint.com/amazon-alexa-skill/
- https://developer.amazon.com/alexa/console/ask
- https://developer.amazon.com/en-US/docs/alexa/alexa-design/get-started.html
- https://ngrok.com/
MIT License © Thulio Philipe