How to design & code Alexa skills

Rajan Shah
AppGambit
Published in
6 min readJul 19, 2022

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.

Amazon developer services
Amazon Alexa voice AI

Click on create Alexa skills which will render the screen as below.

Alexa Skills kit

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

  1. Skill name : The name you wish for your skill.
  2. 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).
  3. 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.
  4. 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.
  5. 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:

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

  1. {coffee}.
  2. I would like {coffee} in {addon}.
  3. I would like {coffee} in {flavour}.
  4. I want {coffee} in {flavour} flavour with {addon} addon.
  5. I want {coffee} in {flavour} flavour.
  6. I will have {coffee} with {addon} addon.
  7. I will have {coffee}.
  8. 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

  1. {yesNo} thank you
  2. {yesNo} i will not
  3. {yesNo} I will
  4. {yesNo}

{yesNo} are the slots for this intent.

will invoke this intent

Intents of our skill

Slots types :-

  1. addons
    Slot values :
    1. old brew
    2. pour over
    3. drip
    4. aeropress
    5. french press
    6. soy milk
    7. almond milk,
  2. coffeeTypes
    slot values :
    1. irish
    2. mocha
    3. black
    4. arabica
    5. espresso
    6. americano
    7. cappuccino
    8. latte
  3. flavours
    slot values :
    1. caramel
    2. french vanilla
    3. dark chocolate
    4. cocoa
    5. hazelnut,
  4. 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).

Intents of our skill
Custom slot types of our skill

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.

  1. coffee
  2. addon
  3. flavour
  4. yesNo

After adding invocation name, intents, slots & their validations, our interaction model should look like

  1. en-US.json:
interaction model / JSON editor : 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.

package.jsonpackage.json
index.js

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

  1. coffee_name.
  2. I would like coffee_name in addon_name.
  3. I would like coffee_name in flavour_name.
  4. I want coffee_name in flavour_name flavour with addon_name addon.
  5. I want coffee_name in flavour_name flavour.
  6. I will have coffee_name with addon_name addon.
  7. I will have coffee_name.
  8. 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 1

Test 2:
Where I give instructions in a predefined way & responds to Alexa by myself

Test 2

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

--

--

Rajan Shah
AppGambit
0 Followers
Writer for

I really feel like I needed to come here.