Raj Bhanushali
Created June 9, 2017

Gorilla Facts

Want to know more about the furry yet ferocious beasts we call gorillas? Look no further! This skill will tell you all about gorillas.

27
Gorilla Facts

Things used in this project

Hardware components

Echo Dot
Amazon Alexa Echo Dot
×1

Software apps and online services

Alexa Skills Kit
Amazon Alexa Alexa Skills Kit
AWS Lambda
Amazon Web Services AWS Lambda

Story

Read more

Code

Lambda Function Code

JavaScript
Lambda function with code to return a random fact in the array when called. Make sure to include the alexa-sdk library as well.
'use strict';
var Alexa = require('alexa-sdk');

var APP_ID = undefined; //OPTIONAL: replace with "amzn1.echo-sdk-ams.app.[your-unique-value-here]";
var SKILL_NAME = 'Gorilla Facts';

/**
 * Array containing gorilla facts.
 */
var FACTS = [
    "Gorillas are herbivores and eat leaves, shoots, roots, vines and fruits.",
    "Eastern lowland gorilla numbers have rapidly declined to below 5,000 today.",
    "Mountain gorillas, another endangered subspecies, number at around 700. ",
    "Great apes are different from monkeys for a variety of reasons: they are larger, walk upright for a longer period of time, don’t have tails and have much larger, more developed brains.",
    "gorillas have arms that are longer than their legs and tend to walk on all four limbs at certain times – a movement that is called knuckle walking. ",
    "Mountain gorillas also have longer and thicker fur which is adapted to their colder mountainous habitat. ",
    "Gorillas are ground-dwelling and live in groups of 6-12 with the oldest and largest silverback leading a family of females, their young and younger males called blackbacks.",
    "Gorillas are shy animals that are most active during the day."
];

exports.handler = function(event, context, callback) {
    var alexa = Alexa.handler(event, context);
    alexa.APP_ID = APP_ID;
    alexa.registerHandlers(handlers);
    alexa.execute();
};

var handlers = {
    'LaunchRequest': function () {
        this.emit('GetFact');
    },
    'GetNewFactIntent': function () {
        this.emit('GetFact');
    },
    'GetFact': function () {
        // Get a random space fact from the gorilla facts list
        var factIndex = Math.floor(Math.random() * FACTS.length);
        var randomFact = FACTS[factIndex];

        // Create speech output
        var speechOutput = "Here's your fact: " + randomFact;

        this.emit(':tellWithCard', speechOutput, SKILL_NAME, randomFact)
    },
    'AMAZON.HelpIntent': function () {
        var speechOutput = "You can say tell me a gorilla fact, or, you can say exit... What can I help you with?";
        var reprompt = "What can I help you with?";
        this.emit(':ask', speechOutput, reprompt);
    },
    'AMAZON.CancelIntent': function () {
        this.emit(':tell', 'Goodbye!');
    },
    'AMAZON.StopIntent': function () {
        this.emit(':tell', 'Goodbye!');
    }
};

Credits

Raj Bhanushali

Raj Bhanushali

2 projects • 0 followers

Comments