Guest User

Untitled

a guest
Jan 19th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. const Alexa = require('alexa-sdk');
  2.  
  3. movies = {
  4. 'comedy': ['Monty Python and the Holy Grail', 'Gentlemen Prefer Blondes', 'Some Like It Hot'],
  5. 'action': ['Mad Max: Fury Road', 'Seven Samurai', 'The Terminator'],
  6. 'sci-fi': ['Alien', 'Blade Runner', 'Doctor Strange'],
  7. 'drama': ['12 Years a Slave', 'L.A. Confidential', 'Whiplash']
  8. }
  9.  
  10. function getRandomInt(max) {
  11. return Math.floor(Math.random() * Math.floor(max));
  12. }
  13.  
  14.  
  15. exports.handler = (event, context, callback) => {
  16. console.log(event)
  17. const alexa = Alexa.handler(event, context, callback);
  18. alexa.appId = '<ID GOES HERE>'
  19. alexa.registerHandlers(handlers);
  20. alexa.execute();
  21. };
  22.  
  23.  
  24. const handlers = {
  25. 'FindMovieIntent' : function() {
  26. const intentObj = this.event.request.intent;
  27. if (!intentObj.slots.genre.value) {
  28. this.emit(':tell', 'What genre?');
  29. } else {
  30. //this.emit(':tell', "Hold tight. I'm looking for a good " + genre + " movie for you.")
  31. genre = intentObj.slots.genre.value
  32. if (genre in movies) {
  33. candidates = movies[genre]
  34. if (candidates.length > 0) {
  35. suggestion = candidates[getRandomInt(candidates.length - 1)]
  36. this.emit(':tell', "How about \"" + suggestion + "\"?")
  37. } else {
  38. this.emit(':tell', "I don't know any " + genre + " movies yet")
  39. }
  40. } else {
  41. this.emit(':tell', "I don't know any " + genre + " movies yet")
  42. }
  43. }
  44. }
  45. };
Add Comment
Please, Sign In to add comment