I want to accomplish the following scenario: A small dialog between Alexa and the user, with the following 2 Intents:
NameIntent
: "My name is{name}
"
Where {name}
is AMAZON.US_FIRST_NAME
and with the slot made required and a prompt defined.
ActivityIntent
: "I like{activity}
"
And here it becomes more difficult. I made {activity}
a custom slot and defined some values for it like "fishing, sports" and the like, but obviously there are more answers to this. If I now respond with something I don't have defined (e.g. "darts"), Alexa always goes back to the first intent, as it seems to thing it is a name.
Example:
LaunchRequest: "Welcome. What is your name?" -> My name is Peter
NameIntent: "Welcome Peter. What do you like to do?" -> Darts -> "Welcome Darts. What do you like to do?"
I would simply like to have Alexa accept whatever value the user says there, in Dialogflow this would be simply done with an {any} entity. I followed this blog article from the alexa blog, and there they seem to be able to capture whatever nickname you throw at it, even ones which aren't defined, which is what I want to accomplish here.
Question: How can I capture any kind of input with Alexa, phrases beyond whatever I have defined in the skill builder? How can I make sure this phrase gets directed to the correct intent?
I am a bit frustrated with this, especially if you use ElicitSlotDirectives
to specifically ask the user about a slot, and then it jumps to a completely different intent.
The code for the 2 intent handlers:
const NameIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'NameIntent';
},
handle(handlerInput) {
const { intent } = handlerInput.requestEnvelope.request;
const name = intent.slots.name.value;
const speechText = `Welcome ${name}. What is your favourite activity?`;
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.withShouldEndSession(false)
.getResponse();
},
};
const ActivityIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'ActivityIntent';
},
handle(handlerInput) {
const { intent } = handlerInput.requestEnvelope.request;
const activity = intent.slots.activity.value;
const speechText = `You like ${activity}.`;
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.withShouldEndSession(false)
.getResponse();
},
};