def action_func(measure_type=None, choices=None): if choices and not measure_type: measure_type_data = measure_choices[choices] else: measure_type_data = measure_type manager.get('data').set('store-measure', measure_type_data) return event('AskSortType')
def action_func(): # Checking if option is selected if (context_manager.get("actions_intent_option")) is not None: option = context_manager.get("actions_intent_option").get( "OPTION") # getting the key sent if option == "flask_assistant": return event("assistCarousel") # returning events elif option == "flask_ask": return event("fAsk") # returning events elif option == "flask": return event("fCard") # returning events # Basic speech/text response resp = ask("Select Flask-Assistant for a carousel") # Create a list with a title mylist = resp.build_list("Awesome List") # Add items directly to list mylist.add_item( "Flask-Assistant", key="flask_assistant", # query sent if item selected img_url=ASSIST_LOGO_URL, description="Select for carousel", synonyms=["flask assistant", "number one", "assistant", "carousel"], ) mylist.add_item( "Flask-Ask", key="flask_ask", img_url=ASK_LOGO_URL, description= "Rapid Alexa Skills Kit Development for Amazon Echo Devices", synonyms=["ask", "flask ask", "number two"], ) # Or build items independent of list flask_item = build_item( "Flask", key="flask", img_url=FLASK_LOGO_URL, description= "A microframework for Python based on Werkzeug, Jinja 2 and good intentions", synonyms=["flask", "number three"], ) # and add them to the lsit later mylist.include_items(flask_item) return mylist
def action_func(scope=None, choices=None): if choices and not scope: scope_data = scope_choices[choices] else: scope_data = scope manager.get('data').set('store-scope', scope_data) manager.add(scope_data + '-stores') if scope_data == 'all': # stores are selected - all of them manager.get('data').set('stores', 'all') manager.add('stores-selected') return event('SelectMeasureType') else: # need to choose the stores, then select mesauretype return event('SelectStores')
def action_func(): #Checking if option is selected if (context_manager.get('actions_intent_option')) is not None: option = context_manager.get('actions_intent_option').get( 'OPTION') #getting the key sent if (option == "flask_assistant"): return event('assistCarousel') #returning events elif option == 'flask_ask': return event('fAsk') #returning events elif option == 'flask': return event('fCard') #returning events # Basic speech/text response resp = ask("Select Flask-Assistant for a carousel") # Create a list with a title mylist = resp.build_list('Awesome List') # Add items directly to list mylist.add_item( 'Flask-Assistant', key='flask_assistant', # query sent if item selected img_url=ASSIST_LOGO_URL, description='Select for carousel', synonyms=['flask assistant', 'number one', 'assistant', 'carousel']) mylist.add_item( 'Flask-Ask', key='flask_ask', img_url=ASK_LOGO_URL, description= 'Rapid Alexa Skills Kit Development for Amazon Echo Devices', synonyms=['ask', 'flask ask', 'number two']) # Or build items independent of list flask_item = build_item( 'Flask', key='flask', img_url=FLASK_LOGO_URL, description= 'A microframework for Python based on Werkzeug, Jinja 2 and good intentions', synonyms=['flask', 'number three']) # and add them to the lsit later mylist.include_items(flask_item) return mylist
def prompt_trade_currency(capital_base): current_app.logger.debug(f"Setting capital base as {capital_base}") context_manager.set("strat-config-data", "captial_base", capital_base) speech = "Which asset would you like to trade?" resp = inline_keyboard(speech) exchange = context_manager.get("strat-config-data").get("exchange") quote_currency = context_manager.get("strat-config-data").get( "quote_currency") options = task.get_available_base_currencies(exchange, quote_currency) for o in options: resp.add_button(o, o) return resp
def action_func(): metrics = manager.get('data').get('metrics') speech = """How would you like to sort {}? a) from largest to smallest b) from smallest to largest""".format(metrics[0]) return ask(speech)
def begin_time_dialogue(date_time): # interval if '/' in date_time: delta = parse_date_interval(date_time) manager.get('data').set('time-delta', str(delta)) ask_period = largest_period(delta.days) manager.add(ask_period, lifespan=1) return event('StepToProducts') else: return ask( "Sorry I cant do single dates yet. Is there a range of time you'd like to see?" )
def action_func(): metrics = manager.get('data').get('metrics') speech = """Would you like to see {} for a) each store b) just the total?""".format(metrics) return ask(speech)
def won_game(game): game = load_game() context_manager.get("game_in_progress").lifespan = 0 game.end_game() speech = "Oh llama! You won the game! Would you like to start a new game or hear about the rules?" context_manager.add("choose_game_or_rules", lifespan=3) return ask(speech)
def action_func(): metrics = manager.get('data').get('metrics') speech = """Would you like to see information a) for each store or b) do you just want the {} to represent all stores?""".format( metrics) return ask(speech)
def action_func(scope=None, choices=None): # choice/scope not list because need one answer if choices and not scope: scope_data = scope_choices[choices] else: scope_data = scope manager.get('data').set('product-scope', scope_data) manager.add(scope_data + '-products') if scope_data == 'all': # Products are selected - all of them manager.get('data').set('products', 'all') manager.add('products-selected') return event('SelectMeasureType') else: # need to choose the products, then select mesauretype return event('SelectProducts')
def ask_products(): metrics = manager.get('data').get('metrics') speech = """Do you want to see {} for: a) all the products b) just for certain products?""".format(metrics) return ask(speech)
def hello_world(): google_data = request contextsList = google_data["result"]["contexts"] for context in contextsList: if context["name"] == "playstart": currentTrack = context["parameters"]["currentTrack"] break else: currentTrack = "1" continue my_context = context_manager.get('playstart', 'currentTrack') context_manager.add("playstart") context_manager.set('playstart', 'currentTrack', currentTrack) if tracksData[currentTrack]["que"] == "X": google_data = request contextsList = google_data["result"]["contexts"] for context in contextsList: if context["name"] == "playstart": currentTrack = context["parameters"]["currentTrack"] break else: currentTrack = "1" continue if currentTrack == "32": newTrack = "1" else: newTrack = str(int(currentTrack) + 1) context_manager.add("playstart") context_manager.set('playstart', 'currentTrack', newTrack) speech = """ <speak> There is no question for this song. Now Playing """ + tracksData[newTrack]["name"] + """ . <break time="1000ms"/> <audio src=" """ + tracksData[newTrack]["url"] + """ "> <desc>""" + tracksData[newTrack]["name"] + """</desc> Sorry, there is some problem </audio> <break time="1000ms"/> Would you like to play the quiz now? </speak> """ return ask(speech) else: speech = """ <speak> Ok, so here is your question, """ + tracksData[currentTrack]["que"] + """. Your options are, """ + tracksData[currentTrack]["optionOne"] + """ , """ + tracksData[currentTrack]["optionTwo"] + """ , """ + tracksData[currentTrack]["optionThree"] + """ , or , """ + tracksData[currentTrack]["optionFour"] + """ . </speak> """ return ask(speech)
def prompt_capital_base(quote_currency): current_app.logger.debug(f"Setting quote currency as {quote_currency}") context_manager.set("strat-config-data", "quote_currency", quote_currency) speech = f"How much {quote_currency.upper()} would you like to allocate as the capital base?" exchange = context_manager.get("strat-config-data").get("exchange") # enqueue base_currency options current_app.logger.debug("enqueing for base currencies") task.get_available_base_currencies(exchange, quote_currency) return ask(speech)
def hello_world(): google_data = request contextsList = google_data["result"]["contexts"] for context in contextsList: if context["name"] == "playstart": currentTrack = context["parameters"]["currentTrack"] answerByUser = context["parameters"]["any.original"] break else: currentTrack = "1" answerByUser = "******" continue answer = tracksData[currentTrack]["ans"][0] if answerByUser == "default answer": sOut = "There was some problem in fetching the answer" elif answerByUser == answer: sOut = """ <audio src="https://s3.amazonaws.com/bobthetraincanatech/CHILDREN-cheering+VE+2.mp3"><desc></desc></audio> <audio src="https://s3.amazonaws.com/bobthetraincanatech/Claping+5Sec.mp3"><desc></desc></audio> Yes, """ + answer + """ is the correct answer. """ else: sOut = """ <audio src="https://s3.amazonaws.com/bobthetraincanatech/sfx_1.wav"><desc></desc></audio> <audio src="https://s3.amazonaws.com/bobthetraincanatech/sfx_2.wav"><desc></desc></audio> Oops, the correct answer is, """ + answer my_context = context_manager.get('playstart', 'currentTrack') if currentTrack == "32": newTrack = "1" else: newTrack = str(int(currentTrack) + 1) context_manager.add("playstart") context_manager.set('playstart', 'currentTrack', newTrack) speech = """ <speak> """ + sOut + """ <break time="1000ms"/> . Now Playing """ + tracksData[newTrack]["name"] + """ . <break time="1000ms"/> <audio src=" """ + tracksData[newTrack]["url"] + """ "> <desc>""" + tracksData[newTrack]["name"] + """</desc> Sorry, there is some problem </audio> <break time="1000ms"/> Would you like to play the quiz now? </speak> """ return ask(speech)
def action_func(): metrics = manager.get('data').get('metrics') if len(metrics) > 1: return event('SelectMetricToSort') else: return event('AskSortType') speech = """How would you like to sort {}? a) from largest to smallest b) from smallest to largest""".format(metrics[0]) return ask(speech)
def respond(): context_manager.add('dialogue') handler = ConversationHandler(conf, logger) user_query = request['queryResult']['queryText'] # restore dialogue dialogue = context_manager.get('dialogue').parameters.get('serialized') dialogue = deserialize_dialogue(dialogue) resp, isend = handler.get_response(dialogue, user_query) context_manager.set('dialogue', 'serialized', serialize_dialogue(dialogue)) return tell(resp)
def wine_recommendation(): context = context_manager.get('make-food') chosen_recipe = context.parameters.get('chosen_recipe') wine_response = SpoonacularUtils.get_wine(chosen_recipe) try: wine = json.loads(r'' + wine_response.text + '')['pairedWines'][0] if not wine: wine = "pinot noir" except: wine = 'gruener veltliner' return tell("{} will be perfect".format(wine))
def game_over(game): game = load_game() context_manager.get("game_in_progress").lifespan = 0 game.end_game() speech_options = [ "Oh no! You are turtle-ly out of strikes!", "Oh, the hue-manatee! You're out of strikes!" ] speech = choice( speech_options ) + " Would you like to start a new game or hear about the rules?" context_manager.add("choose_game_or_rules", lifespan=3) return ask(speech)
def hello_world(): google_data = request my_context = context_manager.get('testContext', 'param1') speech = """ <speak> <audio src="https://s3.amazonaws.com/bobthetraincanatech/Hi+Kids+I_m+Bob.mp3"> <desc>Welcome to Bob The Train Songs</desc> Hi Kids, I am Bob </audio> <break time="1000ms"/> Say play all, to play all the songs, or , say the name of the song you want to play. </speak> """ return ask(speech)
def action_func(sort_type=None, choices=None): if choices and not sort_type: sort_type_data = scope_choices[choices] else: sort_type_data = sort_type data = manager.get('data').set('sort_type', sort_type_data) speech = 'Sorting with the following parameters:\n\n' for k, v in data.parameters.items(): speech += '{}: {}<br/>'.format(k, v) return tell(speech)
def get_food(product): context = context_manager.get('await_for_food') if context is None: speech = "sorry, can you please remind me what is your allergy?" return ask(speech) product = context.parameters['product'] allergy = context.parameters['allergan'] #TODO: need to check here what is happening if they have two allergies product = EngineClient.findProductByName(product) allergans_in_product = EngineClient.checkAllergies(product) if allergy in allergans_in_product: speech = "This food is not safe for you" else: speech = "I couldn't find any allergans in this food related to your allergies" return ask(speech)
def launch_strategy_live(existing_strategy): context = context_manager.get("strat-config-data") job_id = build.launch_live(context) url = os.path.join(current_app.config["FRONTEND_URL"], "strategy", job_id) hours = context.get("hours") speech = f"""\ Great! The strategy is now live and will run for the next {hours} hours. You can view your strategy's progress by clicking the link \ below and I will keep you updated on how it performs. """.format(hours) resp = inline_keyboard(dedent(speech)) resp.add_button(url, "View your Strategy") return resp
def prompt_for_mode(): context = context_manager.get("strat-config-data") # backtest_id = build.launch_backtest(context) # current_app.logger.info(f"Queues Strat {backtest_id}") # backtest_url = os.path.join( # current_app.config["FRONTEND_URL"], "strategy/backtest/strategy/", backtest_id # ) speech = f"Your strategy is now configured!\n\n Would you like to launch it?\n\n" resp = inline_keyboard(dedent(speech)) # resp.add_button("View Past Performance", url=backtest_url) resp.add_button("paper", "Launch in Paper Mode") resp.add_button("live", "Lauch in Live mode") resp.add_button("no", "Nevermind") return resp
def choose_another(): context = context_manager.get('make-food') recipes = context.parameters.get('recipes') current_recipe = int(context.parameters.get('current_recipe_index') + 1) context_manager.set("make-food", "current_recipe_index", current_recipe) recipe_id = int(recipes[current_recipe]['id']) if len(recipes) <= current_recipe + 1: return tell( "Sorry but I don't have any more recipes to make, please ask for another recipe" ) # RECIPE WITH 2 STEPS SECTIONS: recipe_id = 324694 if not is_recipe_has_single_step_section(recipe_id): return choose_another() speech = "Do you want to make {choice}?".format( choice=recipes[current_recipe]['title']) return ask(speech)
def hello_world(): google_data = request my_context = context_manager.get('testContext', 'param1') context_manager.add("playstart") context_manager.set('playstart', 'currentTrack', "1") speech = """ <speak> Playing """ + tracksData["1"]["name"] + """ . <break time="1000ms"/> <audio src=" """ + tracksData["1"]["url"] + """ "> <desc>""" + tracksData["1"]["name"] + """</desc> Sorry, there is some problem </audio> <break time="1000ms"/> Would you like to play the quiz now? </speak> """ return ask(speech)
def hello_world(): google_data = request contextsList = google_data["result"]["contexts"] for context in contextsList: if context["name"] == "playstart": currentTrack = context["parameters"]["currentTrack"] break else: currentTrack = "1" continue my_context = context_manager.get('playstart', 'currentTrack') context_manager.add("playstart") context_manager.set('playstart', 'currentTrack', currentTrack) if tracksData[currentTrack]["que"] == "X": google_data = request contextsList = google_data["result"]["contexts"] for context in contextsList: if context["name"] == "playstart": currentTrack = context["parameters"]["currentTrack"] break else: currentTrack = "1" continue speech = """ <speak> <break time="1000ms"/> There is no question for this song. Say, play all to play all the songs, or , say , the name of the song you want to play. </speak> """ return ask(speech) else: speech = """ <speak> Ok, so here is your question, """ + tracksData[currentTrack]["que"] + """ . Your options are, """ + tracksData[currentTrack]["optionOne"] + """ , """ + tracksData[currentTrack]["optionTwo"] + """ , """ + tracksData[currentTrack]["optionThree"] + """ , or , """ + tracksData[currentTrack]["optionFour"] + """ . </speak> """ return ask(speech)
def hello_world(): google_data = request contextsList = google_data["result"]["contexts"] for context in contextsList: if context["name"] == "playstart": currentTrack = context["parameters"]["currentTrack"] break else: currentTrack = "1" continue answerByUser = google_data["result"]["parameters"]["any1"] answer = tracksData[currentTrack]["ans"][0] if answerByUser == "default answer": sOut = "There was some problem in fetching the answer. " elif answerByUser == answer: sOut = """ <audio src="https://s3.amazonaws.com/bobthetraincanatech/CHILDREN-cheering+VE+2.mp3"><desc></desc></audio> <audio src="https://s3.amazonaws.com/bobthetraincanatech/Claping+5Sec.mp3"><desc></desc></audio> Yes, """ + answer + """ is the correct answer. """ else: sOut = """ <audio src="https://s3.amazonaws.com/bobthetraincanatech/sfx_1.wav"><desc></desc></audio> <audio src="https://s3.amazonaws.com/bobthetraincanatech/sfx_2.wav"><desc></desc></audio> Oops, the correct answer is, """ + answer my_context = context_manager.get('playstart', 'currentTrack') if currentTrack == "32": newTrack = "1" else: newTrack = str(int(currentTrack) + 1) context_manager.add("playstart") context_manager.set('playstart', 'currentTrack', newTrack) speech = """ <speak> """ + sOut + """ Say, play all, to play all the songs, or , say the name of the song you want to play. </speak> """ return ask(speech)
def get_step(step_number): print("The step number to get is {}".format(step_number)) context = context_manager.get('make-food') requested_step = step_number steps = json.loads(str(context.parameters.get('recipe_steps'))) if int(requested_step) >= len(steps[0].get("steps")): # no more steps speech = "You finished the recipe! bonappetit. Can I help with anything else?" return ask(speech) if int(requested_step) < 0: requested_step = requested_step + 1 context_manager.set('make-food', 'current_step', int(requested_step)) pre_speach = "" if int(requested_step) == 0: pre_speach = "I will now tell you how to make this recipe. " \ "You can ask for the next, previous or current step. Let's start with the first step! \n" return ask(pre_speach + steps[0].get("steps")[int(requested_step)].get("step"))
def get_mail(): context = context_manager.get('get-age-followup') age = context.parameters['age']['amount'] prefernce = context.parameters['food-perference'] gender = context.parameters['gender'] weight = context.parameters['unit-weight']['amount'] height = context.parameters['unit-length']['amount'] email = context.parameters['email'] activity = context.parameters['activity-level'] user = User.User(gender=gender, age=age, weight=weight, height=height, taste=prefernce, activityLevel=activity, email=email) menu = EngineClient.createMenuAndSendMail(user) speech = "A new cool menu will be sent to you shortly!" return ask(speech)