Skip to content

An Alexa skill that counts the number of days until special events.

License

Notifications You must be signed in to change notification settings

nfriend/days-until

Repository files navigation

Days Until

GitLab build status

An Alexa skill that counts the number of days until special events.

View the published skill here: https://www.amazon.com/dp/B0759KJ8D2

Example Dialog

You: "Alexa, ask Days Until to create a new countdown for the end of the world on May 21."
Alexa: "Okay, I'll start a new countdown for the end of the world on May 21, 2011. Does that sound right?"
You: "Yes!"

Later that day...

You: "Alexa, ask Days until, 'How long until the end of the world?'"
Alexa: "17 days!"

Overview

Days Until helps you keep track of the number of days until special events. Set up a count down with any of these:

  • "Alexa, open Days Until"
  • "Alexa, ask Days Until to start a new countdown"
  • "Alexa, ask Days Until to create a countdown for the first day of school"
  • "Alexa, ask Days Until to create a new countdown for the first day of school on August 21"

Alexa will then confirm the date with you before the count down is saved.

After you've created a count down, you can ask Alexa how many days there are until the event:

  • "Alexa, ask Days Until, 'How many days until the first day of school?'"
  • "Alexa, ask Days Until, 'How long until the first day of school?'"

Alexa will then calculate the number of days from today until the event's date and report back to you.

If you're having trouble getting Alexa to recognize your event name, try something a bit simpler. For example, instead of "John Smith's retirement party at the lakehouse", try "the retirement party", or even just "the party".

Developing

  1. Clone this repo
  2. cd lambda
  3. yarn
  4. yarn build
  5. yarn test
  6. yarn lint

See the scripts section of lambda/package.json for a complete list of commands that can be used during development.

The yarn prepush script runs all prerequisite scripts necessary for the pipeline to succeed. It is recommended to run this script before pushing to master.

Additionally, this project uses the ASK CLI for deployment and testing. You can install the CLI globally using yarn global add ask-cli, and then run CLI commands at the root of this project, e.g. ask dialog. See ASK CLI's documentation for a complete list of available commands.

Building the model

This skill's model is generated using the Alexa Skill Utterance and Schema Generator library. This library takes en-US.grammar and outputs en-US.json. To run this process, run yarn model. Note that you will need a JDK installed for this command to run; it executes alexa-generate.jar which is included in this repository.

Testing

The easiest way to develop on this project is using test-driven development through Jest. You can run the tests using yarn test or yarn test:watch. See the existing tests for some examples.

i18n

This project uses i18next for internationalization ("i18n"). i18next-scanner is used to extract the strings directly from the source into this project's i18n directory. You can run this extraction process by running yarn translate.

To make this skill available in all English-speaking Amazon stores, a utility script (lambda/utility-scripts/copy-english-files.js) can be run to copy the appropriate en-US files/sections to en-CA, en-GB, en-AU, and en-IN.

Troubleshooting

I get an error message like "errorMessage": "lambdaFunc[lambdaHandler] is not a function" when running tests

This is most likely because of a compilation error when running the tests. Try running yarn build and make sure this succeeds.

Linting

This project uses Prettier and ESLint to help keep the codebase consistent. You can run all linting checks using yarn lint. Many of the more tedious errors can be fixed automatically; to do this, run yarn lint --fix.

Deploying

Deployment of the skill is handled by this project's GitLab pipeline. Any new commits added to master will trigger a redeploy of the skill (to its "development" stage).

Currently, the pipeline is: GitLab build status

Pipeline variables

The GitLab pipeline relies on a few environment variables:

Variable name Description
AWS_ACCESS_KEY_ID The AWS access key ID of the IAM user that executes the deployment
AWS_SECRET_ACCESS_KEY The AWS secret access key of the user mentioned above
ASK_VENDOR_ID The ASK vendor ID associated with the Alexa Developer account that owns the skill
ASK_REFRESH_TOKEN The OAuth 2.0 refresh token of the Alexa Developer account mentioned above
SENTRY_AUTH_TOKEN The Sentry API token used to upload sourcemaps to Sentry
PROJECT_TOKEN Token used to commit and push changes back to GitLab inside the pipeline. A project-level access token with write_repository scope is sufficient.
ASSETS_BUCKET_NAME Name of the AWS S3 bucket that stores and hosts assets (e.g. images, sound effects) used by the skill

More info on these variables and how to generate their values can be found in this blog post.

IAM user permissions

The IAM user used to execute the deploy must have an IAM policy like this applied:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "VisualEditor0",
      "Effect": "Allow",
      "Action": [
        "iam:GetRole",
        "iam:PassRole",
        "s3:*",
        "logs:*",
        "lambda:*",
        "iam:CreateRole",
        "cloudformation:*",
        "dynamodb:*",
        "iam:AttachRolePolicy",
        "iam:PutRolePolicy"
      ],
      "Resource": "*"
    }
  ]
}

Skill description, updates description, and testing instructions

See comments in lambda/utility-scripts/copy-plain-text-content.js for an explanation about how skill-package/*.txt files get read and used as content for skill.json.

Acknowledgements

Icons from www.flaticon.com were made by the following authors: