Back to List

How to Provide an Alexa Skill Content from Kentico Cloud

Axel Larsen Axel Larsen  |  
Jan 18, 2018
 
If you haven’t noticed yet, there’s a new way to browse the web and it doesn’t even require unlocking a screen: voice assistants. These have been around for a while in our phones and computers, but now companies like Amazon and Google have developed their own hardware that utilize these digital helpers. The technology research organization Gartner predicts that in just 2 years 30% of web browsing will be conducted with these screenless devices (and others like it). You’re probably wondering how your organization is going to provide content to these services and so many other current and emerging channels.

One solution for this growing problem is by utilizing the headless CMS Kentico Cloud – a simplified content management system that focuses on the distribution of your content to multiple platforms instead of focusing on a single way to present that content on a single platform. In other words, by storing and managing your content on Kentico Cloud, you can customize how any piece of content is presented on the various platforms and channels it should be shown on.

The following steps walk through creating a basic Alexa Skill that pulls content from a Kentico Cloud project. The code that pulls the content randomly selects a single item from a list of items of a singular content type.
 

Create an Amazon Developer account

1. Go to the URL https://developer.amazon.com/

2. Click the Sign In link in the header
amazon developer sign in

3. If you’ve already created an Amazon Developer account, enter your email and password and click Sign In – then skip to step 10

4. Click the Create your Amazon Developer account button
create amazon developer account

5. Fill out the form and click Create your Amazon Developer account
create amazon dev account

6. Fill in your email and password for your Amazon Developer account and click the Sign in button
amazon developer sign in

7. Fill in your profile information and click the Save and Continue button
amazon developer registration
amazon developer registration

8. Read through the App Distribution Agreement and if you agree with and accept the terms click the Accept and Continue button.

9. Truthfully answer any questions regarding payments and then click the Save and Continue button.
amazon dev app distribution
 

Create Your Alexa Skill

10. Click the ALEXA link in the navigation
create alexa skill

11. Click the Get Started > button within the Alexa Skills Kit card
alexa skills kit

12. Click the Add a New Skill button  
new alexa skill

13. Give your skill a name. This is probably going to be based on your organization’s name or a brand name.

14. Give your skill an invocation name. This is what a user will say for Alexa to know which skill to utilize. This value might be the same as your skill’s name or might be a shortened version of it. For example, if your skill name is “Teach Kids to Cook” you could assign an invocation name of “Kids Cook” so a user only has to say “Alexa, ask Kids Cook how to make…”. You can change your skill name and invocation name at any time.

15. Click the Save button.
alexa skill info

16. Click the Next button
alexa next

17. Click the Launch Skill Build BETA button
alexa skill build beta

18. Once the interface finishes loading, click the Add an Intent + link.
alexa skill intent

19. Enter a name for your intent (no spaces or special characters).

20. Click the Create Intent button
alexa custom intent

21. In the text box with placeholder text “What might a user say to invoke this intent?” enter a phrase that a user would say to indicate to Alexa to use this intent of the skill. For example, an intent named CookingTip might have an utterance of “give me a cooking tip”.

22. Click the + icon within the textbox of your new utterance
alexa utterance

23. Repeat steps 21 and 22 for any other phrases you can think of to initiate and/or use this intent. The more examples you provide and more diverse the words and syntax of those examples, the better Alexa will be at matching the near-infinite ways a user can phrase their request to the most appropriate intent of your skill.
alexa sample utterance

24. Click the Build Model link in the header
alexa build model

25. After a few minutes you should see a notification indicating the model successfully built
alexa interaction model

26. After that click the Configuration link in the header
alexa configuration
 

Create a Service for Your Alexa Skill

From here we’ll be creating a simple service that provides an endpoint the Alexa skill will point to. This service will handle the request sent by Alexa and return a response in the format that Alexa expects it to be in. Although this service is technically not free to use, upon registering I was given a $5 credit to the account which covered all the requests I needed to develop and test this skill (and then some).

27. To create this service endpoint, follow the sections described from Minute 3: StdLib Account Setup to Minute 6: Assigning Your StdLib Endpoint to Alexa of this quick tutorial https://hackernoon.com/build-an-alexa-skill-in-7-minutes-flat-with-node-js-and-stdlib-70611f58c37f#95fb

28. Open a command prompt (windows key + r, cmd.exe)
create service alexa skill

29. Navigate to the directory of the node.js project created in the hackernoon tutorial
alexa hackernoon tutorial

30. Type in the following command:  npm install request

31. In your development environment add a new JavaScript file under the Intents directory and name it after the intent you created through the Alexa Skill Builder interface (the following screenshots are of Visual Studio Code, a free IDE).
alexa javascript

32. Enter the following code in your newly created JavaScript file

const lib = require('lib');
const request = require('request');

/**
* @param {string} name Intent Name (Automatically Populated by Handler)
* @param {object} slots Slot Information, {name, value}
* @returns {any}
*/
module.exports = (name = '', slots = {}, callback) => {
    var url = 'https://deliver.kenticocloud.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/items?system.type=content_model_code_name'
    request({
    url: url,
    json: true
    }, function (error, response, body) {

    if (!error && response.statusCode === 200) {
        var randomIndex = Math.floor(Math.random() * body.items.length);
        var item = body.items[randomIndex].elements;
        var responseText = item.alexa_name.value + ': ' + item.description.value.replace(/(<([^>]+)>)/ig, '');

        return callback(null, responseText);
    }
    });
};


33. Go to https://app.kenticocloud.com

34. Select the project you’re using with your Alexa Skill
alexa skill project

35. Open the Kentico Cloud menu and click the API Keys link
kentico cloud menu
kentico cloud api keys

36. Click the Copy to clipboard button under Project ID
kentico cloud apis

37. Go back to your JavaScript file and replace the xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx within the URL variable’s value with your Project ID.

38. Go to your Kentico Cloud project again, and this time click the Content models link in the menu
kentico cloud models

39. Click the name of the type of content your intent is going to utilize
kentico content

40. Click the {#} button to reveal your content type’s code name
kentico content type

41. Click the Copy to clipboard button
kentico cloud copy

42. Go back to your intent’s JavaScript file and change the content_model_code_name text at the end of the URL value with the code name you just copied

43. Change the value for responseText to reference the content elements associated to your content model. For an easy way to see what elements you can reference, copy the URL value and paste it into the address bar of any browser. A JSON response is shown containing an array of objects called items. Each object in the array contains an object called system and another object called elements. In the intent’s JavaScript example in this tutorial you’ll see I’m referencing the value of the alexa_name element and description element.

{
    "items": [
        {
        "system": {
            "id": "0c23d4fd-ad5b-4d76-8cc5-9c7ceee432e7",
            "name": "Protect Yourself",
            "codename": "protect_yourself",
            "language": "default",
            "type": "tip",
            "sitemap_locations": [],
            "last_modified": "2017-12-04T06:42:27.7807216Z"
        },
        "elements": {
            "alexa_name": {
            "type": "text",
            "name": "Alexa Name",
            "value": "safety first, protect yourself"
            },
            "description": {
            "type": "rich_text",
            "name": "Description",
            "images": {},
            "links": {},
            "modular_content": [],
            "value": "<p>Don't touch hot items with your bare hands. Always handle hot handles, pots, and dishes with a heat resistant pad or glove.</p>"
            },
            "product": {
            "type": "modular_content",
            "name": "Product",
            "value": []
            },
            "meat": {
            "type": "taxonomy",
            "name": "Meat",
            "taxonomy_group": "",
            "value": []
            }
        }
        },
        {
        "system": {
            "id": "31421ba7-a078-493d-82b9-046f9e9bf751",
            "name": "Try Not to Spill",
            "codename": "try_not_to_spill",
            "language": "default",
            "type": "tip",
            "sitemap_locations": [],
            "last_modified": "2017-12-04T06:40:01.863107Z"
        },
        "elements": {
            "alexa_name": {
            "type": "text",
            "name": "Alexa Name",
            "value": "try not to spill"
            },
            "description": {
            "type": "rich_text",
            "name": "Description",
            "images": {},
            "links": {},
            "modular_content": [],
            "value": "<p>spilling ingredients makes a mess and is wasteful however sometimes dogs will appreciate cleaning it up for you.</p>"
            },
            "product": {
            "type": "modular_content",
            "name": "Product",
            "value": []
            },
            "meat": {
            "type": "taxonomy",
            "name": "Meat",
            "taxonomy_group": "",
            "value": []
            }
        }
        },
        {
        "system": {
            "id": "f71d80e3-46a1-473e-b69b-81ce94f6a031",
            "name": "Use a Timer",
            "codename": "use_a_timer",
            "language": "default",
            "type": "tip",
            "sitemap_locations": [],
            "last_modified": "2017-12-04T06:41:06.0675828Z"
        },
        "elements": {
            "alexa_name": {
            "type": "text",
            "name": "Alexa Name",
            "value": "use a timer"
            },
            "description": {
            "type": "rich_text",
            "name": "Description",
            "images": {},
            "links": {},
            "modular_content": [],
            "value": "<p>a timer will help remind you to follow the instructions of your recipe.</p>"
            },
            "product": {
            "type": "modular_content",
            "name": "Product",
            "value": []
            },
            "meat": {
            "type": "taxonomy",
            "name": "Meat",
            "taxonomy_group": "",
            "value": []
            }
        }
        }
    ],
    "modular_content": {},
    "pagination": {
        "skip": 0,
        "limit": 0,
        "count": 3,
        "next_page": ""
    }
}
          
           


44. Once you’ve finished editing the responseText variable, in your command window enter the following command: lib up dev. This will publish your intent’s JavaScript code to the service endpoint that your Alexa Skill will use.  
 

Test Your Alexa Skill

45. Go to the Amazon Developer portal and click Test from the navigation menu
text alexa skill

46. Click the switch to Enabled to enable testing. Note that you will need to have built your skill at least once to test it.
alexa interaction model

47. Now you can either test your skill by using an Echo device signed in with the same email address as your Amazon Developer account OR by scrolling down to the Service Simulator section.

48. Type out an utterance in the textbox under the Service Simulator section
alexa service simulator

49. Click the Ask <your skill name> button

50. If your code works you should get a response like what’s shown below
alexa code works

51. If you’d like to listen to how Alexa will read out the response click the Listen button
alexa listen
 

Publish Your Alexa Skill

52. Once you’re ready to publish click the Next button
alexa next

53. Fill out the Publishing Information form for the skill
alexa global fields

54. Click the Next button
alexa next

55. Fill out the Privacy Compliance form
alexa privacy compliance

56. To publish the skill to the Amazon Alexa Skills Store, click the Submit for certification button
amazon alexa skills store
 

Conclusion

Now you have a skill that can provide basic information to your users such as your restaurant’s daily specials or your venue’s room availability and capacities. To create more sophisticated skills – such as one that allows users to book an appointment with your accounting firm or screen candidates interested in your organizations current job openings – developers can add slots or prompts to utterances. Or they can utilize the global fields for audio player, video app, or render template.

To learn more about how people are using your skill, including exactly how they phrase their requests, you could incorporate an analytics technology like Google Analytics in your service’s code and/or using Kentico Cloud’s activity tracking capabilities. The possibilities and opportunities only grow from here. Comment below or contact us with how you’d like to utilize Kentico Cloud with Alexa and other voice assistants.
 

 

Love our Blogs?

Sign up to get notified of new Skyline posts.