8
votes

I am creating an Alexa skill, I have coded several custom and default intents and they are working fine.

Now I want to write a fallback intent wherein I want to get the exact statement asked/sent to Alexa skill, is there a way wherein we may get the entire question string/text that has been asked to Alexa skill. I know we can get slot values and intent information, but I need the entire text statement sent to skill.

Thanks

4

4 Answers

3
votes

Well, I had faced the same issue. After trying several methods, I have got the complete text of the statement asked Alexa.

You have to make the following setup in your Alexa skill (name of intent, slot name, and slot type you can choose as per your need)

Setting up Intent

Setting up Intent

Setting up custom slot type

Setting up custom slot type

After setting up your Alexa skill you can invoke your skill, keep some response for launch request and say anything you want, you can catch the entire text as shown here.

"intent": {
            "name": "sample",
            "confirmationStatus": "NONE",
            "slots": {
                "sentence": {
                    "name": "sentence",
                    "value": "hello, how are you?",
                    "resolutions": {
                        "resolutionsPerAuthority": [
                            {
                                "authority": "xxxxxxx",
                                "status": {
                                    "code": "xxxxxxx"
                                }
                            }
                        ]
                    },
                    "confirmationStatus": "NONE",
                    "source": "USER"
                }
            }
        }

Note*: In this method you will need to handle utterances properly if there are more than one intent.

2
votes

There's no way to get the whole utterance straight from a top level intent. Right now the closest you can get is using a custom slot with type AMAZON.SearchQuery (not a custom type as suggested in another answer) but you will have to define an anchor phrase in your utterance that goes before the slot. For example, you would define an utterance like:

search {query}

where query is a slot of type AMAZON.SearchQuery.

The anchor search in the utterance is mandatory (a requirement of the SearchQuery type), so as long as the user starts the utterance by saying search, anything that follows will be captured which is pretty close to what you want to achieve.

Having said that there's actually one indirect way to approximate capturing the whole utterance the user is saying (filtered by NLU) leveraging AMAZON.SearchQuery but only as part of an ongoing dialog using Dialog Management. If you're engaging in a dialog of this kind where Alexa automatically uses defined prompts to solicit slot information you can define an utterance that is a single isolated slot of type AMAZON.SearchQuery with no anchor. Example:

Alexa: Ok, I will create a reminder for you. Please tell me the text of the reminder

User: Pick of the kids from school

Alexa: Ok. I will remind you to Pick up the kids from school

In the example above Alexa detects that the user wants to send a reminder but there's no reminder text set up so it elicits the slot. When you, as a developer, define the prompts that Alexa needs to ask you also define the possible reponses. In this case you can define a response utterance as just:

{query}

and capture the whole thing the user says in response to the prompt, like e.g. "pick up the kids from school"

-1
votes

The English US language has a Slot Type called AMAZON.LITERAL that lets you capture the exact phrase or sentence used (depending on how it's used in your utterance). This Slot Type, however, isn't available in other regions.

Amazon also don't recommend using it:

Although you can submit new and updated English (US) skills with AMAZON.LITERAL, custom slot types provide better accuracy than AMAZON.LITERAL in most cases. Therefore, we recommend that you consider migrating to custom slot types if possible. Note that AMAZON.LITERAL is not supported for any language other than English (US).

See: https://developer.amazon.com/docs/custom-skills/literal-slot-type-reference.html

-1
votes

There once used to be a slot type called Amazon.LITERAL, that was allowed to be used in specific regions. However, it has now been either deprecated (or removed). There is however another solution to this problem using custom slots.

Let's say we are creating a Food Ordering System on Alexa. A skill for something like Zomato or Yelp for Alexa. Let us give the skill the invocation name robert.

So first we make a list of the type of statements which are going to be made. You can skip this step if your skill isn't this specific. However, this just helps you define the type of statements your skill might expect to encounter.

  • Alexa order robert to send me a chicken steak with mashed potatoes.
  • Alexa ask robert to recommend me some good Indian restaurants near me.
  • Alexa please tell robert to rate Restaurant XYZ's recent delivery with a single star.

After we have made a list of statements we store them in a csv file. We go ahead and click on the Add button beside Slot Types. Give your Custom Slot Type a name. Name Your Custom Slot Type Now once you are done with this, come up with the list of constructs in which your skill can be invoked. Some of them have been given below.

  • Alexa ask robert to ...
  • Alexa make robert ...
  • Alexa order robert to ...
  • Alexa tell robert to ...

The three dots (...) represent the actual part of the order/statement. This is the text which you are interested in extracting. An example would be; for the statement,

Alexa ask Robert to send me a bucket of chicken nuggets.

you would be interested in extracting only the portion in bold.

Now Amazon classifies statements based on intent. They have five default, predefined intents for Welcome, Cancelling, Help and other basic functionalities. We go ahead and create a custom intent for dealing with the mainstream statements that will be used to primarily interact with our skill. Create Custom Intent

Under the new Custom Intent Window, at the bottom of the page is the space to add slots which will be used in your intent. We add our previously created custom slot and name it literal. (You can name it anything) The custom slot, literal in our case, is the text we want to be extracted out of the user's statements. Now we go ahead and replace the three dots (...) in the list of constructs with {literal} and add it to the list of sample utterances.

Add Custom Slot and Sample Utterances to the Custom Intent

For the statement

Alexa order robert to send me a chicken steak with mashed potatoes.

The JSON would contain a section like this for the custom intent and highlighting the custom slot text.

"request": {
    "type": "IntentRequest",
    "requestId": "",
    "timestamp": "2019-01-01T19:37:17Z",
    "locale": "en-IN",
    "intent": {
        "name": "InteractionIntent",
        "confirmationStatus": "NONE",
        "slots": {
            "literal": {
                "name": "literal",
                "value": "to send me a chicken steak with mashed potatoes.",
                "resolutions": {
                    "resolutionsPerAuthority": [
                        {
                            "authority": "",
                            "status": {
                                "code": ""
                            }
                        }
                    ]
                },
                "confirmationStatus": "NONE",
                "source": "USER"
            }
        }
    }
}

Under the slots subsection under the custom intent we have our literal slot whose value gives us the text of the user's speech.

"slots": {
        "literal": {
            "name": "literal",
            "value": "to send me a chicken steak with mashed potatoes."