1

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:

  1. to use an if statement to test my utterance and have Alexa reply based on my utterance
  2. 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.

haltersweb
  • 3,001
  • 2
  • 13
  • 14

1 Answers1

3

You are using a "LITERAL" slot type. (This is discouraged, but it is still supported.) That means you are just recognizing a word. Spoken words have no case. But the === operator in Javascript is case sensitive. If you check your logs, I suspect that when you say "Jonathan" what you get is "jonathan", which your match then fails.

To fix this you can change your compare to lower case, or change the operator to a case insensitive string compare (see here).

Another approach would be to not use the LITERAL slot type, and use the AMAZON.US_FIRST_NAME instead. Since this knows it is a name, it returns it capitalized.

Community
  • 1
  • 1
Joseph Jaquinta
  • 2,118
  • 17
  • 15
  • This is great! Thanks! While I couldn't get AMAZON.US_FIRST_NAME to work, changing the case to lower case and using LITERAL worked perfectly! – haltersweb Jul 16 '16 at 22:11