Created
June 1, 2017 09:05
-
-
Save mmetting/0182f240e723a5a95ac8755377542366 to your computer and use it in GitHub Desktop.
Implementing our Skill
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
var express = require('express'); | |
var bodyParser = require('body-parser'); | |
var cors = require('cors'); | |
const LambdaMockContext = require('aws-lambda-mock-context'); | |
const Alexa = require('alexa-sdk'); | |
function alexaRoute() { | |
var alexa = new express.Router(); | |
alexa.use(cors()); | |
alexa.use(bodyParser()); | |
alexa.post('/', function (request, response) { | |
var lambdaCtx = LambdaMockContext(); | |
const handlers = { | |
'HelloWorldIntent': function () { | |
this.emit(':tell', 'From Red Hat Mobile: Hello World!'); | |
}, | |
'AMAZON.HelpIntent': function () { | |
this.emit(':tell', 'How can I help you?'); | |
}, | |
'AMAZON.StopIntent': function () { | |
this.emit(':tell', 'Cheers!'); | |
}, | |
'AMAZON.CancelIntent': function () { | |
this.emit(':tell', 'Cheers!'); | |
}, | |
'SessionEndedRequest': function () { | |
this.emit(':tell', 'Good Bye!'); | |
}, | |
'Unhandled': function () { | |
this.emit(':tell', 'What\'s up?'); | |
}, | |
}; | |
var alexa = Alexa.handler(request.body, lambdaCtx); | |
alexa.registerHandlers(handlers); | |
alexa.execute(); | |
lambdaCtx.Promise | |
.then(resp => { return response.status(200).json(resp); }) | |
.catch(err => { console.log(err); }) | |
}); | |
return alexa; | |
} | |
module.exports = alexaRoute; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment