DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Building Conversations With Alexa

Alexa skills have a lot of moving parts, but prompting users for more information, establishing a Dialog, doesn't have to be complicated.

Lorna Mitchell user avatar by
Lorna Mitchell
·
Jun. 27, 17 · Tutorial
Like (3)
Save
Tweet
Share
8.60K Views

Join the DZone community and get the full member experience.

Join For Free

Having an Amazon Echo Dot in my office is quite fun, and I've accidentally started writing more skills and giving a few talks about building skills for the Alexa toolchain. Today, I created a skill that uses multiple steps to make a conversation and thought I'd better write down what I did so I'd be able to remember!

The basic idea is that when creating the "intent", i.e. the action that you want Alexa to do, you also define "slots". The slots are the variables; if this were a command line tool, they'd be the arguments you typed. It's possible to include both intent and slots in your wording when you speak to Alexa, but equally, you can just invoke the skill and have it prompt you for the rest of the information.

Prompting the User for Information

This model of having multiple steps in the exchange between the human and Alexa is what Amazon calls a "Dialog", and to define this, you need to use their new graphical skill builder tool rather than just a JSON structure describing your intents and slots (a bit tedious for those of us who struggle with graphical interfaces). When you add a slot, you can specify the data type and the "prompt", so the words that the device will say when asking the human to supply the information. You can have one or many of these. In the request object that arrives when the skill is invoked, you should also see a dialogState element has appeared.

If this says STARTED, then you can ask Alexa to go ahead and prompt for the information from the user by sending a Dialog.Delegate directive (note that you must not send output speech with this directive, it gets upset). Once all the slots are filled, you'll get another IntentRequest and the dialogState will say COMPLETED. At this point, you should have all the information you'd need to figure out a response and send it back.

Dynamic User Prompts

Sometimes, we don't want to use automatic wording. For example, I have a skill that challenges the user to answer a simple math question — so the user input still needs to go into a slot, but I need to ask a different question every time. For that, we can use the Dialog.ElicitSlot and send some output speech to use as the prompt. Here's the response I send to achieve this:

{
   "outputSpeech":{
      "type":"PlainText",
      "text":"Ready? What is 4 plus 5?"
   },
   "directives":[
      {
         "type":"Dialog.ElicitSlot",
         "slotToElicit":"Number"
      }
   ],
   "shouldEndSession":"false"
}


Using this approach, you can nominate whichever slots up front, and then prompt the user as appropriate, either using predefined wording or using your application to create and prompt. Once I understood how all the moving parts worked, this was fairly simple to get working, so hopefully it helps someone else get quickly started to making something awesome too!

Conversations (software)

Published at DZone with permission of Lorna Mitchell, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Bye-Bye, Regular Dev [Comic]
  • Top Three Docker Alternatives To Consider
  • Top 5 Java REST API Frameworks
  • What Was the Question Again, ChatGPT?

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: