I am new to programming for Amazon Echo. I am using Node.js and am trying to return a different response based on my utterance of a name.
For example if I say the name "David" or "James" or "Benjy" Alexa should just say "Welcome [and the name I said]" but if I say "Jonathan" it should say "Yay! Welcome home Jonathan".
But when I say "Jonathan" it just says "Welcome Jonathan".
I have been modifying the basic alexa-skills-kit-color-expert Lambda and have modified the setColorInSession() function in that code. I have renamed that function setAndWelcomePerson().
I have tried:
- to use an if statement to test my utterance and have Alexa reply based on my utterance
- to give different examples of utterances to try to teach Alexa to differentiate between one name and the next.
None of this seems to work. Please tell me what I'm doing wrong and suggestions to fix. Some code below:
The setAndWelcomePerson() function from my Lambda code:
/**
* Sets the name of the person(s) and welcomes them.
*/
function setAndWelcomePerson(intent, session, callback) {
var cardTitle = intent.name;
var whoToGreetSlot = intent.slots.Person;
var repromptText = null;
var sessionAttributes = {};
var shouldEndSession = false;
var speechOutput = "";
if (whoToGreetSlot) {
var whoToGreet = whoToGreetSlot.value;
sessionAttributes = createWhoToGreetAttributes(whoToGreet);
if (whoToGreet === "Jonathan") {
speechOutput = "Yay! Welcome home " + whoToGreet + "!";
} else {
speechOutput = "Welcome " + whoToGreet + ".";
}
} else {
speechOutput = "I'm not sure who you want me to welcome. Please try again.";
}
callback(sessionAttributes,
buildSpeechletResponse(cardTitle, speechOutput, repromptText, shouldEndSession));
}
My intent schema:
{
"intents": [
{
"intent": "WhoShouldBeGreeted",
"slots": [
{
"name": "Person",
"type": "LITERAL"
}
]
},
{
"intent": "AdditionalGreetingRequest",
"slots": []
}
]
}
My sample utterances:
WhoShouldBeGreeted {Sam and Cat|Person}
WhoShouldBeGreeted {Jonathan|Person}
WhoShouldBeGreeted {James|Person}
WhoShouldBeGreeted {Benji|Person}
WhoShouldBeGreeted welcome {Sam and Cat|Person}
WhoShouldBeGreeted welcome {Jonathan|Person}
WhoShouldBeGreeted welcome {James|Person}
WhoShouldBeGreeted welcome {Benji|Person}
Thank you for your help.