Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- const Alexa = require('ask-sdk-v1adapter');
- const APP_ID = undefined;
- /***********
- Data: Customize the data below as you please.
- ***********/
- const SKILL_NAME = "Quickmeal";
- const STOP_MESSAGE = "See you next time.";
- const CANCEL_MESSAGE = "Okay. Do you want to hear a different recipe instead?";
- const HELP_START = "I have a bunch of tasty and quick recipes for you.";
- const HELP_START_REPROMPT = "Just tell me what type of meal you'd like.";
- const HELP_RECIPE = "Choose whatever recipe you want.";
- const HELP_RECIPE_REPROMPT = "Just ask me for a recipe.";
- const HELP_INSTRUCTIONS = "You can ask me to repeat the instructions or say 'next' for the next step.";
- const HELP_INSTRUCTIONS_REPROMPT = "You can say repeat, next or 'I changed my mind' for another recipe.";
- const HELP_CANCEL = "You can hear a new recipe or just not eat.";
- const HELP_CANCEL_REPROMPT = "Not eating so far caused 100% of test subjects to die.";
- const CHOOSE_TYPE_MESSAGE = "Welcome to Quickmeal! I have really nice breakfast, lunch, snack, or dinner recipes for you. What are you looking for?";
- const REPROMPT_TYPE = "You can choose a breakfast, lunch, snack, or dinner recipe. What type of meal would you like to choose?";
- 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?`;
- const RECIPE_ADJECTIVES = [
- "awesome",
- "super simple",
- "fun",
- "tasty",
- "yummy",
- "delicious",
- "delectable",
- "extremely tasty"
- ];
- 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`;
- const MISUNDERSTOOD_RECIPE_ANSWER = "Please answer with yes or no.";
- const NO_REMAINING_RECIPE = "This was it. I currently have no more recipes. Do you want to select a different meal type?"
- const INGREDIENTS_INTRO = "You will need"; // Here follows a list of ingredients
- const INGREDIENTS_ENDING = "Does that sound like a meal you want to eat?"; // Will be said after the list of ingredients
- const FIRST_TIME_INSTRUCTIONS = "Say 'next' for the next step. Say 'repeat' if you want to hear the last line of instructions again.";
- const REPROMPT_INSTRUCTIONS = "Say 'next' for the next step. Say 'repeat' if you want to hear the last line of instructions again.";
- const MISUNDERSTOOD_INSTRUCTIONS_ANSWER = "Sorry, I didn't understand you there.";
- const CLOSING_MESSAGE = "Wonderful. Hope you have a great meal and will come back for more";
- const recipes = {
- breakfast: [
- {
- name: "Lemon Ricotta Pancakes",
- instructions: [
- "Have the following ingredients ready: half cup of ricotta cheese, one large egg, one lemon and one cup of flour.",
- "First, whisk three quarter cup water or milk and half teaspoon baking soda together in a mixing bowl",
- "Add half cup ricotta cheese and one tablespoon grated lemon zest",
- "Add 1 tablespoon vegetables oil, 1 tablespoon sugar, 1 large egg, and 1/8 spoon vanilla extract to the mixture",
- "Whisk until smooth, breaking up lumps of cheese as you mix.",
- "Now add 2 tablespoons melted butter and 1 tablespoon lemon juice. ",
- `Add 1 cup plus 2 tablespoons self-rising flour.`,
- "Whisk together, stirring until most of flour disappears into the batter.",
- "Let batter sit at room temperature about 15 minutes.",
- "Heat lightly greased cast iron skillet or griddle over medium-high heat.",
- "Portion out 1/4 cup scoops of batter onto skillet and cook the pancakes in batches.",
- "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."
- ],
- ingredients: [
- "three quarters cup cold water or milk",
- "half teaspoon baking soda",
- "half cup ricotta cheese",
- "one tablespoon grated lemon zest",
- "one tablespoon vegetable oil",
- "one tablespoon white sugar",
- "one large egg",
- "one eighth teaspoon vanilla extract",
- "two tablespoons melted butter",
- "one tablespoon lemon juice",
- "one cup self-rising flour",
- "two tablespoons self-rising flour"
- ] },
- {
- name: "Avocado Toast",
- instructions: [
- "Get whole-grain bread, 1 avocado and one bunch of fresh parsley.",
- "Wash and chop 1 bunch of fresh parsley. You will need 2 tablespoons for the meal.",
- "Juice a half lemon.",
- "Scoop 1 avocado into a bowl.",
- "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.",
- "Mash everything together using a potato masher.",
- "Spread avocado mixture into each piece of toast. If you like you can top each toast with a fried egg."
- ],
- ingredients: [
- "4 slices whole-grain bread",
- "1 avocado",
- "1 small bunch of fresh parsley",
- "one and a half teaspoons olive oil",
- "a half of lemon",
- "a half teaspoon salt",
- "a half teaspoon ground black pepper",
- "a half teaspoon onion powder",
- "a half teaspoon garlic powder"
- ]
- },
- {
- name: "Breakfast Smoothie",
- instructions: [
- "Get some spinach, 1 frozen banana, half of avocado and almond milk.",
- "Wash half cup spinach and drain.",
- "Cut 1 frozen banana into chunks.",
- "Put into the blender the spinach, the banana chunks, 1/2 avocado, 1/4 cup almond milk.",
- "Add 1/2 teaspoon vanilla extract and 1/4 teaspoon gound cinnamon and blend until smooth."
- ],
- ingredients: [
- "half cup of spinach",
- "1 frozen banana",
- "a half an avocado",
- "a quarter cup of almond milk",
- "a half teaspoon vanilla extract",
- "one quarter teaspoon of ground cinnamon"
- ]
- },
- {
- name: "Banana Wraps",
- instructions: [
- "Have the following ingredients ready: 1 banana, 2 large whole wheat tortillas, some peanut butter, some granola and some honey.",
- "Peel 1 banana and half lengthwise.",
- "Stir together the peanut butter and honey in a bowl until smooth.",
- "Mix in a quarter cup coconut and 1/2 cup granola. Divide the mixture in half, and spread half over each tortilla.",
- "Place a banana half in the center of a tortilla, and roll up. Slice the rolls in half and enjoy."
- ],
- ingredients: [
- "4 teaspoons peanut butter",
- "2 tablespoons honey",
- "a half cup granola",
- "1 banana",
- "2 large whole wheat tortillas",
- "a quarter cup shredded coconut, if desired"
- ]
- },
- {
- name: "Pizza Muffins",
- instructions: [
- "Get 1 can of refrigerated buttermilk biscuit dough, some pizza sauce, shredded mozzerella cheese and pepperoni.",
- "Preheat oven to 425 degrees Fahrenheit or 220 degrees Celcius. Spray 10 muffin cups with cooking spray.",
- "Press biscuits, one at a time, between hands to flatten. Place each flattened biscuit in a muffin cup.",
- "Press biscuit dough into bottom and up sides of muffin form.",
- "Set aside for biscuit to settle and slightly rise, about 5 minutes. Lightly press biscuits into cups as needed.",
- "Spoon 1 tablespoon pizza sauce into each biscuit; top each with 1 slice pepperoni and 1 tablespoon mozzarella cheese.",
- "Bake in the preheated oven until biscuit is lightly browned and cheese is melted, about 10 minutes.",
- "Remove each pizza from tin and place on a cooling rack, about 5 minutes."
- ],
- ingredients: [
- "1 can or 10 ounce refrigerated buttermilk biscuit dough",
- "10 tablespoons pizza sauce",
- "10 slices pepperoni",
- "10 tablespoons shredded mozzarella cheese",
- "Some cooking spray"
- ]
- }
- ],
- lunch: [
- {
- name: "Japanese Cucumber",
- instructions: [
- "Have the following ingredients ready: 2 cucumbers, some fresh ginger and rice vinegar.",
- "Peel 2 cucumbers and half lengthwise.",
- "Scoop out any larger seeds.",
- "Slice crosswise into very thin slices.",
- "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.",
- "Place cucumbers inside of the bowl, stir so that cucumbers are coated with the mixture.",
- "Refrigerate the bowl of cucumbers for at least 1 hour before serving."
- ],
- ingredients: [
- "2 large cucumbers",
- "one third cup rice vinegar",
- "4 teaspoons white sugar",
- "1 teaspoon salt",
- "one and a half teaspoons minced fresh ginger root"
- ]
- },
- {
- name: "Strawberry Avocado Salad",
- instructions: [
- "First, get 1 avocado, 10 strawberries, green salad and some chopped pecans.",
- "Slice 1 avocado",
- "Wash and slice 10 strawberries",
- "Wash 2 cups salad greens and drain",
- "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.",
- "Place the salad greens in a serving bowl, and top with sliced avocado and strawberries.",
- "Drizzle dressing over everything, then sprinkle with 1/2 cup chopped pecans. You can serve it warm or chilled."
- ],
- ingredients: [
- "2 tablespoons white sugar",
- "2 tablespoons olive oil",
- "4 teaspoons honey",
- "1 tablespoon cider vinegar",
- "1 teaspoon lemon juice",
- "2 cups torn salad greens",
- "1 avocado",
- "10 strawberries",
- "a half cup chopped pecans"
- ]
- },
- {
- name: "Creamy Dill Cucumber Toasties",
- instructions: [
- "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.",
- "Cut 1 baguette into 1/2 inch thick circles.",
- "Slice 1 cucumber",
- "In a medium bowl, mix together 1 package softened cream cheese, 1 package dry dressing mix and a half cup mayonnaise.",
- "Spread a thin layer of the cream cheese mixture on a slice of bread, and top with a slice of cucumber.",
- "Sprinkle with 2 teaspoons dried dill weed and enjoy."
- ],
- ingredients: [
- "8 ounce or 1 package cream cheese",
- "7 ounce or 1 package dry Italian-style salad dressing mix",
- "1/2 cup mayonaise",
- "1 French baguette",
- "1 cucumber",
- "2 teaspoons dried dill weed"
- ]
- },
- {
- name: "Watermelon salad with feta cheese",
- instructions: [
- "Grab a watermelon, some fresh mint and a half cup of crumbled feta cheese.",
- "Cut the watermelon in cubes.",
- "Wash and chop the fresh mint.",
- "Toss the mint and crumbled feta cheese over the watermelon and chill until ready to serve."
- ],
- ingredients: [
- "a quarter of a watermelon",
- "half cup of crumbled feta cheese",
- "some fresh mint"
- ]
- }
- ],
- dinner: [
- {
- name: "Sesame Noodle Salad",
- instructions: [
- "Have the following ingredients ready: 1 package angel hair pasta, 1 green onion, 1 red bell pepper, some sesame oil and soy sauce.",
- "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.",
- "Cook the pasta uncovered, stirring occasionally, until the pasta has cooked through, but is still firm to the bite, 4 to 5 minutes.",
- "In the meantime, chop 1 green onion.",
- "Dice 1 red bell pepper",
- "Drain the pasta in a colander set in the sink.",
- "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. ",
- "Toss the pasta in the dressing, then sprinkle with a half cup of sesame seeds, green onion, and bell pepper.",
- "Serve warm, or cover and refrigerate for a cold salad."
- ],
- ingredients: [
- "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."
- ]
- },
- {
- name: "Fried breaded tofu",
- instructions: [
- "Get 1 package extra firm tofu, vegetable broth, some nutritional yeast, some flour, sage and cayenne pepper.",
- "Cut pressed tofu into half inch thick slices; then cut again into half inch wide sticks.",
- "Place tofu in a bowl, and pour 2 cup vegetable broth over the top. Set aside to soak.",
- "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.",
- "Warm oil in a large skillet over medium-high heat.",
- "Remove tofu sticks from broth, and squeeze most, but not all of the liquid from them.",
- "Roll sticks in breading several times. The sticks should be dry to touch.",
- "Place tofu in hot oil; fry until crisp and browned on all sides. Add more oil if necessary."
- ],
- ingredients: [
- "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."
- ]
- },
- {
- name: "Dagmar's Chicken Ragout",
- instructions: [
- "Have the following ready: 1 whole chicken, 1 stick butter, 2 onions, 2 cans of mushrooms and fresh lemonjuice.",
- "For the chicken soup, cube the onions and saute them with some butter in a big stockpot. ",
- "Add the whole chicken, 1 tablespoon salt, some pepper and enough water to cover the chicken.",
- "Cook the chicken for 1 hour at medium to low heat.",
- "Place the chicken on a plate and pull the meat from the bones. Discard the bones.",
- "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.",
- "Add gradually 1 cup of chicken stock to the mixture and stir with a whisk.",
- "Continue adding another cup of chicken stock to the mixture and stir.",
- "Gradually add 2 cups of chicken stock and stir until it becomes a smooth gravy.",
- "Add 2 cans of drained mushrooms to the sauce.",
- "Add the pulled chicken to the sauce and stir. ",
- "Add 1-2 tablespoons of fresh lemon juice according to your taste. Serve this comforting meal with yellow rice and buttered vegetables."
- ],
- ingredients: [
- "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."
- ]
- },
- {
- name: "Red lentil curry",
- instructions: [
- "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.",
- "Mince 1 fresh ginger root. You need 1 teaspoon for the recipe",
- "Mince fresh garlic. You need 1 teaspoon minched garlic for the recipe",
- "Dice 1 onion.",
- "Wash 2 cups lentils in cold water until the water runs clear.",
- "Put lentils in a pot with enough water to cover and bring to a boil.",
- "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.",
- "Drain the lentils",
- "Heat vegetable oil in a large skillet over medium heat; cook and stir onions in hot oil until caramelized, about 20 minutes.",
- "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.",
- "Stir the mix into the onions. Increase heat to high and cook, stirring constantly, until fragrant, 1 to 2 minutes.",
- "Stir in 1 can tomato puree, remove from heat and stir into the lentils. You are ready to serve."
- ],
- ingredients: [
- "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."
- ]
- }
- ],
- snack: [
- {
- name: "Homemade cheese crackers",
- instructions: [
- "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.",
- "Cut the half stick butter in cubes.",
- "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.",
- "Add 2 tablespoons cold water, 1 tablespoon at a time, until dough is moistened.",
- "Wrap dough in plastic wrap and refrigerate for 20 minutes.",
- "Preheat oven to 350 degrees Fahrenheit or 175 degree Celcius",
- "Roll dough onto a lightly floured work surface and cut into desired shapes using a cookie cutter.",
- "Arrange shapes on a baking sheet lined with parchment paper.",
- "Bake the crackers in the preheated oven until golden brown and crispy, 15 to 16 minutes. Enjoy!"
- ],
- ingredients: [
- "8 ounces shredded sharp Cheddar cheese, 1 cup all-purpose flour, a quarter cup butter, three quarter teaspoon salt, 2 tablespoons cold water"
- ]
- },
- {
- name: "Cream cheese caramel dip",
- instructions: [
- "Gather 16 individually wrapped caramels, a quarter cup water, 8 ounce or 1 package cream cheese and a half cup brown sugar.",
- "In a medium saucepan over medium-low heat, or in the microwave, melt the unwrapped caramels with a quarter cup water, stirring frequently.",
- "Remove from heat. In a medium bowl, cream together 1 package cream cheese and a half cup brown sugar.",
- "Fold in caramel mixture and enjoy this dip with sliced apples."
- ],
- ingredients: [
- "16 individually wrapped caramels, a quarter cup water, 8 ounce or 1 package cream cheese, a half cup brown sugar"
- ]
- },
- {
- name: "Cream cheese caramel dip",
- instructions: [
- "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 .",
- "Half 1/2 cup strawberries.",
- "Prepare 1 cup apple chunks",
- "Wash 1 cup of grapes.",
- "Prepare 1 cup pineapple chunks.",
- "Thread grapes, strawberries, apple chunks, and pineapple chunks alternatively onto skewers.",
- "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.",
- "Arrange finished skewers on a plate with the dip and enjoy."
- ],
- ingredients: [
- "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."
- ]
- },
- {
- name: "Baked Apple Chips",
- instructions: [
- "Get some white sugar, some ground cinnamon and 4 Granny Smith apples.",
- "Wash and slice 4 cored apples in rounds very thin.",
- "Preheat oven to 250 degrees Fahrenheit or 120 degrees Celcius.",
- "Line two baking sheets with parchment paper.",
- "Whisk 2 tablespoons white sugar and 1 tablespoon ground cinnamon together in a large bowl.",
- "Add apple slices and toss to coat.",
- "Arrange apple slices in a single layer on prepared baking sheets.",
- "Bake apples in the preheated oven until browned and just crisped, about 2 hours. Cool completely and store in an airtight container."
- ],
- ingredients: [
- "2 tablespoons white sugar, 1 tablespoon ground cinnamon, 4 Granny Smith apples"
- ]
- },
- {
- name: "Lemon Bars",
- instructions: [
- "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.",
- "Preheat the oven to 375 degrees Fahrenheit or 190 degrees Celcius. Grease a 9 times 13 inch baking pan.",
- "Combine 1 and a half cup flour, two thirds of a cup confectioners' sugar, and three quarter cup butter.",
- "Pat dough into prepared pan.",
- "Bake for 20 minutes in the preheated oven, until slightly golden.",
- "While the crust is baking, whisk together 3 eggs, 1 cup white sugar, 3 tablespoons flour, and a quarter cup lemon juice until frothy.",
- "Pour this lemon mixture over the hot crust.",
- "Return to the preheated oven for an additional 20 to 25 minutes, or until light golden brown.",
- "Cool on a wire rack.",
- "Dust the top with a thirds cup of confectioners' sugar and cut this treat into squares to serve."
- ],
- ingredients: [
- "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"
- ]
- }
- ]
- };
- /***********
- Execution Code: Avoid editing the code below if you don't know JavaScript.
- ***********/
- // Private methods (this is the actual code logic behind the app)
- const _getCurrentStep = handler => handler.attributes['instructions'][handler.attributes['current_step']];
- const _intentAndSlotPresent = handler => {
- try {
- return handler.event.request.intent.slots.mealType;
- }
- catch (e){
- return false;
- }
- };
- const _selectedMealType = handler => {
- return _intentAndSlotPresent(handler) && handler.event.request.intent.slots.mealType.value;
- };
- const _checkMealTypePresence = handler => {
- return Object.keys(recipes).includes(_selectedMealType(handler));
- };
- const _setMealType = handler => {
- // Reset remaining recipes in case the user went back from before
- handler.attributes['mealType'] = _selectedMealType(handler);
- handler.attributes['remainingRecipes'] = recipes[handler.attributes['mealType']];
- handler.handler.state = states.RECIPEMODE;
- handler.emitWithState("Recipe");
- return true;
- };
- const _randomIndexOfArray = (array) => Math.floor(Math.random() * array.length);
- const _pickRandom = (array) => array[_randomIndexOfArray(array)];
- // Handle user input and intents:
- const states = {
- STARTMODE: "_STARTMODE",
- RECIPEMODE: "_RECIPEMODE",
- INSTRUCTIONSMODE: "_INSTRUCTIONSMODE",
- CANCELMODE: "_CANCELMODE"
- };
- const newSessionhandlers = {
- 'NewSession': function(){
- this.handler.state = states.STARTMODE;
- this.emitWithState('NewSession');
- },
- 'AMAZON.HelpIntent': function(){
- this.emit(':ask', HELP_START, HELP_START_REPROMPT);
- },
- 'AMAZON.CancelIntent': function(){
- this.emit(':tell', CANCEL_MESSAGE);
- },
- 'AMAZON.StopIntent': function(){
- this.emit(':tell', STOP_MESSAGE);
- },
- 'Unhandled': function(){
- this.emit(':ask', REPROMPT_TYPE);
- }
- };
- const startModeHandlers = Alexa.CreateStateHandler(states.STARTMODE, {
- 'NewSession': function(startMessage = CHOOSE_TYPE_MESSAGE){
- if(_checkMealTypePresence(this)){
- // Go directly to selecting a meal if mealtype was already present in the slots
- _setMealType(this);
- }else{
- this.emit(':ask', startMessage, REPROMPT_TYPE);
- }
- },
- 'ChooseTypeIntent': function(){
- if(_checkMealTypePresence(this)){
- _setMealType(this);
- }else{
- this.emit(':ask', MEALTYPE_NOT_IN_LIST(_selectedMealType(this)));
- }
- },
- 'AMAZON.HelpIntent': function(){
- this.emit(':ask', HELP_START, HELP_START_REPROMPT);
- },
- 'AMAZON.CancelIntent': function(){
- this.emit(':tell', CANCEL_MESSAGE);
- },
- 'AMAZON.StopIntent': function(){
- this.emit(':tell', STOP_MESSAGE);
- },
- 'Unhandled': function(){
- this.emit(':ask', REPROMPT_TYPE);
- }
- });
- const recipeModeHandlers = Alexa.CreateStateHandler(states.RECIPEMODE, {
- 'Recipe': function(){
- if(this.new){
- this.attributes['remainingRecipes'] = recipes[handler.attributes['mealType']];
- }
- if(this.attributes['remainingRecipes'].length > 0){
- // Select random recipe and remove it form remainingRecipes
- this.attributes['recipe'] = this.attributes['remainingRecipes'].splice(_randomIndexOfArray(this.attributes['remainingRecipes']), 1)[0]; // Select a random recipe
- // Ask user to confirm selection
- this.emit(':ask', SUGGEST_RECIPE(this.attributes['recipe'].name));
- }else{
- this.attributes['remainingRecipes'] = recipes[this.attributes['mealType']];
- this.handler.state = states.CANCELMODE;
- this.emitWithState('NoRecipeLeftHandler');
- }
- },
- 'IngredientsIntent': function(){
- var ingredients = this.attributes['recipe'].ingredients.join(', ').replace(/,(?!.*,)/gmi, ' and'); // Add 'and' before last ingredient
- this.emit(':ask', `${INGREDIENTS_INTRO} ${ingredients}. ${INGREDIENTS_ENDING}`)
- },
- 'AMAZON.YesIntent': function(){
- this.attributes['instructions'] = this.attributes['recipe'].instructions;
- this.attributes['current_step'] = 0;
- this.handler.state = states.INSTRUCTIONSMODE;
- this.emitWithState('InstructionsIntent');
- },
- 'AMAZON.NoIntent': function(){
- this.emitWithState('Recipe');
- },
- 'AMAZON.HelpIntent': function(){
- this.emit(':ask', HELP_RECIPE, HELP_RECIPE_REPROMPT);
- },
- 'AMAZON.CancelIntent': function(){
- this.handler.state = states.CANCELMODE;
- this.emitWithState('AskToCancelHandler');
- },
- 'AMAZON.StopIntent': function(){
- this.emit(':tell', STOP_MESSAGE);
- },
- 'Unhandled': function(){
- this.emit(':ask', MISUNDERSTOOD_RECIPE_ANSWER);
- }
- });
- const instructionsModeHandlers = Alexa.CreateStateHandler(states.INSTRUCTIONSMODE, {
- 'InstructionsIntent': function(){
- const firstTimeInstructions = (this.attributes['current_step'] == 0) ? FIRST_TIME_INSTRUCTIONS : '';
- this.emit(':ask', `${_getCurrentStep(this)} ${firstTimeInstructions}`, REPROMPT_INSTRUCTIONS);
- },
- 'NextStepIntent': function(){
- this.attributes['current_step']++;
- if(this.attributes['current_step'] < this.attributes['instructions'].length - 1){
- this.emitWithState('InstructionsIntent');
- }else{
- this.emitWithState('InstructionsEnded');
- }
- },
- 'InstructionsEnded': function(){
- this.emit(':tell', `${_getCurrentStep(this)} ${CLOSING_MESSAGE}`);
- },
- 'DifferentRecipeIntent': function(){
- this.handler.state = states.RECIPEMODE;
- this.emitWithState('Recipe');
- },
- 'AMAZON.HelpIntent': function(){
- this.emit(':ask', HELP_INSTRUCTIONS, HELP_INSTRUCTIONS_REPROMPT);
- },
- 'AMAZON.CancelIntent': function(){
- this.handler.state = states.CANCELMODE;
- this.emitWithState('AskToCancelHandler');
- },
- 'AMAZON.StopIntent': function(){
- this.emit(':tell', STOP_MESSAGE);
- },
- 'Unhandled': function(){
- this.emit(':ask', MISUNDERSTOOD_INSTRUCTIONS_ANSWER);
- }
- });
- const cancelModeHandlers = Alexa.CreateStateHandler(states.CANCELMODE, {
- 'NoRecipeLeftHandler': function(){
- this.emit(':ask', NO_REMAINING_RECIPE);
- },
- 'AskToCancelHandler': function(){
- this.emit(':ask', CANCEL_MESSAGE);
- },
- 'AMAZON.YesIntent': function(){
- this.attributes['current_step'] = 0;
- this.handler.state = states.STARTMODE;
- this.emitWithState('NewSession', REPROMPT_TYPE);
- },
- 'AMAZON.NoIntent': function(){
- this.emit(':tell', STOP_MESSAGE);
- },
- 'AMAZON.HelpIntent': function(){
- this.emit(':ask', HELP_CANCEL, HELP_CANCEL_REPROMPT);
- },
- 'AMAZON.CancelIntent': function(){
- this.emit(':tell', STOP_MESSAGE);
- },
- 'AMAZON.StopIntent': function(){
- this.emit(':tell', STOP_MESSAGE);
- },
- 'Unhandled': function(){
- this.emit(':ask', MISUNDERSTOOD_RECIPE_ANSWER);
- }
- });
- exports.handler = (event, context, callback) => {
- const alexa = Alexa.handler(event, context);
- alexa.APP_ID = APP_ID;
- alexa.registerHandlers(newSessionhandlers, startModeHandlers, recipeModeHandlers, instructionsModeHandlers, cancelModeHandlers);
- alexa.execute();
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement