Skip to content

Demonstrates how to use the new in-skill purchase features of Alexa skills by offering different packs of facts behind a purchase, and a subscription to unlock all of the packs at once

License

Notifications You must be signed in to change notification settings

engineerChick/skill-sample-nodejs-fact-in-skill-purchases

 
 

Repository files navigation

Build An Alexa Skill with In-Skill Purchases

Setup the ASK CLI

There are several aspects of developing an Alexa skill with in-skill purchases that require the use of the Alexa Skills Kit Command Line Interface (ASK CLI), so this entire walkthrough will require you to have installed and configured the ASK CLI. If you haven't done this before, here are the resources you need to get the ASK CLI installed on your machine:

If you have used the ASK CLI previously, you will also need to make sure that you have the most recent version of the ASK CLI. You can make sure you have the latest version by running the command:

$ npm update -g ask-cli

Installation

Note: if you have git installed, you can clone this repo and skip this section.

Note: if you don't have git installed and want to skip this section, download the repo as a zip from here.

  1. Create a new skill using the CLI.

    $ ask new
  2. Name the skill "Premium_Facts_Sample".

    ? Please type in your new skill name:
    Premium_Facts_Sample
  3. Navigate to your project folder.

    $ cd Premium_Facts_Sample
  4. Explore the project structure. You should see folders for lambda and models, and skill.json file.

    $ ls
    lambda		models		skill.json
  5. Open the models folder.

    $ cd models
  6. Open the interaction model file, en-US.json.

    $ open en-US.json
  7. Replace the contents of en-US.json with the contents of this JSON file, and save it.

  8. Go back to the project's root folder.

    $ cd ..
  9. Replace the contents of package.json with the contents of this JSON file, and save it.

  10. Navigate to the lambda folder.

    $ cd ../lambda/custom
  11. Open the AWS Lambda function code file, index.js.

    $ open index.js
  12. Replace the contents of index.js with the contents of this JS file, and save it.

  13. Update the Alexa SDK and the other npm dependencies.

    $ npm update
  14. Navigate back to the root project directory.

    $ cd ../..

Creating In-Skill Products

There are ASK CLI commands for creating your in-skill purchases. This guide will walk you through creating three different one-time purchases (entitlements), as well as a subscription. Our sample code is expecting these to be created as described, so make sure to follow along carefully.

  1. Create your first in-skill product. You should be in the project's root directory.

    $ ask add isp
  2. Choose Entitlement.

    ? List of in-skill product types you can choose (Use arrow keys)
    ❯ Entitlement
    Subscription
  3. Choose Entitlement_Template as your template.

    ? List of in-skill product templates you can choose (Use arrow keys)
    ❯ Entitlement_Template
  4. Name your in-skill product science_pack.

    ? Please type in your new in-skill product name:
    (Entitlement_Template) science_pack
  5. Repeat steps #2 - #5 to create two more entitlements: history_pack and space_pack.

    ? Please type in your new in-skill product name:
    (Entitlement_Template) history_pack
    ...
    ? Please type in your new in-skill product name:
    (Entitlement_Template) space_pack
  6. Create a subscription product named all_access using a similar process.

    $ ask add isp
    
    ? List of in-skill product types you can choose (Use arrow keys)
      Entitlement
    ❯ Subscription
    
    ? List of in-skill product templates you can choose (Use arrow keys)
    ❯ Subscription_Template
    
    ? Please type in your new in-skill product name:
    (Subscription_Template) all_access
    
  7. Navigate to the new ISPs directory, and note the two folders, entitlement and subscription. This is where the JSON files for each of your in-skill products reside.

    $ cd isps
    $ ls
  8. Navigate to the entitlement folder. You should see three files in this directory, one for each of the entitlements you created in our previous steps.

    $ cd entitlement
    $ ls
  9. Open history_pack.json

    This JSON file contains all of the necessary fields for your in-skill product, but you'll need to add the details to get them ready to sell. Because we used the Entitlement_Template template, we have provided a small explanation for each field, make sure you replace all of them. Take a look at the sample in our docs for an additional reference. For this sample, at a minimum, you will need to update the name (not referenceName!), smallIconUri, largeIconUri, summary, description, purchasePromptDescription, boughtCardDescription, releaseDate and privacyPolicyUrl. Alternatively you can copy and paste the contents of the files found here: ISP Entitlements.

    After updating history.pack.json, Fill out the details for the science_pack.json and space_pack.json files. You will need to update with content about your science and space products including icons for each.

    IMPORTANT: Don't change the referenceName in your files, as our codebase is relying on those to be consistent.

    Once you are happy with your pricing, descriptions, and the other metadata for your three entitlements, you should update the same fields plus the subscriptionPaymentFrequency for your subscription. Alternatively you can copy and paste the contents of All Access ISP subscription sample into your all_access.json file.

  10. Review and edit the subscription file.

    $ cd ../subscription
    $ open all_access.json

    Now that you have customized your in-skill products, you can deploy your skill using the ASK CLI, and start testing it.

    Note: be sure to review the output to confirm there were no errors.

Deployment

  1. Navigate to the project's root directory. You should see a file named 'skill.json' there.

    $ cd ../..
  2. Deploy the skill and the Lambda function in one step by running the following command:

    $ ask deploy

    Assuming that you followed all of the setup instructions for the ASK CLI, your entire skill and Lambda function should be created on their respective portals.

Testing

  1. To test, login to Alexa Developer Console, click on the Premium Facts Sample entry in your skill list, and click on the "Test" tab. The "Test" switch on your skill should have been automatically enabled. If it was not, enable it now.

  2. Your skill can now be tested on devices associated with your developer account, as well as the Test tab in the Developer Portal. To start using your skill, just type or say:

    Alexa, open premium facts sample
    

Note: The developer account associated with the skill is never charged for in-skill products. For more details about testing skills with in-skill products, please refer to the In-Skill Purchase Testing Guide

License Summary

This sample code is made available under a modified MIT license. See the LICENSE file.

About

Demonstrates how to use the new in-skill purchase features of Alexa skills by offering different packs of facts behind a purchase, and a subscription to unlock all of the packs at once

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%