In this blog we will explain how to use the Skill flow Builder Editor GUI to create, edit, and preview content for your skill. The project can be downloaded here .
Once you open the SFB editor you will see a similar image as above. The main elements you will find are:
Go to “File Menu” or “Project History” and select “New project”. After clicking it you will see a screen like this:
From all the options the most relevant is the type of “Starter Template” Existing templates contain rich samples you can use to build your skill:
We will start our development from scratch. Select “Blank template”, write your project name and project directory, then, click OK.
SFB is organized around the idea of scenes and and we can consider them as the main building blocks. A scene imitates a film or theatrical screenplay, in which the narrative is told through a series of scenes. In a scene, a small portion of the narrative unfolds, through characters, visuals, and sound design. Then, the players makes a decision, speaks that decision to Alexa, and the skill advances to the appropriate scene.
After creating your blank project the editor will open the “Map view” and the “Source view” showing your story.abc file. The node or scene added in this blank template is a special one: @start which is the first scene for a new user to the story or after a restart of the story.
For now we will just focus on the main elements of a scene. Select your start scene in the “Map view” and change the view to “Guided”.
Main elements of a scene are:
For now, let's add 2 scenes that will be connected to our start node. Go to the “Map” view, select the node and click ‘+’ (bottom right corner in the “Map” view), then select the new one and repeat the process. Now you should have 3 scenes connected in your map view as the below image:
Edit the say, recap and reprompt on each scene, and then “Save” the project. If you prefer you can go to the “Source view” and paste the following code:
@start
*say
Welcome to the Skill Flow Builder.
*then
-> learn scenes
@learn scenes
*say
Great! Welcome to the framework! Let's get started.
Scenes are the basic building blocks of a story in the Skill Flow Builder.
They can be connected linearly, branching, looping, or any other way you can think of.
First, you have to give each scene a name. For example, this scene is named 'learn scenes'. This name needs to be unique within your story.
Then, you can give your scene some content. For example, this scene has 'say' content, which you are hearing right now and some 'then' content which tells it where to go next.
*then
-> learn say and reprompt
@learn say and reprompt
*say
Let's learn more about 'say' and 'reprompt' content within a scene.
What you are hearing right now is this scene's 'say' content.
To hear this scene's 'reprompt' try not saying anything...
*reprompt
'reprompt' content is what the player will hear if nothing is said or we didn't understand what the player said.
If you don't provide 'reprompt' content, it will just repeat the 'say' content.
Try saying 'continue' this time.
*then
SFB's hear action allows the skill to select the next scene based on the user’s response. To create one, select the last scene ‘learn say and reprompt’ and go to the guided view, select “Add hear Action” and add the following content (it will add a new scene called ‘learn choices’ that we will use in the next exercise). Then save it.
So far we have added a hear action but you would probably like to add multiple choices and not just one. Go to your new ‘learn choices’ scene and in the “Guided view” add two “Hear actions” (one should go to the scene ‘more on choices’ and the other to ‘learn variables’) . You can copy/paste the following code in the scene:
@learn choices
*say
In the 'then' content, you can tell the scene to go somewhere if it hears something by using the keyword 'hear'.
We've been using this in the previous scenes to listen for the word 'continue' and then -> the next scene.
You can use 'hear' multiple times in order to give players choices.
For example, would you like to learn more about choices or move on to the next topic?
*then
hear learn more about choices {
-> more on choices
}
hear move on to the next topic {
-> learn variables
}
Remember: If the user says an utterance that is not supported in our hear actions, SFB will read the reprompt message and if it's not defined it will repeat the say text again.
SFB is a graph so you can navigate to a scene from multiple nodes . Let’s try it: Go to your new scene ‘more on choices’ and add a “Hear action” to the scene ‘learn variables’.
After completing these steps your “Map view” should look similar to this one:
@more on choices
*say
Players might respond with variations of the command you provide them. You can list multiple variations inline using a comma to separate them.
For example, say 'continue', 'move on', or 'get moving' to continue.
*then
hear continue, move on, get moving {
-> learn variables
}
@learn variables
*say
Great! Sometimes you might want to add or remove items or change some attributes to make your story more exciting.
You can accomplish this in the 'then' content. 'set', 'increase', or 'decrease' a variable.
For example, we set 'antidote' to 0.
Now, we can use this variable in our story. Say 'continue' to find out how.
*then
Terminators , noted as ‘>>*’, are special instructions you can include in your scenes. The most important terminators are:
SFB offers a list of special scenes you can use in your skills. Like any other scene, the scene identifier is unique so you cannot repeat it. The most relevant scenes are:
In the following exercise we will add a global help, repeat, restart and a previous scene handler to our flow (e.g: the user can ask for help in any scene) and we will also add the special scenes @resume, @pause .
1) Open the “Source view”.
2) Copy and paste the following code to add the scenes.
// Played before resuming the skill
@resume
// Triggered on AMAZON.CancelIntent, AMAZON.PauseIntent and AMAZON.StopIntent
@pause
// Appended to all scenes (performed after every scene)
@global append
3) Save the project and switch to “Map view”. You should see something like this:
4) Select ‘resume’ scene. Go to “Guided view” and add to say following test:
“This is a resuming scene. This scene is played when the user re-launches your skill after exiting. Do you want to continue your story from where you last left off?”
5) Add to the scene two hear actions (Utterance: ‘Yes’, action: → Resume; Utterance: ‘No’, action: → Restart) and save the project.
6) Select the Pause scene and add this say message: “Thanks for playing!”
7) Select the @global append scene and add the following hear actions:
- Utterances: restart, start again ; Action: → Restart
- Utterances: repeat, say again, repeat it, what did you say, I didn’t understand ; Action: → Repeat
- Utterances: help, I need help, please help me ; Action: Go to Scene help (help is a new scene)
- Utterances: back, previous, rewind ; Action: → Back
8) Select the new ‘Help’ scene and add this say message: “This is a help message. In this story, this scene is set up to be reachable only through the global scene.”
9) Add an action to the ‘Help’ scene and select ‘Back’.
If you have followed correctly all instructions you source code should include this at the end:
@resume
*say
This is a resuming scene. This scene is played when the user re-launches your skill after exiting.
Do you want to continue your story from where you last left off?
*then
hear Yes {
>> RESUME
}
hear No {
>> RESTART
}
@pause
*say
Thanks for playing!
@global append
*then
hear restart, start again {
// Tell the framework to restart from the beginning
>> RESTART
}
hear repeat, say again, repeat it, what did you say, I didn’t understand {
// Tell the framework to repeat everything the player just heard. You can use >> REPROMPT which only plays the reprompt content
>> REPEAT
}
hear help, I need help, please help me {
-> help
}
hear back, previous, rewind {
>> BACK
}
@help
*say
This is a help message. In this story, this scene is set up to be reachable only through the global scene.
*then
>> BACK
SFB allow developers to collect and use values in their stories. These values can be simple variables representing a number, a string, a predefined enumeration (e.g: names, actors, cities, etc.) or a custom value that developers can define in the “Slot types” (e.g: list of fruits, player classes, etc.).
The simplest way to capture a value is using the command hear and the {slot} value in the utterance. The slot instruction tells Alexa that when we are using {slot} for a hear it should expect to hear a number, string, or an enum (depending on the slot type definition). For example:
slot playerName as 'AMAZON.US_FIRST_NAME'
hear my name is {playerName}, {playerName}, call me {playerName} {
-> learn scenes
}
The above code will tell Alexa that when a user says ‘my name is XXX’ it should expect a name in XXX from the list of available names in the AMAZON.US_FIRST_NAME type. You can select any built-in type (be sure the type is available in your locale) or create your own type.
You can also reference your collected value by using {slot} notation in the say command.
Go to your start node and select the “Source view”, then copy and paste the following code:
@start
*say
Welcome to the Skill Flow Builder. Let's get to know each other.
What is your name?
*then
slot playerName as 'AMAZON.US_FIRST_NAME'
hear my name is {playerName}, {playerName}, call me {playerName} {
-> learn scenes
}
Now we are going to use that value in our say command. Go to the ‘learn scenes’ “Source view” and then replace the content with this:
@learn scenes
*say
Great! Welcome to the framework {playerName}! Let's get started.
Scenes are the basic building blocks of a story in the Skill Flow Builder.
They can be connected linearly, branching, looping, or any other way you can think of.
First, you have to give each scene a name. For example, this scene is named 'learn scenes'. This name needs to be unique within your story.
Then, you can give your scene some content. For example, this scene has 'say' content, which you are hearing right now and some 'then' content which tells it where to go next.
*then
-> learn say and reprompt
“Save” and “Build” the project again.
You can also add a value in the “Guided view” by double clicking the word (without brackets) and selecting “Value”.
To create your own type you need to go to the “Slot type view” (icon ‘?’) under the “Map view”. Then select a “New slot type”:
You can now add values by clicking the ‘+’ button
These slot types can be used in the same way as any AMAZON built in type.
Create a CustomFruitType slot and add ‘pear’, ‘pineapple’, ‘apple’, and ‘orange’ as values.
SFB allows developers to store information about the progress of the story, manipulate that information and make it persistent even after closing the session. Based on the type of value we can classify them in three types:
You can use the variables in your say as explained previously but you can also use them to define navigation logic in your flow using if
Go to ‘learn variables’ scene and modify the code in the “Source view”
@learn variables
*say
Great! Sometimes you might want to add or remove items or change some attributes to make your story more exciting.
You can accomplish this in the 'then' content. 'set', 'increase', or 'decrease' a variable.
For example, we set 'antidote' to 0.
Now, we can use this variable in our story. Say 'continue' to find out how.
*then
set antidote to 0
hear continue {
-> learn conditional
}
We are declaring a numeric variable that will be initialized to 0.
Now add the scene ‘learn conditional’ with the following code:
@learn conditional
*then
if antidote is 0 {
-> antidote zero
}
if antidote is 1 {
-> antidote one
}
-> antidotes
This scene will verify the value of our variable antidote and it will send us to different scenes depending on the value (0, 1 or other). Note that in this scene we didn’t include any say command so in case we resume the skill right here then it will restart in the previous scene ‘learn variables’.
Now complete the code adding the snippet below. If the user leaves the game while in these scenes then the value of the variable antidotes will be kept. If we want to remove the value we need to use the command clear.
@antidote zero
*say
You are hearing this because we detected that you don't have any antidotes.
We used an 'if' statement in the 'then' content to accomplish this. Use a period to close your 'if' statement.
Add an antidote by saying 'add antidote'.
*reprompt
Say 'add antidote.'
*then
hear add antidote, antidote, more antidote {
increase antidote by 1
-> learn conditional
}
@antidote one
*say
You are hearing this because we detected that you now have 1 antidote.
Add one more antidote by saying 'add antidote'.
*reprompt
Say 'add antidote.'
*then
hear add antidote, antidote, more antidote {
increase antidote by 1
-> learn conditional
}
@antidotes
*say
You have {antidote} antidotes.
You are hearing this because the first 2 'if' statements weren't triggered.
When an 'if' is triggered and it has a '->' in it, nothing afterwards is executed.
Try adding one more antidote or say continue to move to next scene.
*recap
You have {antidote} antidotes.
This is the same scene as the one you just heard but you are hearing the recap content instead of the say content.
The 'recap' is played if you have already heard this scene once and can be useful in trimming down long scenes that the user could encounter multiple times.
You can add even more antidotes by saying 'add antidote' or say 'continue' to move on.
*then
hear add antidote, antidote, more antidote {
increase antidote by 1
-> learn conditional
}
hear continue, move on {
-> images
}
The table below describes the syntax you can use in your scenes depending on the types used.
Boolean | Number | String | Enums | |
Declare | * [flag|unflag] <name>. If not declared variable will be set to false. |
* set <name> to <value> | * set <name> as '<value>' | * slot <name> as <slotType> |
Modify | * flag <name> . Set true * unflag <name> . Set false |
* set <name> to <value> * increase <name> by <value> Increase variable <name > by <value> * decrease <name> by <value> Decrease variable <name > by <value> |
* set <name> as '<value>' | |
Logical operands | * <name> is true * <name> is false * !<name> * <name> |
* <name> [<|>|>=|<=|==|!=] <value> * <name> is <value> * !name |
* <name> is '<value>' | * <name> is '<value>' * !name |
Say Reprompt Recap |
{name} | |||
Remove |
clear <name> |
Now that we have covered the most important topics when building a SFB skill we can take a look at how to improve the skill engagement by adding images, music and voices to your skill.
First we will use show which displays the visual components assigned within this section. As this is a basic tutorial we will use the 'default' APL template included in the project.
Go to the ‘images’ scene, go to the “Source View” and then copy and paste the following code:
*say
Skill Flow Builder allows you to show content on supported devices during a scene.
Ready to continue?
*show
template: 'default'
background:'https://m.media-amazon.com/images/G/01/alexa-games/backgrounds/memorystory-gui-1._CB473869069_.png'
image:'https://sfb-framework.s3.amazonaws.com/examples/images/alps.jpg'
title: 'Skill Flow Builder'
subtitle: ''
*then
hear continue, yes, ready {
-> background music
}
This template will create a simple presentation with a title and a background image.
Now we will add a background sound while Alexa reads the say text. To do that we will use the instruction bgm <audiourl> that needs to be included in the then section and it requires Amazon Polly to be enabled in your skill configuration. As Polly is enabled by default in our project we don’t need to worry about it. In addition, you can also use SSML tags in the say section.
Create a new ‘background music’ scene and add this code:
@background music
*say
Skill Flow Builder allows you to mix sounds into the background of a scene
and use SSML in the say section,
like playing a trumpet sound. <audio src='https://s3.amazonaws.com/alexa-ml/testadventureskill/en-US/audio/trumpet_1.mp3' />
Ready to continue?
*then
// BGM requires polly-config enabled from the abcConfig.json
bgm https://alexa-ml.s3.amazonaws.com/sounds/sound-library/EXTRA/Crowd_Cheer_2_LONG.mp3
hear continue, yes, ready {
-> congrats
}
As final step add a last scene named ‘congrats’
@congrats
*say
Congratulations! You have finished the basic tutorial.
There are more features that can be found in the documentation.
Snippets allow developers to provide a shorter syntax for performing common operations in *.abc files. They can be found in the editor with the scissor symbol.
Snippets can be used to shorten the URLs to resources used in your skill such links to audio or image files. To use a snippet, use brackets that enclose the snippet name like [<snippetName>] in any of your skill say, recap, prompt again, or then sections.
To create a snippet:
1. click on “New snippet” button
2. then name it as “trumpet” and add the following ssml code:
3. Then click on “Create”. This code will play a trumpet sound when the snippet is used.
Repeat previous steps and create following snippets:
name | code |
kid | <voice name='Justin'> |
/kid | </voice> |
pause | <break time='1s'/> |
pause for | <break time='$1'/> |
Now lets use our snippets:
Snippets allow you to insert content or markup into your story.
Here are a few common use cases for snippets.
Sound effects [trumpet]
[kid]
Character voices.
[/kid]
Pauses [pause]
And more! Even longer, dramatic pauses, by passing arguments to a snippet.
[pause for 2s]
You can define snippets in the abcconfig file.
Ready to continue?
The updated code should look like this:
@background music
*say
Skill Flow Builder allows you to mix sounds into the background of a scene and use SSML in the say section, like playing a trumpet sound. <audio src='https://s3.amazonaws.com/alexa-ml/testadventureskill/en-US/audio/trumpet_1.mp3' />
Ready to continue?
*then
// BGM requires polly-config enabled from the abcConfig.json
bgm https://alexa-ml.s3.amazonaws.com/sounds/sound-library/EXTRA/Crowd_Cheer_2_LONG.mp3
hear continue, yes, ready {
-> snippets
}
@snippets
*say
Snippets allow you to insert content or markup into your story.
Here are a few common use cases for snippets.
Sound effects [trumpet]
[kid]
Character voices.
[/kid]
Pauses [pause]
And more! Even longer, dramatic pauses, by passing arguments to a snippet.
[pause for 2s]
You can define snippets in the abcconfig file.
Ready to continue?
*then
hear continue, yes, ready {
-> congrats
}
As you have noticed one of the snippets we created is using ‘$1’ that is the way we pass parameters (“2s”). This can be really useful when we want to reuse code in the .abc file. There is no limit of the number of parameters, just ensure you define them in your snippet code ($1, $2,$3, etc.)
Finally there is a predefined variable you can use in your code to substitute your skills default content URL: $SNIPPET_S3_RESOURCES_URI. For example, this code <audio src='$SNIPPET_S3_RESOURCES_URI/audio/$1'/> will be replaced during runtime/simulate by this one: sfx": "<audio src='https://s3.amazonaws.com/alexa-ml/testadventureskill/en-US/audio/$1'/>.
Note: This special variable replacement can also help with content localization of audio/images files, as the generated URL contains the locale in the generated URL.
We have completed our skill and we want to see how it works . Before we try it out please save your project and check there is no error message.
Once saved, select one scene in your “Map view” (e.g: background music) and click the tab “Simulate” (play icon). You should see an image like this:
Select “Simulate from Current” (this may take several seconds till SFB prepares the code and audio) and then you will see this image:
From the “Simulate View” you will be able to navigate to any of the available scenes (e.g hear options: ‘continue’, ‘restart’, ‘repeat’, etc) by clicking one of the buttons. If you have variables and images you will also see them in the “Simulate view”.
If you have errors opening the “Simulate view” or is not refreshed go to “File”→“Troubleshooting”→“Clear Voice Preview Cache” and try it again.
In this basic tutorial, we learnt the basics of Skill Flow Builder editor and how to use this powerful tool to create engaging stories for your customers. In order to get started you can check the resources aboves, and star building your own projects!