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.")
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")
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)
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.")
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)
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)
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)
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)
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")
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)
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)
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)
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)
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)
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)
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)
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)
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)
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))
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)
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)
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)
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)
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)
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)
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)