Skip to content

Instantly share code, notes, and snippets.

@maegnes
Created November 15, 2018 15:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maegnes/0fa08ef86c721bf5b62d0b5721b20136 to your computer and use it in GitHub Desktop.
Save maegnes/0fa08ef86c721bf5b62d0b5721b20136 to your computer and use it in GitHub Desktop.
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!');
});
}
@iambaji
Copy link

iambaji commented Mar 28, 2019

it is throwing invoke is not a function error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment