Created
June 11, 2016 00:06
-
-
Save wero1414/39c0886d6fcc60f786fb9e8cea02f410 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
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, tell Greeter to say hello" | |
* Alexa: "Hello World!" | |
*/ | |
/** | |
* App ID for the skill | |
*/ | |
var APP_ID = "amzn1.echo-sdk-ams.app.87ee3e2a-6d2e-4fca-bf08-edc559ad5335"; //replace with "amzn1.echo-sdk-ams.app.[your-unique-value-here]"; | |
/** | |
* The AlexaSkill prototype and helper functions | |
*/ | |
var AlexaSkill = require('./AlexaSkill'); | |
/** | |
* HelloWorld 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 HelloWorld = function () { | |
AlexaSkill.call(this, APP_ID); | |
}; | |
// Extend AlexaSkill | |
HelloWorld.prototype = Object.create(AlexaSkill.prototype); | |
HelloWorld.prototype.constructor = HelloWorld; | |
HelloWorld.prototype.eventHandlers.onSessionStarted = function (sessionStartedRequest, session) { | |
console.log("HelloWorld onSessionStarted requestId: " + sessionStartedRequest.requestId | |
+ ", sessionId: " + session.sessionId); | |
// any initialization logic goes here | |
}; | |
HelloWorld.prototype.eventHandlers.onLaunch = function (launchRequest, session, response) { | |
console.log("HelloWorld onLaunch requestId: " + launchRequest.requestId + ", sessionId: " + session.sessionId); | |
var speechOutput = "Welcome to the Alexa Skills Kit, you can say hello"; | |
var repromptText = "You can say hello"; | |
response.ask(speechOutput, repromptText); | |
}; | |
HelloWorld.prototype.eventHandlers.onSessionEnded = function (sessionEndedRequest, session) { | |
console.log("HelloWorld onSessionEnded requestId: " + sessionEndedRequest.requestId | |
+ ", sessionId: " + session.sessionId); | |
// any cleanup logic goes here | |
}; | |
HelloWorld.prototype.intentHandlers = { | |
// register custom intent handlers | |
"HelloWorldIntent": function (intent, session, response) { | |
response.tellWithCard("Hello World!", "Greeter", "Hello World!"); | |
}, | |
"AMAZON.HelpIntent": function (intent, session, response) { | |
response.ask("You can say hello to me!", "You can say hello to me!"); | |
} | |
}; | |
// Create the handler that responds to the Alexa Request. | |
exports.handler = function (event, context) { | |
// Create an instance of the HelloWorld skill. | |
var helloWorld = new HelloWorld(); | |
helloWorld.execute(event, context); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Te amo