Giter Club home page Giter Club logo

scout-alexa's Introduction

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:

  • Create an EC2 instance of Amazon Linux. Create an EC2 instance of Amazon Linux
  • Be sure to choose Amazon Linux when you choose your instance type.
  • SSH to your instance
  • Install node |curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash|
  • Set the node version to match your lambda version: |nvm install 8.10|
  • Install dev tools: |sudo yum groupinstall "Development Tools"|
  • Install git: |sudo yum install git|
  • clone the source: |git clone https://github.com/MozScout/scout-alexa.git|
  • |cd scout-alexa/lambda/custom && npm install|
  • copy the scout-alexa/lambda/custom/node_modules directory to your local machine from the directory where your key is: |scp -i ./yourkey.pem -r [email protected]:/home/ec2-user/scout-alexa/ /your/local/dest/|
  • Use that node_modules directory when uploading your lambda function making sure to use the same version that ou cross compiled on.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.