/**
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 = undefined; //replace with "amzn1.echo-sdk-ams.app.[your-unique-value-here]";
/**
* Array containing space facts.
*/
var SPACE_FACTS = [
"California's Mount Whitney measures as the highest peak in the lower 48 states. Its most famous climb is Mount Whitney Trail to the 14,495 feet summit. Wilderness permits are required.",
"In 1925 a giant sequoia located in California's Kings Canyon National Park was named the nation's national Christmas tree. The tree is over 300 feet in height.",
"More turkeys are raised in California than in any other state in the United States.",
"Alpine County is the eighth smallest of California's 58 counties. It has no high school, ATMs, dentists, banks, or traffic lights.",
"Fallbrook is known as the Avocado Capital of the World and hosts an annual Avocado Festival. More avocados are grown in the region than any other county in the nation.",
"In the late 1850s, Kennedy Mine, located in Jackson, served as one of the richest gold mines in the world and the deepest mine in North America.",
"An animal called the riparian brush rabbit calls Caswell Memorial State Park (near Manteca) its home. Endemic only to the state's park system, the critter lives in approximately 255 acres stretching along the area's once-vast hardwood forest.",
"In city of Pacific Grove, there is a law on the books declaring the molestation of monarch butterflies to be illegal.",
"The largest three-day rodeo in the United States is held on the Tehama County Fairgrounds in Red Bluff.",
"Demonstrations on making toothpaste from orange by-products were popular attractions at the Los Angeles County fair in 1922. The fair is held in Pomona.",
"Located in Sacramento, the California State Railroad Museum is the largest museum of its kind in North America.",
"Several celebrities are buried at Hillside Cemetery in Culver City. Included gravesites are those of Al Jolson, George Jessel, Eddie Cantor, Jack Benny, and Percy Faith.",
"California Caverns claims the distinction of being the most extensive system of caverns and passageways in the Mother Lode region of the state.",
"Totaling nearly three million acres, San Bernardino County is the largest county in the country.",
"On Catalina Island in 1926, American author Zane Grey built a pueblo-style home on the hillside overlooking Avalon Bay. He spent much of his later life in Avalon. The home is now a hotel.",
"Klamath Basin National Wildlife Refuge contains the largest winter population of bald eagles in the continental United States.",
"In Atwater the Castle Air Museum has the largest display of military aircraft in the state.",
"The Country Store in Baker has sold more winning California State Lottery tickets than any outlet in the state.",
"Reputed to be the most corrupt politician in Fresno County history, Vice-leader Joseph Spinney was mayor for only ten minutes.",
"Death Valley is recognized as the hottest, driest place in the United States. It isn't uncommon for the summer temperatures to reach more than 115 degrees.",
"San Francisco Bay is considered the world's largest landlocked harbor.",
"Sequoia National Park contains the largest living tree. Its trunk is 102 feet in circumference.",
"One out of every eight United States residents lives in California.",
"California is the first state to ever reach a trillion dollar economy in gross state product.",
"California has the largest economy in the states of the union.",
"If California's economic size were measured by itself to other countries, it would rank the 7th largest economy in the world.",
"California is known variously as The Land of Milk and Honey, The El Dorado State, The Golden State, and The Grape State.",
"California produces more than 17 million gallons of wine each year.",
"The redwood is the official state tree. Some of the giant redwoods in Sequoia National Park are more than 2,000 years old."
];
/**
* 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 SpaceGeek = function () {
AlexaSkill.call(this, APP_ID);
};
// Extend AlexaSkill
SpaceGeek.prototype = Object.create(AlexaSkill.prototype);
SpaceGeek.prototype.constructor = SpaceGeek;
SpaceGeek.prototype.eventHandlers.onSessionStarted = function (sessionStartedRequest, session) {
console.log("SpaceGeek onSessionStarted requestId: " + sessionStartedRequest.requestId
+ ", sessionId: " + session.sessionId);
// any initialization logic goes here
};
SpaceGeek.prototype.eventHandlers.onLaunch = function (launchRequest, session, response) {
console.log("SpaceGeek onLaunch requestId: " + launchRequest.requestId + ", sessionId: " + session.sessionId);
handleNewFactRequest(response);
};
/**
* Overridden to show that a subclass can override this function to teardown session state.
*/
SpaceGeek.prototype.eventHandlers.onSessionEnded = function (sessionEndedRequest, session) {
console.log("SpaceGeek onSessionEnded requestId: " + sessionEndedRequest.requestId
+ ", sessionId: " + session.sessionId);
// any cleanup logic goes here
};
SpaceGeek.prototype.intentHandlers = {
"GetNewFactIntent": function (intent, session, response) {
handleNewFactRequest(response);
},
"AMAZON.HelpIntent": function (intent, session, response) {
response.ask("You can ask Cali fact tell me a California fact, 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 handleNewFactRequest(response) {
// Get a random space fact from the space facts list
var factIndex = Math.floor(Math.random() * SPACE_FACTS.length);
var fact = SPACE_FACTS[factIndex];
// Create speech output
var speechOutput = "Here's your California fact: " + fact;
response.tellWithCard(speechOutput, "California Fact", speechOutput);
}
// Create the handler that responds to the Alexa Request.
exports.handler = function (event, context) {
// Create an instance of the SpaceGeek skill.
var spaceGeek = new SpaceGeek();
spaceGeek.execute(event, context);
};
Comments