Voice UI Access to CEC Using Alexa Skills Kit

March 29, 2018 | 6 minute read
John Featherly
Cloud Native Architect
Text Size 100%:

Introduction

The Content and Experience (CEC) REST API can be used to access CEC resources. The Alexa Skills Kit provides speech-to-text, natural language understanding and text to speech capabilities. CEC access via the CEC REST API from JavaScript running in a node.js AWS Lambda serverless container.

Setup

There are a handful of steps involved in setup consisting of the following:

  • Create a new Alexa Skill in Amazon Developer
  • Load the Interaction Model and train/build
  • Create AWS Lambda and load node.js code package
  • Configure ARN from Lambda to connect Alexa Skill
  • Test

Create a new Alexa Skill in Amazon Developer

Login to Amazon Developer Console and select Alexa development and Alexa Skill

alexa-skill

The invocation name is what users will say to invoke the skill.

skill-names

Click the Save button at the bottom of the page to create the skill then click Next to move on to setting up the Interaction Model.

Load the Interaction Model and Train

There are three parts to load the interaction model; intent schema, slot types and sample utterances. The intent schema is JSON data that enumerates the intents as shown below.

{
  "intents": [
    {
      "intent": "GetOfferIntent"
    },
    {
      "slots": [
        {
          "name": "PRODUCT",
          "type": "CAFE_PRODUCTS"
        }
      ],
      "intent": "GetProductOfferIntent"
    },
    {
      "slots": [
        {
          "name": "DRINK",
          "type": "CAFE_DRINKS"
        }
      ],
      "intent": "GetRecipeIntent"
    },
    {
      "slots": [
        {
          "name": "DRINK",
          "type": "CAFE_DRINKS"
        }
      ],
      "intent": "AddRecipeIngredientsToListIntent"
    },
    {
      "intent": "AMAZON.HelpIntent"
    },
    {
      "intent": "AMAZON.StopIntent"
    },
    {
      "intent": "AMAZON.CancelIntent"
    }
  ]
}

Create a list of sample utterances, something like:

GetOfferIntent tell me all offers
GetOfferIntent offers
GetOfferIntent tell me about offers
GetOfferIntent give me an offer
GetOfferIntent give me new promotions
GetOfferIntent promotions
GetOfferIntent tell me some specials
GetOfferIntent give me information on offers
GetOfferIntent give me some offers
GetOfferIntent specials
GetOfferIntent tell me some deals
GetOfferIntent give me a special
GetOfferIntent give me a deal
GetOfferIntent what's the latest offer
GetOfferIntent what's the latest promotion
GetOfferIntent what's the latest special
GetOfferIntent I would like to hear an offer
GetOfferIntent I want to know about specials
GetProductOfferIntent what {PRODUCT} offers do you have
GetProductOfferIntent {PRODUCT} offers
GetProductOfferIntent {PRODUCT} offer
GetProductOfferIntent tell me about {PRODUCT} specials
GetProductOfferIntent deals on {PRODUCT}
GetProductOfferIntent specials on {PRODUCT}
GetProductOfferIntent tell me about {PRODUCT} promotions
GetProductOfferIntent tell me about {PRODUCT} offers
GetProductOfferIntent give me some {PRODUCT} specials
GetProductOfferIntent give me some deals on {PRODUCT}
GetProductOfferIntent what {PRODUCT} specials do you have
GetProductOfferIntent {PRODUCT} specials
GetProductOfferIntent {PRODUCT} special
GetProductOfferIntent what {PRODUCT} promotions do you have
GetProductOfferIntent {PRODUCT} promotions
GetProductOfferIntent {PRODUCT} promotion
GetProductOfferIntent give me deals on {PRODUCT}
GetProductOfferIntent give me promotions on {PRODUCT}
GetProductOfferIntent tell me about offers on {PRODUCT}
GetProductOfferIntent promotions for {PRODUCT}
GetProductOfferIntent i want to know about {PRODUCT} offers
GetRecipeIntent get me a recipe for {DRINK}
GetRecipeIntent find a recipe for {DRINK}
GetRecipeIntent tell me a recipe for {DRINK}
GetRecipeIntent {DRINK} recipes
GetRecipeIntent tell me {DRINK} recipes
GetRecipeIntent get me {DRINK} recipes
GetRecipeIntent find {DRINK} recipes
GetRecipeIntent I want a recipe for {DRINK}
GetRecipeIntent recipes for {DRINK}
AddRecipeIngredientsToListIntent add ingredients for {DRINK} to my shopping list
AddRecipeIngredientsToListIntent put ingredients for {DRINK} on my shopping list
AddRecipeIngredientsToListIntent I'm going shopping for {DRINK} ingredients
AddRecipeIngredientsToListIntent I'm planning to buy ingredients for {DRINK}
AddRecipeIngredientsToListIntent I'm planning to make {DRINK} and need to buy the ingredients

Create the slot names and enumerations for CAFE_PRODUCTS and CAFE_DRINKS. Make up a list of products and drinks, use the samples below to get started.

PRODUCTS
coffee
bakery
cake
pastry
breakfast
snacks
tea
Arabica
iced
Kona
dark roast
aroma roast
Robusta
Liberian
ground
course grind
DRINKS
latte
mocha
cappuccino
espresso
frappuccino
irish coffee
buttered toffee coffee

Once the components of the interaction model are entered click on create to train the model.

interaction-model

Load & Configure AWS Lambda Code Package

Login to AWS console and select Lambda under Compute Services. Give your Lambda Function a name and select node.js for the Runtime and lambda_basic_execution for as the existing role.

lambda-create

Click the Create funtion button on the lower right of the page.

On the Lambda configuration page, add an Alexa Skills Kit trigger and set the Code entry type to Upload a .ZIP file. Click the Upload button and select the zip file containing your Alexa Skill code that calls CEC via the REST API. Click the Save button on the upper right of the page to save the configuration and upload the code package.

lambda-config

The final step in Lambda setup is to register environment variables for CEC server URL, Content Type names etc. Use the table below to create the six listed variables. Depending on how you coded your CEC access functions you will need server URL, content type names etc.

Configure ARN from Lambda to Alexa Skill

After the Lambda Function configuration is saved you will see the ARN at the top of the configuration page. Select and copy the ARN to the clipboard.

ARN

You can close the AWS Lambda console and return to the Alexa Skill configuration page. On the Alexa Skill configuration page, select AWS Lambda ARN as the Endpoint Type and paste the ARN copied to the clipboard earlier in the Default value box. Also select Lists Read and Lists Write to enable access to the shopping list.

skill-config

Click the Save button to save the configuration and then the Next button to proceed to the Test page.

Test

On the test page enter a sample utterance in the Service Simulator and then click the Ask button.

skill-test

Setup CEC

There are two Content Types necessary in CEC for this demo, Promo and Recipe. Create the Content Types as described below and create a handful of Content Items of each type. Typically you will create a site and add the content items to the site collection. After the site collection exists obtain the corresponding access token value that is needed for the REST calls in the Lambda function.
There are a number of ways to retrieve access tokens. One is to use the following request to your CEC server

https://server/documents/integration?IdcService=GET_ACCESSABLE_PUBLISH_TARGETS&IsJson=1

using Postman or a similar tool and sort through the response to get the access token corresponding to your site collection and the username used on the above call.

Promo Content Type

Create a Promo Content Type with the following attributes

Field Data Type
image_banner media
image_mobile_header media
image_mobile_thumbnail media
summary rich text
content rich text
textposition Left, Center, Right
textcolor Light, Dark

 

Promo

Recipe Content Type

Create a Recipe Content Type with the following attributes

Field Data Type
author text
cooktime text
description text
image media
ingredients text array
preptime text
recipeinstructions text array
recipeyield text

Recipes

Summary

The combination of CEC REST API and Alexa Skills Kit make it easy to build a voice user interface to CEC resources.

John Featherly

Cloud Native Architect


Previous Post

Connecting Oracle Data Sync to the Autonomous Data Warehouse Cloud using OCI

Dayne Carley | 1 min read

Next Post


Functions-as-a-Service - What SOA Should Have Been

Sherwood Zern | 7 min read