4
votes

I'm trying to write my first Alexa skill, but the application flow is a bit confusing, even reading all the documentation about dialogue delegation etc etc. I'd really love a bit of advice.

The Flow I'm Pursuing

"Alexa, start Movietime Quiz."

Welcome to Movietime Quiz. Before we begin, what team are you on: red or blue?

"Blue."

Blue was always the best team. Question 1: which of these films was not directed by Alfred Hitchcock? A: Vertigo, B: Rope, C: Happy Gilmore.

"C."

Correct! 10 points to the blue team. Question 2...

This is a boiled-down example to illustrate my problem in the shortest, clearest way, before you wonder why teams need to be involved in this.

My Instinct/Naive Approach

Have the initial launch-request handler say welcome-and-what-team, and then have two intents. The first would obviously be AnswerQuestionIntent, which listens for "A", "B", "C" or "D." The second would be SetTeamIntent, which listens for "red" or "blue."

I'd have an array with ~100 trivia questions. When the game starts, set a session attribute 'currentQuestion' to 0. In AnswerQuestionIntent, after handling the user's correct/incorrect response, increment that number, and if it's at 9, end the game; if not, ask a random question.

My Problem

I can't actually figure out how to have Alexa use a single slot as an utterance. I mean, I'd want to have a 'team' slot type (values 'red' and 'blue') and an 'answer' slot type (values 'A', 'B', 'C', and 'D'). SetTeamIntent should be activated by the utterance {team} and AnswerQuestionIntent by {answer}, but the developer.amazon.com skill builder gives me 'Bad Request' errors when I try to set that.

I tried looking at the SDK examples on GitHub, but I'm a bit lost because I've been using the GUI skill builder while learning and am not sure exactly how it maps -- not well enough to read the solution, anyway.

1

1 Answers

1
votes

There is two different ways to handle this.

1. ElicitSlot Directive WITH Dialog Model

After you launch your skill and trigger an intent you can respond with a elicitslot directive.

Interaction Model: You define a slot and an intent, for example {team} and {answer} in PlayGameIntent. Provide utterances for the intent to get triggered, for example "start a game".

Skill: After triggering the PlayGameIntent. Return a response with a elicit slot directive. Something like the following.

{
  "version": "1.0",
  "sessionAttributes": {},
  "response": {
    "outputSpeech": {
      "type": "PlainText",
      "text": "What team are you on? Blue or Red? "
      },
    "shouldEndSession": false,
    "directives": [
      {
        "type": "Dialog.ElicitSlot",
        "slotToElicit": "team",
        "updatedIntent": {
          "name": "PlayGameIntent",
          "confirmationStatus": "NONE",
          "slots": {
            "team": {
              "name": "team",
              "confirmationStatus": "NONE"
            },
            "answer": {
              "name": "answer",
              "confirmationStatus": "NONE"
            }
          }
        }
      }
    ]
  }
}

The User can now provide an answer for the slot {team} and Alexa sends another IntentRequest for PlayGameIntent. You reelicit as many times as you need until your game is finished.

2. Custom Intents WITHOUT Dialog Model

Without using the Dialog Model you have no restriction with only-slot-utterances. You can build your intent schema as you described. If you leave the Skill Builder Beta you automatically disable the Dialog Model for your Interaction Model.

You can then build an intent schema with sample utterances like this:

AnswerQuestionIntent {answer}
SetTeamIntent {team}