Alexa skill - how to invoke Alexa intent skill with a number - alexa

Newbie -- trying to figure out how to implement in Alexa skill that just jumps right in. Eg. say, a pizza finder skill:
e.g.
User: "Alexa run Pizza Finder"
Alexa: "OK, what's your zip code?"
User: 98132
Alexa: Thanks. If you want me to find the closest pizza store, tell me your address. Otherwise, I can give you ad list. Just say "give me a list".
So right now I have the launchIntent say "OK what's your zip code".
But I can't figure out how to launch the "findPizzaStoreIntent" just by having somebody say a "98132".

Related

Make Alexa Skill Slot accept any word user says

I was wandering if there is a way to make custom Alexa Skill slot accept any word user can say.
I need it to detect a name of a user device. User can name his device how he wants (person name, thing name, singer name and so on...) so there isn't a default slot can help me.
You can use AMAZON.SearchQuery for that case. Once upon a time there was AMAZON.Literal, but it's depricated now.

How to make a single intent match with multiple text lines sent by the user in DialogFlow?

I need help with this issue:
DialogFlow matches the user text block to an intent in order to retrieve an answer. Some users do not type everything in just one block of text, for example:
"Hello! My name is Ane. How can I order a pizza from here?"
Instead, they do:
"Hello!"
"My Name is Ane"
"How can I order a pizza from here?"
Each time the user sends a text, the DialogFlow try to match each sentence to an intent. There's some way to make DialogFlow wait a few seconds before match to an intent or put all this lines together or some way around this problem?
I think you should use followup intents in this case.
Take a look at https://cloud.google.com/dialogflow/docs/contexts-follow-up-intents

Accept any user input for Alexa Custom Skill, but include only part of that input in confirmation

I'm trying to build a custom Alexa skill for a gratitude diary. The goal is to have an interaction in which the Alexa device asks the user what they're grateful for, and repeats it back as confirmation.
I'm encountering a problem when it comes to repeating back what the user has said. I'd like the conversation to go like this:
Alexa: What are you grateful for today?
User I'm grateful for dogs
Alexa: You said you're grateful for dogs. Is that correct?
I've set this up as a single intent, as follows:
gratitude_object as a required slot, of type AMAZON.SearchQuery
user utterances for this slot are I'm grateful for {gratitude_object} (and a few variations)
confirmation message for this slot is You're feeling grateful for {gratitude_object}. Is that correct?
The problem I'm encountering is that when I test this model in the Utterance Profiler, it goes like this:
Alexa: What are you grateful for today?
User I'm grateful for dogs
Alexa: You said you're grateful for I'm grateful for dogs. Is that correct?
I'm guessing this is something to do with the fact that AMAZON.SearchQuery will accept anything as valid input, but I'm not sure how to go about resolving this.
I've also tried creating a custom slot for the I'm grateful for phrase:
slot name: gratitude_phrase_initiator
slot type: custom slot type
slot values: "I'm grateful for", "I am grateful for" (etc)
However, if I then try to use this slot in my intent, by making the user utterance for the gratitude_object slot:
{gratitude_phrase_initiator} {gratitude_object}
...then I get the following error:
Sample utterance "{gratitude_statement_initiator} {gratitude_object}" for slot "gratitude_object" in intent "NewEntryIntent" cannot include both a phrase slot and another intent slot. Error code: InvalidSlotSamplePhraseSlot
.
I'd really like to keep the interaction as it is currently, with the user starting by saying "I'm grateful for...". Any suggestions for how I could make this work using the interaction model, or is it just impossible? Is this something I could handle in the code instead of the interaction model?
Looks like you set it up perfectly but you would expect SearchQuery to do a better job of excluding the initial utterance phrase. So you'll have to parse it some more in code. You should use a Lambda Function to string replace the slot value to remove any initial phrases.
Example in Node.js:
var gratitude_object = this.event.request.intent.slots.gratitude_object.value;
var initial_phrases = [
"i'm grateful for",
"i am grateful for",
];
initial_phrases.forEach(function(value){
gratitude_object = gratitude_object.toLowerCase().replace(value,"");
});
Notice the array of intitial phrases are written in lowercase and the forEach loop also makes the slot value lowercase before checking to replace. That way you don't have to worry about case matching when writing the initial phrases you want to remove.

Alexa Skill - How to get complete text of statement asked to alexa

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
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 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.
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"
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
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.
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.
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.
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."

Alexa getting response from user after prompt

So we are setting up a system in which a user can set reminders. Currently my intent is set up to provide a Day and a Time. If I say something like set reminder for next tuesday at 9pm, in my intent I see the values coming in fine. The issue is if let's say they say something like set reminder for next tuesday, they gave us the day but not time. So in my intent, I have this response:
else if(obj.Day.value && !obj.Time.value) {
this.response.speak(`Looks like you requested a reminder on ${obj.Day.value}, what time would you like the reminder set for?`).listen('Thanks');
console.log(JSON.stringify(this.response, null, 2));
this.emit(':responseReady');
}
The issue I am having is... how do I get what they said? I've also tried this.emit(':ask', '...') but I still don't see what they actually say.
I'm sorry if this is confusing, essentially this is a simplified question.
How do we get the response from the user (for missing information) after Alexa asks something in an intent?
For this, you will want to use the elicitSlot Directive. Docs found here.
Try:
this.emit(':elicitSlot','slotName','intentName');
Alexa will know that you want to fill the next user's response to the Time slot, if you put "Time" into the slotName property above.
In the Alexa Console, you can specify how Alexa should elicit that slot. You can even provide multiple ways of asking and Alexa will choose one.

Resources