Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.72 KB | None | 0 0
  1. 'use strict';
  2. const Alexa = require('ask-sdk-v1adapter');
  3. const APP_ID = undefined;
  4.  
  5. /***********
  6. Data: Customize the data below as you please.
  7. ***********/
  8.  
  9. const SKILL_NAME = "Quickmeal";
  10. const STOP_MESSAGE = "See you next time.";
  11. const CANCEL_MESSAGE = "Okay. Do you want to hear a different recipe instead?";
  12.  
  13. const HELP_START = "I have a bunch of tasty and quick recipes for you.";
  14. const HELP_START_REPROMPT = "Just tell me what type of meal you'd like.";
  15. const HELP_RECIPE = "Choose whatever recipe you want.";
  16. const HELP_RECIPE_REPROMPT = "Just ask me for a recipe.";
  17. const HELP_INSTRUCTIONS = "You can ask me to repeat the instructions or say 'next' for the next step.";
  18. const HELP_INSTRUCTIONS_REPROMPT = "You can say repeat, next or 'I changed my mind' for another recipe.";
  19. const HELP_CANCEL = "You can hear a new recipe or just not eat.";
  20. const HELP_CANCEL_REPROMPT = "Not eating so far caused 100% of test subjects to die.";
  21.  
  22. const CHOOSE_TYPE_MESSAGE = "Welcome to Quickmeal! I have really nice breakfast, lunch, snack, or dinner recipes for you. What are you looking for?";
  23. const REPROMPT_TYPE = "You can choose a breakfast, lunch, snack, or dinner recipe. What type of meal would you like to choose?";
  24. const MEALTYPE_NOT_IN_LIST = chosenType => `Sorry, I couldn't find any recipes for ${chosenType}. Do you want a breakfast, lunch, dinner or snack recipe?`;
  25.  
  26. const RECIPE_ADJECTIVES = [
  27. "awesome",
  28. "super simple",
  29. "fun",
  30. "tasty",
  31. "yummy",
  32. "delicious",
  33. "delectable",
  34. "extremely tasty"
  35. ];
  36. const SUGGEST_RECIPE = recipeName => `I found this ${_pickRandom(RECIPE_ADJECTIVES)} ${recipeName} recipe! Do you want to make ${recipeName}? You can also ask for the ingredients list`;
  37. const MISUNDERSTOOD_RECIPE_ANSWER = "Please answer with yes or no.";
  38. const NO_REMAINING_RECIPE = "This was it. I currently have no more recipes. Do you want to select a different meal type?"
  39. const INGREDIENTS_INTRO = "You will need"; // Here follows a list of ingredients
  40. const INGREDIENTS_ENDING = "Does that sound like a meal you want to eat?"; // Will be said after the list of ingredients
  41.  
  42.  
  43. const FIRST_TIME_INSTRUCTIONS = "Say 'next' for the next step. Say 'repeat' if you want to hear the last line of instructions again.";
  44. const REPROMPT_INSTRUCTIONS = "Say 'next' for the next step. Say 'repeat' if you want to hear the last line of instructions again.";
  45. const MISUNDERSTOOD_INSTRUCTIONS_ANSWER = "Sorry, I didn't understand you there.";
  46. const CLOSING_MESSAGE = "Wonderful. Hope you have a great meal and will come back for more";
  47.  
  48. const recipes = {
  49. breakfast: [
  50. {
  51. name: "Lemon Ricotta Pancakes",
  52. instructions: [
  53. "Have the following ingredients ready: half cup of ricotta cheese, one large egg, one lemon and one cup of flour.",
  54. "First, whisk three quarter cup water or milk and half teaspoon baking soda together in a mixing bowl",
  55. "Add half cup ricotta cheese and one tablespoon grated lemon zest",
  56. "Add 1 tablespoon vegetables oil, 1 tablespoon sugar, 1 large egg, and 1/8 spoon vanilla extract to the mixture",
  57. "Whisk until smooth, breaking up lumps of cheese as you mix.",
  58. "Now add 2 tablespoons melted butter and 1 tablespoon lemon juice. ",
  59. `Add 1 cup plus 2 tablespoons self-rising flour.`,
  60. "Whisk together, stirring until most of flour disappears into the batter.",
  61. "Let batter sit at room temperature about 15 minutes.",
  62. "Heat lightly greased cast iron skillet or griddle over medium-high heat.",
  63. "Portion out 1/4 cup scoops of batter onto skillet and cook the pancakes in batches.",
  64. "When bubbles begin to form on the surface and the edges of the pancakes start to look dry, flip and cook other side until cooked through, about 3 minutes."
  65. ],
  66. ingredients: [
  67. "three quarters cup cold water or milk",
  68. "half teaspoon baking soda",
  69. "half cup ricotta cheese",
  70. "one tablespoon grated lemon zest",
  71. "one tablespoon vegetable oil",
  72. "one tablespoon white sugar",
  73. "one large egg",
  74. "one eighth teaspoon vanilla extract",
  75. "two tablespoons melted butter",
  76. "one tablespoon lemon juice",
  77. "one cup self-rising flour",
  78. "two tablespoons self-rising flour"
  79. ] },
  80. {
  81. name: "Avocado Toast",
  82. instructions: [
  83. "Get whole-grain bread, 1 avocado and one bunch of fresh parsley.",
  84. "Wash and chop 1 bunch of fresh parsley. You will need 2 tablespoons for the meal.",
  85. "Juice a half lemon.",
  86. "Scoop 1 avocado into a bowl.",
  87. "Add 2 tablespoons of parsley, 1 and a half teaspoons of olive oil, lemon juice, half teaspoon salt, half teaspoon pepper, half teaspoon onion powder, and half teaspoon garlic powder.",
  88. "Mash everything together using a potato masher.",
  89. "Spread avocado mixture into each piece of toast. If you like you can top each toast with a fried egg."
  90. ],
  91. ingredients: [
  92. "4 slices whole-grain bread",
  93. "1 avocado",
  94. "1 small bunch of fresh parsley",
  95. "one and a half teaspoons olive oil",
  96. "a half of lemon",
  97. "a half teaspoon salt",
  98. "a half teaspoon ground black pepper",
  99. "a half teaspoon onion powder",
  100. "a half teaspoon garlic powder"
  101. ]
  102. },
  103. {
  104. name: "Breakfast Smoothie",
  105. instructions: [
  106. "Get some spinach, 1 frozen banana, half of avocado and almond milk.",
  107. "Wash half cup spinach and drain.",
  108. "Cut 1 frozen banana into chunks.",
  109. "Put into the blender the spinach, the banana chunks, 1/2 avocado, 1/4 cup almond milk.",
  110. "Add 1/2 teaspoon vanilla extract and 1/4 teaspoon gound cinnamon and blend until smooth."
  111. ],
  112. ingredients: [
  113. "half cup of spinach",
  114. "1 frozen banana",
  115. "a half an avocado",
  116. "a quarter cup of almond milk",
  117. "a half teaspoon vanilla extract",
  118. "one quarter teaspoon of ground cinnamon"
  119. ]
  120. },
  121. {
  122. name: "Banana Wraps",
  123. instructions: [
  124. "Have the following ingredients ready: 1 banana, 2 large whole wheat tortillas, some peanut butter, some granola and some honey.",
  125. "Peel 1 banana and half lengthwise.",
  126. "Stir together the peanut butter and honey in a bowl until smooth.",
  127. "Mix in a quarter cup coconut and 1/2 cup granola. Divide the mixture in half, and spread half over each tortilla.",
  128. "Place a banana half in the center of a tortilla, and roll up. Slice the rolls in half and enjoy."
  129. ],
  130. ingredients: [
  131. "4 teaspoons peanut butter",
  132. "2 tablespoons honey",
  133. "a half cup granola",
  134. "1 banana",
  135. "2 large whole wheat tortillas",
  136. "a quarter cup shredded coconut, if desired"
  137. ]
  138. },
  139. {
  140. name: "Pizza Muffins",
  141. instructions: [
  142. "Get 1 can of refrigerated buttermilk biscuit dough, some pizza sauce, shredded mozzerella cheese and pepperoni.",
  143. "Preheat oven to 425 degrees Fahrenheit or 220 degrees Celcius. Spray 10 muffin cups with cooking spray.",
  144. "Press biscuits, one at a time, between hands to flatten. Place each flattened biscuit in a muffin cup.",
  145. "Press biscuit dough into bottom and up sides of muffin form.",
  146. "Set aside for biscuit to settle and slightly rise, about 5 minutes. Lightly press biscuits into cups as needed.",
  147. "Spoon 1 tablespoon pizza sauce into each biscuit; top each with 1 slice pepperoni and 1 tablespoon mozzarella cheese.",
  148. "Bake in the preheated oven until biscuit is lightly browned and cheese is melted, about 10 minutes.",
  149. "Remove each pizza from tin and place on a cooling rack, about 5 minutes."
  150. ],
  151. ingredients: [
  152. "1 can or 10 ounce refrigerated buttermilk biscuit dough",
  153. "10 tablespoons pizza sauce",
  154. "10 slices pepperoni",
  155. "10 tablespoons shredded mozzarella cheese",
  156. "Some cooking spray"
  157. ]
  158. }
  159. ],
  160. lunch: [
  161. {
  162. name: "Japanese Cucumber",
  163. instructions: [
  164. "Have the following ingredients ready: 2 cucumbers, some fresh ginger and rice vinegar.",
  165. "Peel 2 cucumbers and half lengthwise.",
  166. "Scoop out any larger seeds.",
  167. "Slice crosswise into very thin slices.",
  168. "In a small bowl combine one third cup rice vinegar, 4 teaspoons sugar, 1 teaspoon salt and one and half teaspoons minced fresh ginger root.",
  169. "Place cucumbers inside of the bowl, stir so that cucumbers are coated with the mixture.",
  170. "Refrigerate the bowl of cucumbers for at least 1 hour before serving."
  171. ],
  172. ingredients: [
  173. "2 large cucumbers",
  174. "one third cup rice vinegar",
  175. "4 teaspoons white sugar",
  176. "1 teaspoon salt",
  177. "one and a half teaspoons minced fresh ginger root"
  178. ]
  179. },
  180. {
  181. name: "Strawberry Avocado Salad",
  182. instructions: [
  183. "First, get 1 avocado, 10 strawberries, green salad and some chopped pecans.",
  184. "Slice 1 avocado",
  185. "Wash and slice 10 strawberries",
  186. "Wash 2 cups salad greens and drain",
  187. "In a small bowl, whisk together 2 tablespoons sugar, 2 tablespoons olive oil, 4 teaspoons honey, 1 tablespoon cider vinegar, and 1 teaspoon lemon juice. Set aside.",
  188. "Place the salad greens in a serving bowl, and top with sliced avocado and strawberries.",
  189. "Drizzle dressing over everything, then sprinkle with 1/2 cup chopped pecans. You can serve it warm or chilled."
  190. ],
  191. ingredients: [
  192. "2 tablespoons white sugar",
  193. "2 tablespoons olive oil",
  194. "4 teaspoons honey",
  195. "1 tablespoon cider vinegar",
  196. "1 teaspoon lemon juice",
  197. "2 cups torn salad greens",
  198. "1 avocado",
  199. "10 strawberries",
  200. "a half cup chopped pecans"
  201. ]
  202. },
  203. {
  204. name: "Creamy Dill Cucumber Toasties",
  205. instructions: [
  206. "Great, have the following ingredients ready: 1 package or 9 ounce cream cheese, 1 package dry Italian-style salad dressing mix, half cup of mayonaise, 1 French baguette and 2 teaspoons dried dill weed.",
  207. "Cut 1 baguette into 1/2 inch thick circles.",
  208. "Slice 1 cucumber",
  209. "In a medium bowl, mix together 1 package softened cream cheese, 1 package dry dressing mix and a half cup mayonnaise.",
  210. "Spread a thin layer of the cream cheese mixture on a slice of bread, and top with a slice of cucumber.",
  211. "Sprinkle with 2 teaspoons dried dill weed and enjoy."
  212. ],
  213. ingredients: [
  214. "8 ounce or 1 package cream cheese",
  215. "7 ounce or 1 package dry Italian-style salad dressing mix",
  216. "1/2 cup mayonaise",
  217. "1 French baguette",
  218. "1 cucumber",
  219. "2 teaspoons dried dill weed"
  220. ]
  221. },
  222. {
  223. name: "Watermelon salad with feta cheese",
  224. instructions: [
  225. "Grab a watermelon, some fresh mint and a half cup of crumbled feta cheese.",
  226. "Cut the watermelon in cubes.",
  227. "Wash and chop the fresh mint.",
  228. "Toss the mint and crumbled feta cheese over the watermelon and chill until ready to serve."
  229. ],
  230. ingredients: [
  231. "a quarter of a watermelon",
  232. "half cup of crumbled feta cheese",
  233. "some fresh mint"
  234. ]
  235. }
  236. ],
  237. dinner: [
  238. {
  239. name: "Sesame Noodle Salad",
  240. instructions: [
  241. "Have the following ingredients ready: 1 package angel hair pasta, 1 green onion, 1 red bell pepper, some sesame oil and soy sauce.",
  242. "Fill a large pot with lightly salted water and bring to a rolling boil over high heat. Once the water is boiling, stir in the angel hair pasta, and return to a boil.",
  243. "Cook the pasta uncovered, stirring occasionally, until the pasta has cooked through, but is still firm to the bite, 4 to 5 minutes.",
  244. "In the meantime, chop 1 green onion.",
  245. "Dice 1 red bell pepper",
  246. "Drain the pasta in a colander set in the sink.",
  247. "For the sauce, whisk together a half cup of sesame oil, a half cup of soy sauce, a quarter cup balsamic vinegar, 1 tablespoon hot chili oil and a quarter cup sugar in a large bowl. ",
  248. "Toss the pasta in the dressing, then sprinkle with a half cup of sesame seeds, green onion, and bell pepper.",
  249. "Serve warm, or cover and refrigerate for a cold salad."
  250. ],
  251. ingredients: [
  252. "1 package or 16 ounce of angel hair pasta. A half cup sesame oil. A half cup soy sauce. A quarter cup balsamic vinegar. 1 tablespoon hot chili oil. A quarter cup white sugar. 1 teaspoon sesame seeds. 1 green onion. 1 red bell pepper."
  253. ]
  254. },
  255. {
  256. name: "Fried breaded tofu",
  257. instructions: [
  258. "Get 1 package extra firm tofu, vegetable broth, some nutritional yeast, some flour, sage and cayenne pepper.",
  259. "Cut pressed tofu into half inch thick slices; then cut again into half inch wide sticks.",
  260. "Place tofu in a bowl, and pour 2 cup vegetable broth over the top. Set aside to soak.",
  261. "In a separate bowl, stir together a half cup flour, 3 tablespoons nutritional yeast, 1 teaspoon salt, a half teaspoon ground pepper, 1 teaspoon sage and a half teaspoon of cayenne pepper.",
  262. "Warm oil in a large skillet over medium-high heat.",
  263. "Remove tofu sticks from broth, and squeeze most, but not all of the liquid from them.",
  264. "Roll sticks in breading several times. The sticks should be dry to touch.",
  265. "Place tofu in hot oil; fry until crisp and browned on all sides. Add more oil if necessary."
  266. ],
  267. ingredients: [
  268. "1 package or 16 ounce extra-firm tofu, drained and pressed. 2 cups vegetable broth. 3 tablespoons vegetable oil. a half cup all-purpose flour. 3 tablespoons nutritional yeast. 1 teaspoon salt. a half teaspoon freshly ground black pepper. 1 teaspoon sage. a half teaspoon cayenne pepper."
  269. ]
  270. },
  271. {
  272. name: "Dagmar's Chicken Ragout",
  273. instructions: [
  274. "Have the following ready: 1 whole chicken, 1 stick butter, 2 onions, 2 cans of mushrooms and fresh lemonjuice.",
  275. "For the chicken soup, cube the onions and saute them with some butter in a big stockpot. ",
  276. "Add the whole chicken, 1 tablespoon salt, some pepper and enough water to cover the chicken.",
  277. "Cook the chicken for 1 hour at medium to low heat.",
  278. "Place the chicken on a plate and pull the meat from the bones. Discard the bones.",
  279. "In a big pan, melt 1 stick of butter at medium heat, add 2 tablespoons flour and stir with a whisk. It will look very lumpy.",
  280. "Add gradually 1 cup of chicken stock to the mixture and stir with a whisk.",
  281. "Continue adding another cup of chicken stock to the mixture and stir.",
  282. "Gradually add 2 cups of chicken stock and stir until it becomes a smooth gravy.",
  283. "Add 2 cans of drained mushrooms to the sauce.",
  284. "Add the pulled chicken to the sauce and stir. ",
  285. "Add 1-2 tablespoons of fresh lemon juice according to your taste. Serve this comforting meal with yellow rice and buttered vegetables."
  286. ],
  287. ingredients: [
  288. "1 whole chicken, 1 stick butter, 2 onions, 2 cans of mushromms, 2 tablespoon flour, 1 to 2 tablespoons fresh lemon juice, 1 tablespoon salt and some pepper."
  289. ]
  290. },
  291. {
  292. name: "Red lentil curry",
  293. instructions: [
  294. "Get 2 cups red lentils, 1 large onion, some curry paste, curry powder, ground turmeric, ground cumin, chili powder, fresh ginger, minced garlic and 1 can or 14 ounce tomato puree, sugar and salt.",
  295. "Mince 1 fresh ginger root. You need 1 teaspoon for the recipe",
  296. "Mince fresh garlic. You need 1 teaspoon minched garlic for the recipe",
  297. "Dice 1 onion.",
  298. "Wash 2 cups lentils in cold water until the water runs clear.",
  299. "Put lentils in a pot with enough water to cover and bring to a boil.",
  300. "Place a cover on the pot, reduce heat to medium-low, and simmer, adding water during cooking as needed to keep covered, until tender. Cook for 15 to 20 minutes.",
  301. "Drain the lentils",
  302. "Heat vegetable oil in a large skillet over medium heat; cook and stir onions in hot oil until caramelized, about 20 minutes.",
  303. "Mix 1 tablespoon curry paste. 1 tablespoon curry powder. 1 teaspoon ground turmeric. 1 teaspoon ground cumi. 1 teaspoon chili powder. 1 teaspoon salt. 1 teaspoon white sugar. 1 teaspoon minced garlic. and 1 teaspoon minced ginger together in a large bowl.",
  304. "Stir the mix into the onions. Increase heat to high and cook, stirring constantly, until fragrant, 1 to 2 minutes.",
  305. "Stir in 1 can tomato puree, remove from heat and stir into the lentils. You are ready to serve."
  306. ],
  307. ingredients: [
  308. "You will need 2 cups red lentils, 1 large onion, 1 tablespoon vegetable oil. 2 tablespoons curry paste. 1 tablespoon curry powder. 1 teaspoon ground turmeric. 1 teaspoon ground cumin. 1 teaspoon chili powder. 1 teaspoon salt. 1 teaspoon white sugar. 1 teaspoon minced garlic. 1 teaspoon minced fresh ginger and 1 can or 14.25 ounce can tomato puree."
  309. ]
  310. }
  311. ],
  312. snack: [
  313. {
  314. name: "Homemade cheese crackers",
  315. instructions: [
  316. "Have the following ready: 8 ounces shredded sharp Cheddar cheese, 1 cup all-purpose flour, a half stick butter, some salt and some cold water.",
  317. "Cut the half stick butter in cubes.",
  318. "Combine 8 ounces schredded Cheddar cheese, 1 cup flour, the butter, and three quarter teaspoon salt in a food processor. Pulse until dough has the consistency of sand.",
  319. "Add 2 tablespoons cold water, 1 tablespoon at a time, until dough is moistened.",
  320. "Wrap dough in plastic wrap and refrigerate for 20 minutes.",
  321. "Preheat oven to 350 degrees Fahrenheit or 175 degree Celcius",
  322. "Roll dough onto a lightly floured work surface and cut into desired shapes using a cookie cutter.",
  323. "Arrange shapes on a baking sheet lined with parchment paper.",
  324. "Bake the crackers in the preheated oven until golden brown and crispy, 15 to 16 minutes. Enjoy!"
  325. ],
  326. ingredients: [
  327. "8 ounces shredded sharp Cheddar cheese, 1 cup all-purpose flour, a quarter cup butter, three quarter teaspoon salt, 2 tablespoons cold water"
  328. ]
  329. },
  330. {
  331. name: "Cream cheese caramel dip",
  332. instructions: [
  333. "Gather 16 individually wrapped caramels, a quarter cup water, 8 ounce or 1 package cream cheese and a half cup brown sugar.",
  334. "In a medium saucepan over medium-low heat, or in the microwave, melt the unwrapped caramels with a quarter cup water, stirring frequently.",
  335. "Remove from heat. In a medium bowl, cream together 1 package cream cheese and a half cup brown sugar.",
  336. "Fold in caramel mixture and enjoy this dip with sliced apples."
  337. ],
  338. ingredients: [
  339. "16 individually wrapped caramels, a quarter cup water, 8 ounce or 1 package cream cheese, a half cup brown sugar"
  340. ]
  341. },
  342. {
  343. name: "Cream cheese caramel dip",
  344. instructions: [
  345. "Grab a half cup vanilla Greek-style yogurt, 2 tablespoons applesauce, some almond extract, some ground cinnamon, 1 cup seedless grapes, 1 cup fresh strawberries, 1 cup apple chunks, 1 cup pineapple chunks, 8 wooden 6 inch skewers .",
  346. "Half 1/2 cup strawberries.",
  347. "Prepare 1 cup apple chunks",
  348. "Wash 1 cup of grapes.",
  349. "Prepare 1 cup pineapple chunks.",
  350. "Thread grapes, strawberries, apple chunks, and pineapple chunks alternatively onto skewers.",
  351. "For the dip: Stir a half cup yogurt, 2 tablespoons applesauce, one eighth of a teaspoon almond extract, and one eighth of a teaspoon ground cinnamon together in a bowl until dipping sauce is well-combined.",
  352. "Arrange finished skewers on a plate with the dip and enjoy."
  353. ],
  354. ingredients: [
  355. "a half cup vanilla Greek-style yogurt, 2 tablespoons applesauce, one eights of a teaspoon almond extract, one eights of a teaspoon ground cinnamon, 1 cup seedless grapes, 1 cup fresh strawberries, 1 cup apple chunks, 1 cup pineapple chunks, 8 wooden 6 inch skewers."
  356. ]
  357. },
  358. {
  359. name: "Baked Apple Chips",
  360. instructions: [
  361. "Get some white sugar, some ground cinnamon and 4 Granny Smith apples.",
  362. "Wash and slice 4 cored apples in rounds very thin.",
  363. "Preheat oven to 250 degrees Fahrenheit or 120 degrees Celcius.",
  364. "Line two baking sheets with parchment paper.",
  365. "Whisk 2 tablespoons white sugar and 1 tablespoon ground cinnamon together in a large bowl.",
  366. "Add apple slices and toss to coat.",
  367. "Arrange apple slices in a single layer on prepared baking sheets.",
  368. "Bake apples in the preheated oven until browned and just crisped, about 2 hours. Cool completely and store in an airtight container."
  369. ],
  370. ingredients: [
  371. "2 tablespoons white sugar, 1 tablespoon ground cinnamon, 4 Granny Smith apples"
  372. ]
  373. },
  374. {
  375. name: "Lemon Bars",
  376. instructions: [
  377. "You will need 1 and a half cups of all-purpose flour, two thirds cup of confectioners' sugar, three quarter cup softened butter, 1 cup white sugar, 3 tablespoons all-purpose flour, a quarter cup lemon juice, a third of a cup confectioners' sugar for decoration.",
  378. "Preheat the oven to 375 degrees Fahrenheit or 190 degrees Celcius. Grease a 9 times 13 inch baking pan.",
  379. "Combine 1 and a half cup flour, two thirds of a cup confectioners' sugar, and three quarter cup butter.",
  380. "Pat dough into prepared pan.",
  381. "Bake for 20 minutes in the preheated oven, until slightly golden.",
  382. "While the crust is baking, whisk together 3 eggs, 1 cup white sugar, 3 tablespoons flour, and a quarter cup lemon juice until frothy.",
  383. "Pour this lemon mixture over the hot crust.",
  384. "Return to the preheated oven for an additional 20 to 25 minutes, or until light golden brown.",
  385. "Cool on a wire rack.",
  386. "Dust the top with a thirds cup of confectioners' sugar and cut this treat into squares to serve."
  387. ],
  388. ingredients: [
  389. "1 and a half cups of all-purpose flour, two thirds cup of confectioners' sugar, three quarter cup softened butter, 1 cup white sugar, 3 tablespoons all-purpose flour, a quarter cup lemon juice, a third of a cup confectioners' sugar for decoration"
  390. ]
  391. }
  392. ]
  393. };
  394.  
  395. /***********
  396. Execution Code: Avoid editing the code below if you don't know JavaScript.
  397. ***********/
  398.  
  399. // Private methods (this is the actual code logic behind the app)
  400.  
  401. const _getCurrentStep = handler => handler.attributes['instructions'][handler.attributes['current_step']];
  402.  
  403. const _intentAndSlotPresent = handler => {
  404. try {
  405. return handler.event.request.intent.slots.mealType;
  406. }
  407. catch (e){
  408. return false;
  409. }
  410. };
  411. const _selectedMealType = handler => {
  412. return _intentAndSlotPresent(handler) && handler.event.request.intent.slots.mealType.value;
  413. };
  414. const _checkMealTypePresence = handler => {
  415. return Object.keys(recipes).includes(_selectedMealType(handler));
  416. };
  417. const _setMealType = handler => {
  418. // Reset remaining recipes in case the user went back from before
  419. handler.attributes['mealType'] = _selectedMealType(handler);
  420. handler.attributes['remainingRecipes'] = recipes[handler.attributes['mealType']];
  421. handler.handler.state = states.RECIPEMODE;
  422. handler.emitWithState("Recipe");
  423. return true;
  424. };
  425.  
  426. const _randomIndexOfArray = (array) => Math.floor(Math.random() * array.length);
  427. const _pickRandom = (array) => array[_randomIndexOfArray(array)];
  428.  
  429. // Handle user input and intents:
  430.  
  431. const states = {
  432. STARTMODE: "_STARTMODE",
  433. RECIPEMODE: "_RECIPEMODE",
  434. INSTRUCTIONSMODE: "_INSTRUCTIONSMODE",
  435. CANCELMODE: "_CANCELMODE"
  436. };
  437.  
  438.  
  439. const newSessionhandlers = {
  440. 'NewSession': function(){
  441. this.handler.state = states.STARTMODE;
  442. this.emitWithState('NewSession');
  443. },
  444. 'AMAZON.HelpIntent': function(){
  445. this.emit(':ask', HELP_START, HELP_START_REPROMPT);
  446. },
  447. 'AMAZON.CancelIntent': function(){
  448. this.emit(':tell', CANCEL_MESSAGE);
  449. },
  450. 'AMAZON.StopIntent': function(){
  451. this.emit(':tell', STOP_MESSAGE);
  452. },
  453. 'Unhandled': function(){
  454. this.emit(':ask', REPROMPT_TYPE);
  455. }
  456. };
  457.  
  458. const startModeHandlers = Alexa.CreateStateHandler(states.STARTMODE, {
  459. 'NewSession': function(startMessage = CHOOSE_TYPE_MESSAGE){
  460. if(_checkMealTypePresence(this)){
  461. // Go directly to selecting a meal if mealtype was already present in the slots
  462. _setMealType(this);
  463. }else{
  464. this.emit(':ask', startMessage, REPROMPT_TYPE);
  465. }
  466. },
  467. 'ChooseTypeIntent': function(){
  468. if(_checkMealTypePresence(this)){
  469. _setMealType(this);
  470. }else{
  471. this.emit(':ask', MEALTYPE_NOT_IN_LIST(_selectedMealType(this)));
  472. }
  473. },
  474. 'AMAZON.HelpIntent': function(){
  475. this.emit(':ask', HELP_START, HELP_START_REPROMPT);
  476. },
  477. 'AMAZON.CancelIntent': function(){
  478. this.emit(':tell', CANCEL_MESSAGE);
  479. },
  480. 'AMAZON.StopIntent': function(){
  481. this.emit(':tell', STOP_MESSAGE);
  482. },
  483. 'Unhandled': function(){
  484. this.emit(':ask', REPROMPT_TYPE);
  485. }
  486. });
  487.  
  488. const recipeModeHandlers = Alexa.CreateStateHandler(states.RECIPEMODE, {
  489. 'Recipe': function(){
  490. if(this.new){
  491. this.attributes['remainingRecipes'] = recipes[handler.attributes['mealType']];
  492. }
  493.  
  494. if(this.attributes['remainingRecipes'].length > 0){
  495. // Select random recipe and remove it form remainingRecipes
  496. this.attributes['recipe'] = this.attributes['remainingRecipes'].splice(_randomIndexOfArray(this.attributes['remainingRecipes']), 1)[0]; // Select a random recipe
  497. // Ask user to confirm selection
  498. this.emit(':ask', SUGGEST_RECIPE(this.attributes['recipe'].name));
  499. }else{
  500. this.attributes['remainingRecipes'] = recipes[this.attributes['mealType']];
  501. this.handler.state = states.CANCELMODE;
  502. this.emitWithState('NoRecipeLeftHandler');
  503. }
  504. },
  505. 'IngredientsIntent': function(){
  506. var ingredients = this.attributes['recipe'].ingredients.join(', ').replace(/,(?!.*,)/gmi, ' and'); // Add 'and' before last ingredient
  507.  
  508. this.emit(':ask', `${INGREDIENTS_INTRO} ${ingredients}. ${INGREDIENTS_ENDING}`)
  509. },
  510. 'AMAZON.YesIntent': function(){
  511. this.attributes['instructions'] = this.attributes['recipe'].instructions;
  512. this.attributes['current_step'] = 0;
  513. this.handler.state = states.INSTRUCTIONSMODE;
  514. this.emitWithState('InstructionsIntent');
  515. },
  516. 'AMAZON.NoIntent': function(){
  517. this.emitWithState('Recipe');
  518. },
  519. 'AMAZON.HelpIntent': function(){
  520. this.emit(':ask', HELP_RECIPE, HELP_RECIPE_REPROMPT);
  521. },
  522. 'AMAZON.CancelIntent': function(){
  523. this.handler.state = states.CANCELMODE;
  524. this.emitWithState('AskToCancelHandler');
  525. },
  526. 'AMAZON.StopIntent': function(){
  527. this.emit(':tell', STOP_MESSAGE);
  528. },
  529. 'Unhandled': function(){
  530. this.emit(':ask', MISUNDERSTOOD_RECIPE_ANSWER);
  531. }
  532. });
  533.  
  534. const instructionsModeHandlers = Alexa.CreateStateHandler(states.INSTRUCTIONSMODE, {
  535. 'InstructionsIntent': function(){
  536. const firstTimeInstructions = (this.attributes['current_step'] == 0) ? FIRST_TIME_INSTRUCTIONS : '';
  537. this.emit(':ask', `${_getCurrentStep(this)} ${firstTimeInstructions}`, REPROMPT_INSTRUCTIONS);
  538. },
  539. 'NextStepIntent': function(){
  540. this.attributes['current_step']++;
  541.  
  542. if(this.attributes['current_step'] < this.attributes['instructions'].length - 1){
  543. this.emitWithState('InstructionsIntent');
  544. }else{
  545. this.emitWithState('InstructionsEnded');
  546. }
  547. },
  548. 'InstructionsEnded': function(){
  549. this.emit(':tell', `${_getCurrentStep(this)} ${CLOSING_MESSAGE}`);
  550. },
  551. 'DifferentRecipeIntent': function(){
  552. this.handler.state = states.RECIPEMODE;
  553. this.emitWithState('Recipe');
  554. },
  555. 'AMAZON.HelpIntent': function(){
  556. this.emit(':ask', HELP_INSTRUCTIONS, HELP_INSTRUCTIONS_REPROMPT);
  557. },
  558. 'AMAZON.CancelIntent': function(){
  559. this.handler.state = states.CANCELMODE;
  560. this.emitWithState('AskToCancelHandler');
  561. },
  562. 'AMAZON.StopIntent': function(){
  563. this.emit(':tell', STOP_MESSAGE);
  564. },
  565. 'Unhandled': function(){
  566. this.emit(':ask', MISUNDERSTOOD_INSTRUCTIONS_ANSWER);
  567. }
  568. });
  569.  
  570.  
  571. const cancelModeHandlers = Alexa.CreateStateHandler(states.CANCELMODE, {
  572. 'NoRecipeLeftHandler': function(){
  573. this.emit(':ask', NO_REMAINING_RECIPE);
  574. },
  575. 'AskToCancelHandler': function(){
  576. this.emit(':ask', CANCEL_MESSAGE);
  577. },
  578. 'AMAZON.YesIntent': function(){
  579. this.attributes['current_step'] = 0;
  580. this.handler.state = states.STARTMODE;
  581. this.emitWithState('NewSession', REPROMPT_TYPE);
  582. },
  583. 'AMAZON.NoIntent': function(){
  584. this.emit(':tell', STOP_MESSAGE);
  585. },
  586. 'AMAZON.HelpIntent': function(){
  587. this.emit(':ask', HELP_CANCEL, HELP_CANCEL_REPROMPT);
  588. },
  589. 'AMAZON.CancelIntent': function(){
  590. this.emit(':tell', STOP_MESSAGE);
  591. },
  592. 'AMAZON.StopIntent': function(){
  593. this.emit(':tell', STOP_MESSAGE);
  594. },
  595. 'Unhandled': function(){
  596. this.emit(':ask', MISUNDERSTOOD_RECIPE_ANSWER);
  597. }
  598. });
  599.  
  600. exports.handler = (event, context, callback) => {
  601. const alexa = Alexa.handler(event, context);
  602. alexa.APP_ID = APP_ID;
  603. alexa.registerHandlers(newSessionhandlers, startModeHandlers, recipeModeHandlers, instructionsModeHandlers, cancelModeHandlers);
  604. alexa.execute();
  605. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement