Message:

Subscribe rss
Blog categories
All | Backendless features
Developing an Alexa skill without writing any code – Part 2 (Intents and Slots)
December 21, 2017 by markpiller

This is Part 2 of the article about developing an Amazon Alexa skill without any coding. In Part 1 you learned the following:

  • How to create a Codeless API Service responsible for handling Amazon Alexa requests. The service completely removes the need for adding AWS Lambda functions, it also runs without any cost in the free plan of Backendless.
  • How to create a Codeless custom function which composes a response back to Alexa.
  • How to create a basic Alexa Skill and test it from the Amazon developer console.
  • How to invoke the skill on Alexa, process the invocation in your Codeless Backendless API service and get a response back on Alexa.

In this part of the article, you will learn the following:

  • Creating voice interaction model with “slots” – special placeholders for the “dynamic” parts of the requests for your skill
  • Processing slots in the Codeless API service in Backendless.
  • Executing codeless logic to do something useful and generate a meaningful response.

It is recommended (more like required) to go through Part 1 just so you have the basic environment setup. Also, make sure to watch the “Developing an Alexa Skill without any coding” video which shows the entire process in action.

Interaction Model Slots

  1. To get started, login to your Amazon Developer Portal account and click the Alexa menu. Locate the skill you created in Part 1 and click the “edit” link.
  2. Click the “Interaction Model” section. You will be editing the Intent Schema of your skill. The modified schema looks as shown below:

    Notice the new intent called "Table" . The intent defines the "slots"  array with one slot in it:

    The slot name is "TableName"  and the type is "BackendlessTable" . Now that you see an example of a slot in the intent schema, let’s put it into the perspective. From the video, you might remember I was asking Alexa:

    “how many objects are in the Users table”

    The name of the table here is dynamic, I could have asked about the Person table or any other table for that matter. Slots in the intent schema is what makes it possible. Think about slots as the arguments for an intent.

    To complete slot definition, you need to define its type and include the slot in the Sample Utterances (see the instructions below).

  3. The type for the   "TableName"  slot is  "BackendlessTable" . Use the form located under the Intent Schema field to create a type definition. Enter the data as shown in the image below and click Add when done.
    slot type definition - Developing an Alexa skill without writing any code – Part 2 (Intents and Slots)Once the slot type is added, it should appear as shown below:
    added slot type - Developing an Alexa skill without writing any code – Part 2 (Intents and Slots)
  4. The final step in configuring the skill is updating the sample utterances. These are the phrases the user of your skill may use to invoke it. Locate the Sample Utterances field and update it to contain the following:

    Notice how the phrases start with the name of the intent and reference the slot by the same name as it is defined in the intent schema: {TableName} .

    When you are done, that section of the screen should look as in the image below:
    sample utterances - Developing an Alexa skill without writing any code – Part 2 (Intents and Slots)

  5. Click the Save button at the bottom of the screen. Amazon will perform an update and the Alexa Skill part is ready. The next step is to add the logic for processing the requests on the Backendless side.

Processing Intents and Slots

  1. Login to Backendless Console, select your app and switch to the Business Logic section. Click the CODELESS tab to switch to the Codeless editor.
    codeless tab - Developing an Alexa skill without writing any code – Part 2 (Intents and Slots)
  2. In Part 1 of this article, you already created a custom function called sendAlexaResponse . In this part, you will create two additional custom functions. One will be used to get the name of the intent from the incoming request and the other is to get a slot value. Click the Add New link under Functions as shown below:
    add new function - Developing an Alexa skill without writing any code – Part 2 (Intents and Slots)
  3. Codeless creates a default function placeholder which you will use to define a new function. Make the changes as shown in the image below:
    declare codeless function - Developing an Alexa skill without writing any code – Part 2 (Intents and Slots)
    Specifically, the changes are:
    1. Change the function name to getIntentName .
    2. Click the gear icon.
    3. Drag the input name  block int the inputs  block.
    4. Change the input name from x  to request .
  4. The function definition is ready, now you can add the logic to the function. The logic will be responsible for retrieving the intent name from the request. Modify the function’s logic as shown in the image below:
    getintentname function - Developing an Alexa skill without writing any code – Part 2 (Intents and Slots)
  5. Click the SAVE button to save the function:
    save function - Developing an Alexa skill without writing any code – Part 2 (Intents and Slots)
  6. The next step is to create a custom function responsible for getting the slot value. Create a new function using the same process as described above. The function definition must be as shown below:
    getslotvalue declaration - Developing an Alexa skill without writing any code – Part 2 (Intents and Slots)
  7. Add the logic to the getSlotValue function so it is identical to the one shown below:
    getslotvalue logic - Developing an Alexa skill without writing any code – Part 2 (Intents and Slots)Unlike anything you have done before, this logic uses variables intent , slots , slot and result . Variables can be created using the Variables section of the Codeless toolbar:
    creating vars - Developing an Alexa skill without writing any code – Part 2 (Intents and Slots)
  8. Make sure to save the function when it is created. At this point the functions are ready and you can proceed with the main logic of the API service.

API Service for the Alexa Skill

  1.  In part 1 you already created a basic service for the Alexa skill. The service returned a constant string value. The logic to handle a request with dynamic parts (slots) is quite different. To locate the existing method, expand the AlexaService  node and click the handleRequest  method:
    handle request method - Developing an Alexa skill without writing any code – Part 2 (Intents and Slots)
  2. Remove any codeless blocks you already had in the method as you’d be starting with a blank logic. Compose the logic as shown below:
    handleRequest tablesize - Developing an Alexa skill without writing any code – Part 2 (Intents and Slots)
  3. Click the DEPLOY MODEL button when you are done. Once the service is deployed, you can test your Amazon Alexa skill. To do this, simply ask:

    where my demo  is the skills’ invocation name configured in Amazon Developer Portal (see the Skill Information section):
    invocation name - Developing an Alexa skill without writing any code – Part 2 (Intents and Slots)

Happy Codeless Coding!

Share this post
Tweet about this on TwitterShare on FacebookGoogle+