/scout-alexa-1

Scout Alexa Skill

Primary LanguageJavaScriptMozilla Public License 2.0MPL-2.0

Scout Alexa Skill

Build Status Coverage Status

This is a lambda function that drives the Alexa skill for Scout.

Uses Alexa Skills Kit SDK for Node.js v2. Backwards compatibility with v1: see ASK SDK Migration Guide.

Setting up

Requirements: scout-ua, Auth Lamdba Functions and Auth API Gateways are deployed.

AWS Lambda

Create an AWS Lambda Function on AWS Lambda.

Add the following environment variables to your Lambda function:

  • APP_ID: Alexa Skill ID. You can find it in the Alexa Skills Kit Console
  • JWOT_TOKEN: JWOT token to access API (scout-ua). Generate using the api/auth/register endpoint from scout-ua (POST request with name, email, password fields).
  • SCOUT_ADDR: API hostname for scout-ua (yourserver.com for instance)
  • LOG_LEVEL: Optional. Winston logging level.
  • SUMMARY: Optional. If this is there and set to 'false', the user will not get an option to hear the summary. The only option will be the full article.
  • POCKET_KEY: Optional. If you want to send metrics to the Pocket server, this can be your pocket consumer key.

Cross Compiling the natural packages

In order to run this on Amazon, some of the node packages need to be cross-compiled on Amazon Linux to work properly. Here is a set of steps to do this:

Alexa Skill Kit

Create an Alexa Skill on Alexa Skills Kit. You can put Scout as an invocation name.

  • Use the JSON Editor and upload the skill.json file.
  • Go to Interfaces and enable the AudioPlayer.
  • Go to Endpoint and add your AWS Lambda function ARN in Default Region.
  • Go to Account Linking and select Implicit Grant. Put your scout-auth-lambda API Gateway Invoke URL in the Authorization Grant field.
  • In Client ID, put your Pocket Consumer Key.
  • In Domain List, add the getpocket.com domain and the domains of your API Gateways.

Deployment

  • Fill skill_id in .ask/config with your Skill Id from Alexa Skills Kit.
  • Fill uri in .ask/config with your ARN from your AWS Lambda function.

Deploy using ask deploy (require AWS command line tools). You may require to create an AWS IAM user with correct permissions to deploy with command line.

Enable on Alexa

Go to alexa.amazon.com. In Skills/Your Skills/Dev Skill you should see your Skill in development. Enable-it. You should get redirected to Pocket to authorize the app. Authorize-it.

Testing

Testing using Bespoken virtual-alexa.

To run tests, you need the following configuration:

  • AWS credentials
  • define environment variables:
    • SCOUT_ADDR=<domain for scout-ua server (not a full URL), e.g. "scout-ua.herokuapp.com"
    • JWOT_TOKEN=<valid scout-ua JWT token>
    • SUMMARY=true
    • STRING_BRAND=./scout_strings.json
    • TEST_ACCT1=<user1>@email.com
    • TEST_ACCT2=<user2>@email.com
    • TEST_ACCT_INVALID=<non-existent-user>@email.com
  • Two Scout users with linked Pocket accounts and the following criteria:
    • User 1: <user1>@email.com
      • Account contains 7-9 articles linked in Pocket
      • Article titles to satisfy each of the following search terms:
        • Firefox
        • Intel resignation
        • Amazon TV
        • Boring Company
        • Donald Trump
    • User 2: <user2>@email.com
      • Account contains 7-9 articles saved in Pocket
    • User 3: <non-existent-user>@email.com
      • Account does not exist.

Sample URLs that will make the tests pass: http://www.businessinsider.com/details-emerge-of-intel-ceo-brian-krzanich-office-affair-resignation-2018-6 https://www.bloomberg.com/news/articles/2018-09-18/amazon-dominates-early-emmy-awards-in-sign-tv-bet-is-paying-off https://www.theverge.com/transportation/2018/9/13/17856078/elon-musk-boring-company-underground-garage-hyperloop https://www.cnn.com/2018/09/19/politics/donald-trump-ethics-analysis/index.html https://techcrunch.com/2018/09/18/mozillas-firefox-reality-web-browser-is-now-available/ http://www.spiegel.de/politik/ausland/usa-paul-manafort-kooperiert-mit-sonderermittler-robert-mueller-a-1228236.html https://www.nytimes.com/2018/04/20/well/family/nobody-tells-you-how-long-a-marriage-is.html https://www.newyorker.com/books/page-turner/my-last-day-as-a-surgeon

Do not add more than the 8 URLs.

To run tests manually: npm test from inside the lambda/custom directory. The node_modules must be generated locally on the machine your running the tests from. Using the node_modules generated on the EC2 instance will not work. It's best to backup any EC2 node_modules directory you have, run npm install and then run npm test.

Note that tests may fail if run from a forked repo due to lack of security keys. Before landing a patch, please make sure that the integrations tests pass when you run them locally.