Andrew
Published © Apache-2.0

Baby Names

An Alexa skill that helps new parents pick their new baby's name whether it's a boy or a girl.

EasyShowcase (no instructions)1 hour117
Baby Names

Things used in this project

Story

Read more

Code

code

JavaScript
/**
    Copyright 2014-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.

    Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at

        http://aws.amazon.com/apache2.0/

    or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

/**
 * This simple sample has no external dependencies or session management, and shows the most basic
 * example of how to create a Lambda function for handling Alexa Skill requests.
 *
 * Examples:
 * One-shot model:
 *  User: "Alexa, ask Space Geek for a space fact"
 *  Alexa: "Here's your space fact: ..."
 */

/**
 * App ID for the skill
 */
var APP_ID = ''; //OPTIONAL: replace with "amzn1.echo-sdk-ams.app.[your-unique-value-here]";

/**
 * Array containing space facts.
 */
var Boys = [
"Jackson",
"Aiden",
"Liam",
"Lucas",
"Noah",
"Mason",
"Ethan",
"Caden",
"Jacob",
"Logan",
"Jayden",
"Elijah",
"Jack",
"Luke",
"Michael",
"Benjamin",
"Alexander",
"James",
"Jayce",
"Caleb",
"Connor",
"William",
"Carter",
"Ryan",
"Oliver",
"Matthew",
"Daniel",
"Gabriel",
"Henry",
"Owen",
"Grayson",
"Dylan",
"Landon",
"Isaac",
"Nicholas",
"Wyatt",
"Nathan",
"Andrew",
"Cameron",
"Dominic",
"Joshua",
"Eli",
"Sebastian",
"Hunter",
"Brayden",
"David",
"Samuel",
"Evan",
"Gavin",
"Christian",
"Max",
"Anthony",
"Joseph",
"Julian",
"John",
"Colton",
"Levi",
"Isaiah",
"Aaron",
"Tyler",
"Charlie",
"Adam",
"Parker",
"Austin",
"Thomas",
"Zachary",
"Nolan",
"Alex",
"Ian",
"Jonathan",
"Christopher",
"Cooper",
"Hudson",
"Miles",
"Adrian",
"Leo",
"Blake",
"Lincoln",
"Jordan",
"Tristan",
"Jason",
"Josiah",
"Xavier",
"Camden",
"Chase",
"Declan",
"Carson",
"Colin",
"Brody",
"Asher",
"Jeremiah",
"Micah",
"Easton",
"Xander",
"Ryder",
"Nathaniel",
"Elliot",
"Sean",
"Cole"
];
var Girls=[
"Sophia",
"Emma",
"Olivia",
"Ava",
"Isabella",
"Mia",
"Zoe",
"Lily",
"Emily",
"Madelyn",
"Madison",
"Chloe",
"Charlotte",
"Aubrey",
"Avery",
"Abigail",
"Kaylee",
"Layla",
"Harper",
"Ella",
"Amelia",
"Arianna",
"Riley",
"Aria",
"Hailey",
"Hannah",
"Aaliyah",
"Evelyn",
"Addison",
"Mackenzie",
"Adalyn",
"Ellie",
"Brooklyn",
"Nora",
"Scarlett",
"Grace",
"Anna",
"Isabelle",
"Natalie",
"Kaitlyn",
"Lillian",
"Sarah",
"Audrey",
"Elizabeth",
"Leah",
"Annabelle",
"Kylie",
"Mila",
"Claire",
"Victoria",
"Maya",
"Lila",
"Elena",
"Lucy",
"Savannah",
"Gabriella",
"Callie",
"Alaina",
"Sophie",
"Makayla",
"Kennedy",
"Sadie",
"Skyler",
"Allison",
"Caroline",
"Charlie",
"Penelope",
"Alyssa",
"Peyton",
"Samantha",
"Liliana",
"Bailey",
"Maria",
"Reagan",
"Violet",
"Eliana",
"Adeline",
"Eva",
"Stella",
"Keira",
"Katherine",
"Vivian",
"Alice",
"Alexandra",
"Camilla",
"Kayla",
"Alexis",
"Sydney",
"Kaelyn",
"Jasmine",
"Julia",
"Cora",
"Lauren",
"Piper",
"Gianna",
"Paisley",
"Bella",
"London",
"Clara",
"Cadence"
];
/**
 * The AlexaSkill prototype and helper functions
 */
var AlexaSkill = require('./AlexaSkill');

/**
 * SpaceGeek is a child of AlexaSkill.
 * To read more about inheritance in JavaScript, see the link below.
 *
 * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript#Inheritance
 */
var Fact = function () {
    AlexaSkill.call(this, APP_ID);
};

// Extend AlexaSkill
Fact.prototype = Object.create(AlexaSkill.prototype);
Fact.prototype.constructor = Fact;

Fact.prototype.eventHandlers.onSessionStarted = function (sessionStartedRequest, session) {
    //console.log("onSessionStarted requestId: " + sessionStartedRequest.requestId + ", sessionId: " + session.sessionId);
    // any initialization logic goes here
};

Fact.prototype.eventHandlers.onLaunch = function (launchRequest, session, response) {
    //console.log("onLaunch requestId: " + launchRequest.requestId + ", sessionId: " + session.sessionId);
    handleWelcome(response);
};

/**
 * Overridden to show that a subclass can override this function to teardown session state.
 */
Fact.prototype.eventHandlers.onSessionEnded = function (sessionEndedRequest, session) {
    //console.log("onSessionEnded requestId: " + sessionEndedRequest.requestId + ", sessionId: " + session.sessionId);
    // any cleanup logic goes here
};

Fact.prototype.intentHandlers = {
    "GetNewBoyIntent": function (intent, session, response) {
        handleNewBoyRequest(response);
    },
     "GetNewGirlIntent": function (intent, session, response) {
        handleNewGirlRequest(response);
    },

    "AMAZON.HelpIntent": function (intent, session, response) {
        response.ask("You can say tell me a boy's name, or tell me a girls's name , or,  you can say exit... What can I help you with?", "What can I help you with?");
    },

    "AMAZON.StopIntent": function (intent, session, response) {
        var speechOutput = "Goodbye";
        response.tell(speechOutput);
    },

    "AMAZON.CancelIntent": function (intent, session, response) {
        var speechOutput = "Goodbye";
        response.tell(speechOutput);
    }
};

/**
 * Gets a random new fact from the list and returns to the user.
 */
function handleNewBoyRequest(response) {
    // Get a random space fact from the space facts list
    var factIndex = Math.floor(Math.random() * Boys.length);
    var randomFact = Boys[factIndex];

    // Create speech output
    var speechOutput =  randomFact;
    var cardTitle = "Baby Name";
    response.tellWithCard(speechOutput, cardTitle, speechOutput);
}
function handleNewGirlRequest(response) {
    // Get a random space fact from the space facts list
    var factIndex = Math.floor(Math.random() * Girls.length);
    var randomFact = Girls[factIndex];

    // Create speech output
    var speechOutput =  randomFact;
    var cardTitle = "Baby Name";
    response.tellWithCard(speechOutput, cardTitle, speechOutput);
}
function handleWelcome(response){
    // Create speech output
    var speechOutput =  "Welcome to Baby Name You can say tell me a Boy's name or You can say tell me a Girl's name";
    var cardTitle = "Welcome to Baby Name";
    response.tellWithCard(speechOutput, cardTitle, speechOutput);
}

// Create the handler that responds to the Alexa Request.
exports.handler = function (event, context) {
    // Create an instance of the SpaceGeek skill.
    var fact = new Fact();
    fact.execute(event, context);
};

Credits

Andrew

Andrew

2 projects • 1 follower

Comments