Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Alexa = require('alexa-sdk');
- movies = {
- 'comedy': ['Monty Python and the Holy Grail', 'Gentlemen Prefer Blondes', 'Some Like It Hot'],
- 'action': ['Mad Max: Fury Road', 'Seven Samurai', 'The Terminator'],
- 'sci-fi': ['Alien', 'Blade Runner', 'Doctor Strange'],
- 'drama': ['12 Years a Slave', 'L.A. Confidential', 'Whiplash']
- }
- function getRandomInt(max) {
- return Math.floor(Math.random() * Math.floor(max));
- }
- exports.handler = (event, context, callback) => {
- console.log(event)
- const alexa = Alexa.handler(event, context, callback);
- alexa.appId = '<ID GOES HERE>'
- alexa.registerHandlers(handlers);
- alexa.execute();
- };
- const handlers = {
- 'FindMovieIntent' : function() {
- const intentObj = this.event.request.intent;
- if (!intentObj.slots.genre.value) {
- this.emit(':tell', 'What genre?');
- } else {
- //this.emit(':tell', "Hold tight. I'm looking for a good " + genre + " movie for you.")
- genre = intentObj.slots.genre.value
- if (genre in movies) {
- candidates = movies[genre]
- if (candidates.length > 0) {
- suggestion = candidates[getRandomInt(candidates.length - 1)]
- this.emit(':tell', "How about \"" + suggestion + "\"?")
- } else {
- this.emit(':tell', "I don't know any " + genre + " movies yet")
- }
- } else {
- this.emit(':tell', "I don't know any " + genre + " movies yet")
- }
- }
- }
- };
Add Comment
Please, Sign In to add comment