Article by Vasili Shynkarenka, CEO of Storyline with edits from Voicebox

Imagine an Alexa skill that gives you some facts. It’s a simple skill — you just launch it, and it tells you a fact on some topic.

Simple Alexa skills for Amazon Echo share the same facts every time you launch them. But there are skills, where creators update content on a regular basis. We call them dynamic skills.

In this article, I’ll explain how to make dynamic Alexa skills using Storyline, Google Sheets, and random content feature.


Intro to Dynamic Content

The reason people love dynamic Alexa skills is that they are not dull. If you hear the same content every day from your Amazon Echo, you’re not going to continue using the skills after a few times.

There are a lot of use cases for skills with dynamic content. You can get facts about your favourite blogger, university, or even about Amazon. Alexa skills with dynamic content can help you choose a child name or give you a different quote every day.

For skill creators, adding dynamic content to their skills solves a big problem: it’s easier to add, delete, and manage your content in a convenient interface. Google Sheets is an excellent example of such an interface.

The way creators used to make dynamic Amazon Alexa skills in Storyline was to create a server, put content there, connect it with Storyline using API Request feature, and write a function to randomize responses from that server. This process was clunky and hard to follow. Here’s how to make it easy.

Step 1: Create Your Sheet With Data

Let’s imagine I want to create an Alexa skill that shares a random fact about Google. The first thing I need to do is to find content.

After I find some facts about Google, I paste them into a spreadsheet.

Step 2: Convert Your Spreadsheet Into a JSON

To send your data from Google Sheets to Storyline you need to convert it to JSON — a lightweight format for transferring data.

Here’s how Storyline API Request feature works: you make a GET request to some server, it returns a JSON. Then you take some data out of it, and Alexa pronounces that data to the user.

We are going to use native Google Sheets feature to convert the spreadsheet to JSON.

First, you need to publish your spreadsheet to the web, using File -> Publish To Web your spreadsheet.

After you publish your spreadsheet, you need to get your spreadsheet ID. It is a part of your spreadsheet URL. This is NOT the URL shown in the ‘Publish to Web’ window. It’s the one in your search  In our example, the URL of the spreadsheet is:

https://docs.google.com/spreadsheets/d/1GVfUWL3iZEGJ6YJfycLXzqTXKB2UFl65bjopI8LczS8/edit#gid=0

From this URL, spreadsheet ID is:

1GVfUWL3iZEGJ6YJfycLXzqTXKB2UFl65bjopI8LczS8

Now you can access your simple JSON using the following URL:

https://spreadsheets.google.com/feeds/list/SPREADSHEET_ID/od6/public/basic?alt=json

All you need to do is to replace SPREADSHEET_ID with your real ID. Here’s mine:

https://spreadsheets.google.com/feeds/list/1GVfUWL3iZEGJ6YJfycLXzqTXKB2UFl65bjopI8LczS8/od6/public/basic?alt=json

If you follow that link we created below, you’ll see a real JSON with data from your spreadsheet.

But narrow data is hard to read and understand. Let’s beautify it a little bit. To make JSON readable, you can use beautifyjson.com or JSON Viewer chrome extension.

Here’s how it looks with JSON Viewer extension installed:

Step 3: Create an Alexa Skill and Access Your JSON Using Storyline API Requests

After you finished accessing your JSON, you need to create an Alexa skill in Storyline to be able to grab data it and use it in your Alexa skill.

When you go to https://getstoryline.com, sign up and click New custom skillbutton, you’ll see this screen:

My example Alexa skill in Storyline looks like this.

Here’s how an Alexa Skill from Google Spreadsheet looks like in Storyline.

Here I have a Welcome Block, which starts when a user opens the skill. In this block, there are two messages from Alexa:

  • “Hey there! Welcome to Google Sheets test project.”
  • “Here’s a random fact.”

And two default user replies required by Amazon: “help” and “stop.” Simply put, user replies are just options what user can say to this skill.

I also have a fact block here, which is a default block that I added using the New block button on the top right.

New block button in Storyline interface.

In the fact block I have an API Request, which is called get a fact. I also have a {{fact}} step, which is a variable I created to store the fact that I get from a Google Spreadsheet.

JSON API request in Storyline.

API Request in Storyline consists of several parts:

  • Name of your API Request in Storyline
  • URL to JSON with data
  • A field with variable

The name of your API Request does not really matter; I usually choose something meaningful that I can easily find when my skill is big. I have “get a fact” as a name of my API Request here.

URL here is the same URL to JSON format of my spreadsheet I created during the Step 2:

https://spreadsheets.google.com/feeds/list/1GVfUWL3iZEGJ6YJfycLXzqTXKB2UFl65bjopI8LczS8/od6/public/basic?alt=json

A field with variable contains a path to a fact from our spreadsheet JSON and a variable, where we store that fact to use it in Storyline.

fact=api_response.feed.entry.0.title.$t

Here’s what’s inside of it:

fact is a variable that stores the fact we grab from the Google sheet. We are going to use it in the diagram of our skill.

api_response is an operator that helps Storyline understand that this is an API response.

feed.entry contains the content or our spreadsheet. In other words, cells.

When you’re constructing this line, you’re going down the JSON structure and separating each JSON entry with a dot. If you’re using JSON Viewer extension, you can toggle JSON elements to see the structure in a clear way.

Here’s how it looks if you toggle all fields of a JSON:

Then we can toggle entry field and go one level deeper. Entry here is an array of objects, and each object looks like this:

The field we need is $t, which is located in thetitle.

Here’s how the whole line looks like combined.

api_response.feed.entry.0.title.$t

If you have any questions on this part, please feel free to ask them in our Storyline Community of Alexa skills creators.

At this part, you should already have a working Alexa skill that grabs the first fact from your spreadsheet and pronounces it in Storyline. The next step is to make it dynamic.

Step 4: Randomize Facts in Your Amazon Alexa Skill

To access the first element of your spreadsheet, you use .0 key. To access the second cell you use .1.

To call one element from a column randomly, you need to write .random instead of .0.

The whole field with variable who grabbing a random fact from a spreadsheet should look like this (don’t forget a semicolon in the end):

fact=api_response.feed.entry.random.title.$t;

By doing this, you make Storyline understand that you want to access a random element of that array.

If you followed the tutorial, at this moment, you should have an Alexa skill that grabs a random fact about Amazon from a spreadsheet and uses it in Storyline.

You can play with it right in the browser or publish to your Echo device (and Amazon App Store, for sure).

Storyline Browser Preview of my Alexa Skill.

You can also share an interactive view-only preview of your skill with a friend or colleague so that they can play with it too. To do that, click the Share button at the top, and toggle Enable view-only sharing tumbler.


4 Comments

Integrating Twitter into your custom Alexa Skills | Voicebox · June 24, 2018 at 2:57 pm

[…] spreadsheet will become visible at https://docs.google.com/spreadsheets/u/0/ – then, follow THIS tutorial on getting Alexa to say what we […]

Scheduling skill updates and feeds using WordPress | Voicebox · June 25, 2018 at 7:10 pm

[…] For information on getting data from the Google Spreadsheet, see here. […]

Fixing 'there was a problem with the requested skill's response' errors | Voicebox · June 27, 2018 at 8:18 pm

[…] you still can’t fix it, start from scratch with THIS […]

Making API requests with variables in the URL – Voicebox · August 9, 2018 at 12:54 pm

[…] this tutorial assumes you have a basic knowledge of API requests. If not, I recommend that you read this article first for […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.