Ejemplo n.º 1
0
 def LaunchRequest(self, handlers, persistant_attributes, attributes, slots):
     if persistant_attributes['invocations'] == 1:  # first time! Say hello!
         attributes[core.STATE_KEY] = core.States.ASK_TUTORIAL
         return responder.ask(
             "Hi, I'm your new cookbook. Would you like start off with a tutorial?", None,
             attributes)
     else:
         if attributes['new']:
             attributes[core.STATE_KEY] = core.States.NEW_RECIPE
             return responder.ask("Welcome back. What would you like to make?", None, attributes)
         else:
             persistant_attributes[core.STATE_KEY] = core.States.INITIAL_STATE
             return responder.tell("I've already been launched.")
Ejemplo n.º 2
0
    def FavoriteIntent(self, handlers, persistant_attributes, attributes,
                       slots):
        if 'current_recipe' in attributes:
            current_recipe = attributes['current_recipe']
            if 'recipes' in persistant_attributes:
                if current_recipe in persistant_attributes['recipes']:
                    attributes['tmp_state'] = attributes[core.STATE_KEY]
                    attributes[
                        core.STATE_KEY] = core.States.CONFIRM_OVERWRITE_RECIPE
                    return responder.ask(
                        "This recipe is already in your cookbook. \
                            If you want to overwrite the existing recipe with this one, \
                            say yes. Say no to cancel and leave the existing recipe.",
                        "Do you want to overwrite with this recipe?",
                        attributes)
                else:
                    # it's new, so add it
                    persistant_attributes['recipes'].append(current_recipe)
            else:
                # recipe list doesn't exist
                persistant_attributes['recipes'] = [current_recipe]

        else:
            return responder.tell(
                "I can't favorite a recipe because we're not working on one. \
                    Try searching for a recipe first")
Ejemplo n.º 3
0
    def StartNewRecipeIntent(self, handlers, persistant_attributes, attributes,
                             slots):
        if 'RecipeName' not in slots or 'value' not in slots['RecipeName']:
            attributes['asking_recipe_name'] = True
            attributes[core.STATE_KEY] = core.States.NEW_RECIPE
            return responder.ask("Sorry, what's the recipe?", None, attributes)
        else:
            username = persistant_attributes.get('bigoven_username', None)

            if not username:
                # set url for linking accounts--not very secure.
                if stage.PROD:
                    link_url = 'https://petermitrano.pythonanywhere.com/'
                else:
                    link_url = 'http://localhost:5000/'
                # user has to start over here, sorry.
                persistant_attributes[
                    core.STATE_KEY] = core.States.INITIAL_STATE
                return responder.tell_with_card(
                    "I was unable to find your bigoven username. \
                        Use the link I sent you to connect your bigoven account.",
                    "Link BigOven Account",
                    "%s?amazonId=%s" % (link_url, attributes['user']), None)

            recipe_name = slots['RecipeName']['value']

            return self.start_recipe_search(recipe_name, username, attributes)
Ejemplo n.º 4
0
 def LaunchRequest(self, handlers, persistant_attributes, attributes,
                   slots):
     if persistant_attributes['invocations'] == 1:  # first time! Say hello!
         attributes[core.STATE_KEY] = core.States.ASK_TUTORIAL
         return responder.ask(
             "Hi, I'm your new cookbook. Would you like start off with a tutorial?",
             None, attributes)
     else:
         if attributes['new']:
             attributes[core.STATE_KEY] = core.States.NEW_RECIPE
             return responder.ask(
                 "Welcome back. What would you like to make?", None,
                 attributes)
         else:
             persistant_attributes[
                 core.STATE_KEY] = core.States.INITIAL_STATE
             return responder.tell("I've already been launched.")
Ejemplo n.º 5
0
    def start_recipe_search(self, recipe_name, username, attributes):
        # search the users recipes to find appropriate recipes.
        # the value here is a (possibly empty) list of recipes in order
        # of some ranking I have yet to devise.
        recipes = recipes_helper.search_my_recipes(recipe_name, username)

        # TODO: here would be a good spot to ask questions to narrow down
        # which recipe the user wants to make. for now just pick the first one.
        if len(recipes) == 0:
            attributes[core.STATE_KEY] = core.States.ASK_SEARCH
            attributes['current_recipe_name'] = recipe_name
            return responder.ask("I didn't find any recipe for " + recipe_name +
                                 ", In your cookbook. Should I find one online?",
                                 "Do you want to find another recipe?", attributes)
        else:
            attributes[core.STATE_KEY] = core.States.ASK_MAKE_COOKBOOK
            best_guess_recipe_name = recipes[0]['Title']
            attributes['current_recipe'] = recipes[0]
            return responder.ask("I found a recipe for " + best_guess_recipe_name +
                                 ", In your cookbook. Do you want to use that?", None, attributes)
Ejemplo n.º 6
0
    def start_recipe_search(self, recipe_name, username, attributes):
        # search the users recipes to find appropriate recipes.
        # the value here is a (possibly empty) list of recipes in order
        # of some ranking I have yet to devise.
        recipes = recipes_helper.search_my_recipes(recipe_name, username)

        # TODO: here would be a good spot to ask questions to narrow down
        # which recipe the user wants to make. for now just pick the first one.
        if len(recipes) == 0:
            attributes[core.STATE_KEY] = core.States.ASK_SEARCH
            attributes['current_recipe_name'] = recipe_name
            return responder.ask(
                "I didn't find any recipe for " + recipe_name +
                ", In your cookbook. Should I find one online?",
                "Do you want to find another recipe?", attributes)
        else:
            attributes[core.STATE_KEY] = core.States.ASK_MAKE_COOKBOOK
            best_guess_recipe_name = recipes[0]['Title']
            attributes['current_recipe'] = recipes[0]
            return responder.ask(
                "I found a recipe for " + best_guess_recipe_name +
                ", In your cookbook. Do you want to use that?", None,
                attributes)
Ejemplo n.º 7
0
    def AMAZON_YesIntent(self, handlers, persistant_attributes, attributes, slots):
        # take the time to download the recipe
        if 'search_recipe_result' not in attributes:
            return responder.tell(
                "I've forgotten which recipe you wanted to make. Please start over")

        name = attributes['search_recipe_result']['Title']
        recipe_id = attributes['search_recipe_result']['RecipeID']
        recipe = recipes_helper.get_online_recipe(attributes['search_recipe_result'])

        if not recipe:
            return responder.tell("Sorry, I couldn't find the recipe %s, with id %s" %
                                  (name, recipe_id))

        attributes['current_recipe'] = recipe

        attributes[core.STATE_KEY] = core.States.INGREDIENTS_OR_INSTRUCTIONS
        return responder.ask("Do you want to start with the ingredients or the instructions?", None,
                             attributes)
Ejemplo n.º 8
0
    def AMAZON_YesIntent(self, handlers, persistant_attributes, attributes, slots):
        # search for recipe
        if 'current_recipe_name' not in attributes:
            return responder.tell(
                "I'm not sure what recipe you are searching for. Please start over")

        recipe_name = attributes['current_recipe_name']
        recipes = recipes_helper.search_online_recipes(recipe_name)

        if len(recipes) == 0:
            persistant_attributes[core.STATE_KEY] = core.States.INITIAL_STATE
            return responder.tell("I don't know of any recipes for that. Try something else")

        else:
            attributes[core.STATE_KEY] = core.States.ASK_MAKE_ONLINE
            best_guess_recipe_name = recipes[0]['Title']
            attributes['search_recipe_result'] = recipes[0]
            return responder.ask(
                "I found a recipe for " + best_guess_recipe_name + ". Do you want to use that?",
                None, attributes)
Ejemplo n.º 9
0
    def FavoriteIntent(self, handlers, persistant_attributes, attributes, slots):
        if 'current_recipe' in attributes:
            current_recipe = attributes['current_recipe']
            if 'recipes' in persistant_attributes:
                if current_recipe in persistant_attributes['recipes']:
                    attributes['tmp_state'] = attributes[core.STATE_KEY]
                    attributes[core.STATE_KEY] = core.States.CONFIRM_OVERWRITE_RECIPE
                    return responder.ask("This recipe is already in your cookbook. \
                            If you want to overwrite the existing recipe with this one, \
                            say yes. Say no to cancel and leave the existing recipe.",
                                         "Do you want to overwrite with this recipe?", attributes)
                else:
                    # it's new, so add it
                    persistant_attributes['recipes'].append(current_recipe)
            else:
                # recipe list doesn't exist
                persistant_attributes['recipes'] = [current_recipe]

        else:
            return responder.tell("I can't favorite a recipe because we're not working on one. \
                    Try searching for a recipe first")
Ejemplo n.º 10
0
    def AMAZON_YesIntent(self, handlers, persistant_attributes, attributes,
                         slots):
        # search for recipe
        if 'current_recipe_name' not in attributes:
            return responder.tell(
                "I'm not sure what recipe you are searching for. Please start over"
            )

        recipe_name = attributes['current_recipe_name']
        recipes = recipes_helper.search_online_recipes(recipe_name)

        if len(recipes) == 0:
            persistant_attributes[core.STATE_KEY] = core.States.INITIAL_STATE
            return responder.tell(
                "I don't know of any recipes for that. Try something else")

        else:
            attributes[core.STATE_KEY] = core.States.ASK_MAKE_ONLINE
            best_guess_recipe_name = recipes[0]['Title']
            attributes['search_recipe_result'] = recipes[0]
            return responder.ask(
                "I found a recipe for " + best_guess_recipe_name +
                ". Do you want to use that?", None, attributes)
Ejemplo n.º 11
0
    def StartNewRecipeIntent(self, handlers, persistant_attributes, attributes, slots):
        if 'RecipeName' not in slots or 'value' not in slots['RecipeName']:
            attributes['asking_recipe_name'] = True
            attributes[core.STATE_KEY] = core.States.NEW_RECIPE
            return responder.ask("Sorry, what's the recipe?", None, attributes)
        else:
            username = persistant_attributes.get('bigoven_username', None)

            if not username:
                # set url for linking accounts--not very secure.
                if stage.PROD:
                    link_url = 'https://petermitrano.pythonanywhere.com/'
                else:
                    link_url = 'http://localhost:5000/'
                # user has to start over here, sorry.
                persistant_attributes[core.STATE_KEY] = core.States.INITIAL_STATE
                return responder.tell_with_card("I was unable to find your bigoven username. \
                        Use the link I sent you to connect your bigoven account.",
                                                "Link BigOven Account", "%s?amazonId=%s" %
                                                (link_url, attributes['user']), None)

            recipe_name = slots['RecipeName']['value']

            return self.start_recipe_search(recipe_name, username, attributes)
Ejemplo n.º 12
0
    def AMAZON_YesIntent(self, handlers, persistant_attributes, attributes,
                         slots):
        # take the time to download the recipe
        if 'search_recipe_result' not in attributes:
            return responder.tell(
                "I've forgotten which recipe you wanted to make. Please start over"
            )

        name = attributes['search_recipe_result']['Title']
        recipe_id = attributes['search_recipe_result']['RecipeID']
        recipe = recipes_helper.get_online_recipe(
            attributes['search_recipe_result'])

        if not recipe:
            return responder.tell(
                "Sorry, I couldn't find the recipe %s, with id %s" %
                (name, recipe_id))

        attributes['current_recipe'] = recipe

        attributes[core.STATE_KEY] = core.States.INGREDIENTS_OR_INSTRUCTIONS
        return responder.ask(
            "Do you want to start with the ingredients or the instructions?",
            None, attributes)
Ejemplo n.º 13
0
 def AMAZON_NoIntent(self, handlers, persistant_attributes, attributes, slots):
     attributes[core.STATE_KEY] = core.States.ASK_SEARCH
     return responder.ask("I could search for one online?", None, attributes)
Ejemplo n.º 14
0
 def AMAZON_NoIntent(self, handlers, persistant_attributes, attributes, slots):
     attributes[core.STATE_KEY] = core.States.INITIAL_STATE
     return responder.ask("What can I help you with? Try asking to start a new recipe.", None,
                          attributes)
Ejemplo n.º 15
0
 def Unhandled(self, handlers, persistant_attributes, attributes, slots):
     return responder.ask(
         "I'm confused, Do you want to search online for a recipe? Try saying yes or no.", None,
         attributes)
Ejemplo n.º 16
0
 def AMAZON_NoIntent(self, handlers, persistant_attributes, attributes, slots):
     attributes[core.STATE_KEY] = core.States.ASK_SEARCH
     return responder.ask("then what can I do for you?", None, attributes)
Ejemplo n.º 17
0
 def AMAZON_NoIntent(self, handlers, persistant_attributes, attributes, slots):
     attributes[core.STATE_KEY] = core.States.PROMPT_FOR_START
     return responder.ask("Are you ready to start making something?", None, attributes)
Ejemplo n.º 18
0
 def Unhandled(self, handlers, persistant_attributes, attributes, slots):
     return responder.ask(
         "I'm confused. Do you want to start with a tutorial? Try saying yes or no.", None,
         attributes)
Ejemplo n.º 19
0
 def test_ask(self):
     response = responder.ask("ask", None, {})
     self.assertTrue(responder.is_valid(response))
     response = responder.ask("ask", "reprompt", {})
     self.assertTrue(responder.is_valid(response))
Ejemplo n.º 20
0
 def Unhandled(self, handlers, persistant_attributes, attributes, slots):
     persistant_attributes[core.STATE_KEY] = attributes[core.STATE_KEY]
     return responder.ask("I'm not sure what you mean. \
             Do you want to overwrite the existing recipe? Say yes or no", None, attributes)
Ejemplo n.º 21
0
 def AMAZON_NoIntent(self, handlers, persistant_attributes, attributes,
                     slots):
     attributes[core.STATE_KEY] = core.States.ASK_SEARCH
     return responder.ask("then what can I do for you?", None, attributes)
Ejemplo n.º 22
0
 def Unhandled(self, handlers, persistant_attributes, attributes, slots):
     return responder.ask("I'm confused, Do you want to make the recipe from your cookbook?",
                          None, attributes)
Ejemplo n.º 23
0
 def AMAZON_YesIntent(self, handlers, persistant_attributes, attributes, slots):
     attributes[core.STATE_KEY] = core.States.INGREDIENTS_OR_INSTRUCTIONS
     return responder.ask("Do you want to start with the ingredients or the instructions?", None,
                          attributes)
Ejemplo n.º 24
0
 def AMAZON_YesIntent(self, handlers, persistant_attributes, attributes, slots):
     attributes[core.STATE_KEY] = core.States.NEW_RECIPE
     return responder.ask(
         "What do you want to make? You can say something like, let's make steak, or how do I cook fried chicken.",
         None, attributes)
Ejemplo n.º 25
0
 def Unhandled(self, handlers, persistant_attributes, attributes, slots):
     return responder.ask("I'm confused. Do you want to start with ingredients or instructions?",
                          "Say which one you want.", attributes)
Ejemplo n.º 26
0
 def Unhandled(self, handlers, persistant_attributes, attributes, slots):
     return responder.ask(
         "I'm confused, Do you want to search online for a recipe? Try saying yes or no.",
         None, attributes)