Created
November 15, 2018 15:51
-
-
Save maegnes/0fa08ef86c721bf5b62d0b5721b20136 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
const Alexa = require('ask-sdk'); | |
let skill; | |
const HelloWorldHandler = { | |
canHandle(handlerInput) { | |
return handlerInput.requestEnvelope.request.type === 'IntentRequest' | |
&& handlerInput.requestEnvelope.request.intent.name === 'HelloWorldIntent'; | |
}, | |
handle(handlerInput) { | |
const speechText = 'Hello World!'; | |
return handlerInput.responseBuilder | |
.speak(speechText) | |
.withSimpleCard('Hello World', speechText) | |
.getResponse(); | |
} | |
}; | |
if (ENVIRONMENT === 'production') { | |
exports.handler = async function (event, context) { | |
if (!skill) { | |
skill = Alexa.SkillBuilders.custom() | |
.addRequestHandlers( | |
HelloWorldHandler | |
) | |
.create(); | |
} | |
return skill.invoke(event,context); | |
} | |
} else { | |
// Development environment - we are on our local node server | |
const express = require('express'); | |
const bodyParser = require('body-parser'); | |
const app = express(); | |
app.use(bodyParser.json()); | |
app.post('/', function(req, res) { | |
if (!skill) { | |
skill = Alexa.SkillBuilders.custom() | |
.addRequestHandlers( | |
HelloWorldHandler | |
) | |
.create(); | |
} | |
skill.invoke(req.body) | |
.then(function(responseBody) { | |
res.json(responseBody); | |
}) | |
.catch(function(error) { | |
console.log(error); | |
res.status(500).send('Error during the request'); | |
}); | |
}); | |
app.listen(3000, function () { | |
console.log('Development endpoint listening on port 3000!'); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it is throwing invoke is not a function error