Complete our Horoscope sample skill by
- Creating a HoroscopeForSign Intent which includes a sign slot
- Add a response handler to the code which handles the new intent
- Install nvm (if you need to switch between node versions)
- Install Node 8.10.0 by running
nvm install 8.10.0
- Create Alexa Developer Console account
- Create a new skill on the Alexa Developer Console
- Select
Developer Console
on the top menu bar - Select
Alexa Skills Kit
- Click
Create Skill
- Input your selected skill name
- Select the
Custom
skill model - Select
Start From Scratch
- Navigate back to the
Your Skills
section, and take note of skill ID for your new skill (you will need this later)
- Select
- Download the sample project from Git
- Navigate to
lambda/custom
and runnpm install
- Open
lambda/custom/lib/constants.js
and set theYOUR_APP_ID
variable to the skill ID from above - Open
models/en-US.json
and set theYOUR_INVOCATION_NAME
to your desired invocation name (The default is the skill name)
In production, Alexa skill code typically runs on a lambda function. For development this is not very practical as you cannot easily change and debug your code on lambda.
To run code in development we use a library called bespoken-tools. It allows us to run our code locally by routing Alexa requests to our local machines.
There are two approaches that you can use to run the project for this workshop:
- Using Webstorm
- Copy the runConfiguration folder from the sample project into .idea folder
- Select the new configuration from the top menu bar, and click Run or Debug
- Using the Command line
- Ensure you are running Node 8.10.0 by running
nvm use 8.10.0
- Install bespoken-tools globally
npm install -g bespoken-tools
- Navigate to
lambda/custom
- Run this command on the command line
AWS_REGION="us-east-1"
- Start the skill using bespoken tools by running the following command
bst proxy lambda index.js --verbose
- Ensure you are running Node 8.10.0 by running
If everything is running correctly, bespoken-tools should output something like the following:
Your public URL for accessing your local service:
https://sick-huxley-JuRHxZ.bespoken.link
This URL is where the Alexa Skills kit will need to route requests to.
- Navigate to your skill on the Alexa Developer Console
- In the build tab, do the following:
- Navigate to the
Endpoints
section- Select
HTTPS
- Input the bespoken-tools URL displayed in the last step
- Select
My development endpoint is a sub-domain of a domain that has a wildcard certificate from a trusted certificate authority
- Select
Save Endpoints
at the top of the page
- Select
- Navigate to the
JSON Editor
section- Upload
model/en-US.json
- Click
Save Model
and then clickBuild Model
- Once the build is completed and successful, move on to the next step
- Upload
- Navigate to the
Navigate to Test tab on the Alexa Developer Console
- Enable testing using the toggle on the top of the page
- Test if you can communicate with the skill running locally. For example, enter the following into the input field:
open YOUR_INVOCATION_NAME
- Define a
Sign
custom slot inmodels/en-US.json
- Define
HoroscopeForSign
intent inmodels/en-US.json
that utilizes theSign
slot - Add your invocation name at the top of the models file under
invocationName
- Upload and build your modified models file to the Alexa Developer console
- Define a
HoroscopeForSign
ResponseHandler inlambda/custom/handlers/requests.js
.- Within your handler, use the following to access the inputted slot:
handlerInput.requestEnvelope.request.intent.slots.YOUR_SLOT_NAME
- Make sure to validate the slot value, responding to the user with an error if necessary
- Use
horoscopeService.fetchBySign()
to fetch the horoscope content for the inputted sign. - Add any required string responses in
lambda/custom/strings/en-us.js
- Remember that you can use
const requestAttributes = handlerInput.attributesManager.getRequestAttributes(); const response = requestAttributes.t("YOUR_STRING_KEY", replaceObj)
to fetch strings and make string replacements
- Within your handler, use the following to access the inputted slot:
- Run your skill (following the instructions above) and make sure it responds correctly using the Test tab in the Alexa Developer Console
- In the Alexa Developer Console, Navigate to the
Interfaces
section. EnableDisplay Interface
- In the strings file
lambda/custom/strings/en-us.js
, add display data to the HoroscopeForSign strings (https://github.com/Hearst-DD/ask-toolkit/blob/master/README.md#objects) - Run your skill and test that the visuals show up as desired using the Test tab in the Alexa Developer Console.
- Custom skill documentation
- Slot type documentation
- Bespoken tools tutorial
- ask-tools library developed by Hearst ET Private repository. Contact netteam@hearst.com for access.
- https://www.npmjs.com/~hearst-et