How to design & code Alexa skills
Before we begin the journey into this wonderful space, let’s go back in time and look at where all things were to be done manually though it be playing your favourite music or setting up your to-do list or setting a routine through touch. But in this contemporary world why would you want to tap on a phone screen when you can have your voice assistant to use your voice.
The fact that these still have value stands as a tribute to their effectiveness and capabilities for the daily tasks. But having something as good and effective as this conventional approach could be voice & we do have a clear understanding that today’s needs can’t only be solved by touch having something as good & effective as this conventional approach could be beneficial & having voice assistants like Alexa, Siri & google assistant it becomes increasingly obvious that we are moving beyond the capabilities with these best-of-class enterprise services.
Building skills into Alexa:
Although Amazon Alexa wasn’t first to the voice assistant market (it was preceded by Siri, Cortana and Google Now), it has taken the market by supporting developers. Contrastingly, Siri allows third party development only in narrow categories. Cortana and the newer Google Assistant are also now in catch-up mode. The good news for is this competition is fueled by billions of dollars of R&D, which stimulates innovation in voice at breakneck speed.
How to develop an alexa skill?
Prerequisite: Amazon developer account
Sign in into Amazon developer services & click on Alexa.
Click on create Alexa skills which will render the screen as below.
Clicking on Console will direct you to the Alexa console which lists all the skills you have created.
You can directly come to this page through https://developer.amazon.com/alexa/console/ask
By clicking Create Skill, you will be required to fill certain fields like
- Skill name : The name you wish for your skill.
- Primary locale : The primary language you would like for your skill.(English-UK, English-US, English-AU, English-CA, English-IN,German-DE , Spanish-ES,Spanish-MX, Spanish-US,French-FR, French-CA, Italian-IT, Japanese-JP, Portuguese-BR, Hindi-IN, Arabic-SA).
- Model for your skill : There are many ways to start building a skill, we can either use the predefined models (Flash briefing, smart home, music, video, knowledge, meetings) or use our own custom. In our example we will be creating our model.
- Method for your backend resources : Depending about the available backend resources, we can either use Alexa hosted or provision our own. In our case, we will be going with Alexa hosted skill using node js.
- Region : Any of the AWS regions, we will be moving forward with us-east-1 (N. Virginia).
I would be creating a coffee server skill where the user is asked about the order they would like.
At the skill’s dashboard:
Set skill invocation name as “coffee mate”.
We will be having custom intents, slots as per our requirement.
Intents like
(A) getOrderIntent : -
As the name suggests, it’s an intent which will be invoked to get the order from the user.
Utterance like
- {coffee}.
- I would like {coffee} in {addon}.
- I would like {coffee} in {flavour}.
- I want {coffee} in {flavour} flavour with {addon} addon.
- I want {coffee} in {flavour} flavour.
- I will have {coffee} with {addon} addon.
- I will have {coffee}.
- Hello.
{coffee}, {flavour}, {addon} are the slots for this intent.
will invoke this intent
(B) getExitIntent : -
As the name suggests, it’s an intent which will be invoked when the order is placed & to know whether the user would like to place some another order or would like to leave.
Utterance like
- {yesNo} thank you
- {yesNo} i will not
- {yesNo} I will
- {yesNo}
{yesNo} are the slots for this intent.
will invoke this intent
Slots types :-
- addons
Slot values :
1. old brew
2. pour over
3. drip
4. aeropress
5. french press
6. soy milk
7. almond milk, - coffeeTypes
slot values :
1. irish
2. mocha
3. black
4. arabica
5. espresso
6. americano
7. cappuccino
8. latte - flavours
slot values :
1. caramel
2. french vanilla
3. dark chocolate
4. cocoa
5. hazelnut, - yesOrNoType
slot values :
1. yes
2. no
Coming to the custom slots, it is advisable to have the custom slot values in lowercase, since when you interact with Alexa, Alexa will process the information through lowercase only. Also you can use inbuilt slot types too depending upon your use(you can find more information on Alexa slot types).
At this moment, we are left with validations about the intents, slots i.e the delegations (flow), if some required fields exists then only a order can be placed.
All the 4 slots are required to be filled & based on those validations, delegation flow will be maintained.
- coffee
- addon
- flavour
- yesNo
After adding invocation name, intents, slots & their validations, our interaction model should look like
- en-US.json:
Moving from build to code i.e coming to the back-end , what business logic to perform when the skill is invoked.
The code is available at my git hub account. You can directly download the zip file & export the zip file to you your Alexa developer console.
Skill parameters:
Invocation name: Coffee mate
To place an order you can speak phrases like
- coffee_name.
- I would like coffee_name in addon_name.
- I would like coffee_name in flavour_name.
- I want coffee_name in flavour_name flavour with addon_name addon.
- I want coffee_name in flavour_name flavour.
- I will have coffee_name with addon_name addon.
- I will have coffee_name.
- Hello.
Since for a coffee, a coffee type, its add on & flavour are mandatory, incase you miss on something you will be asked the item you would have missed.
Coming to the actual results, after performing various debugging techniques & hassles of solving errors, the result obtained.
You can test this skill on any Alexa compatible device , Alexa simulator in Alexa developer console, Alexa app on android or iOS but do make sure that you have enabled the testing it in development mode.
Here are the testing results.
Test 1:
Where I give instructions one by one the way alexa responds
Test 2:
Where I give instructions in a predefined way & responds to Alexa by myself
Happy coding! Let me know your insightful thoughts in the comments. If you liked what your read please give it a clap and follow us for more articles. Also If you need any help feel free to be in touch with us and turn your idea into a brilliant solution together.
You can connect me over linkedin or send in respone for more alexa skills