Skip to content

Instantly share code, notes, and snippets.

@runtimeZero
Created January 10, 2018 01:46
Show Gist options
  • Save runtimeZero/25938b6de9c196526ac18ffdf912f4dd to your computer and use it in GitHub Desktop.
Save runtimeZero/25938b6de9c196526ac18ffdf912f4dd to your computer and use it in GitHub Desktop.
PlanMyTrip - with sdk
const Alexa = require('alexa-sdk');
const APP_ID = 'amzn1.ask.skill.be810433-aaae-4cd3-99fc-708e3047a807';
exports.handler = (event, context, callback) => {
const alexa = Alexa.handler(event, context);
alexa.appId = APP_ID;
alexa.registerHandlers(handlers);
alexa.execute();
};
const handlers = {
'LaunchRequest': function() {
const welcomeMessage = 'Welcome to plan my trip from Lambda. You can say Help me plan my trip';
const repromptMessage = 'You can use this skill by saying Plan my trip';
this.response.speak(welcomeMessage).listen(repromptMessage);
this.emit(':responseReady');
},
'SessionEndedRequest': function() {
// close some connection
// send out emails
},
'AMAZON.HelpIntent': function() {
this.emit('LaunchRequest');
},
'AMAZON.CancelIntent': function() {
this.response.speak('Goodbye');
this.emit(':responseReady');
},
'AMAZON.StopIntent': function() {
this.response.speak('Goodbye');
this.emit(':responseReady');
},
'PlanMyTrip': function() {
if (this.event.request.dialogState === 'COMPLETED') {
let speechOutput = "Your itenary is ";
const fromCity = this.event.request.intent.slots.fromCity.value;
const toCity = this.event.request.intent.slots.toCity.value;
const travelDate = this.event.request.intent.slots.travelDate.value;
speechOutput += " from " + fromCity + " to " + toCity + " on " + travelDate;
this.response.speak(speechOutput);
this.emit(':responseReady');
}
else {
this.emit(":delegate");
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment