def handle(self, handler_input):
     data = handler_input.attributes_manager.request_attributes["_"]
     # Get random sauce for speak_output
     random_sauce = recipe_utils.get_random_recipe(handler_input)
     # get prompt and reprompt speach
     speak_ouput = data[prompts.HELP_MESSAGE].format(random_sauce['name'])
     reprompt_output = data[data.HELP_REPROMPT].format(random_sauce['name'])
     # Add APL if device is compatible
     apl_utils.helpScreen(handler_input)
     handler_input.response_builder.speak(speak_ouput).ask(reprompt_output)
     # Generate the JSON response
     return handler_input.response_builder.response
 def handle(self, handler_input):
     data = handler_input.attributes_manager.request_attributes["_"]
     # Get a random sauce
     random_sauce = recipe_utils.get_random_recipe(handler_input)
     # Get prompt and reprompt speech
     speak_output = data[prompts.WELCOME_MESSAGE].format(
         data[prompts.SKILL_NAME], random_sauce['name'])
     reprompt_output = data[prompts.WELCOME_REPROMPT]
     # Add APL Template if device is compatible
     apl_utils.launch_screen(handler_input)
     # Generate JSON Response
     return handler_input.response_builder.speak(speak_output).ask(reprompt_output).response
Beispiel #3
0
def generateLaunchScreenDatasource(handler_input):
    """
    Compute the JSON Datasource associated to APL Launch Screen
    """
    data = handler_input.attributes_manager.request_attributes["_"]
    print(str(data))
    # Get random recipe name for hint
    random_recipe = recipe_utils.get_random_recipe(handler_input)
    # Define header title nad hint
    header_title = data[prompts.HEADER_TITLE].format(data[prompts.SKILL_NAME])
    hint_text = data[prompts.HINT_TEMPLATE].format(random_recipe['name'])
    # Define sauces to be displayed
    saucesIdsToDisplay = ["BBQ", "CRA", "HON",
                          "PES", "PIZ", "TAR", "THO", "SEC"]
    locale = handler_input.request_envelope.request.locale
    all_recipes = recipe_utils.get_locale_specific_recipes(locale)
    sauces = []
    for k in all_recipes.keys():
        if(k in saucesIdsToDisplay):
            sauces.append({
                'id': k,
                'image': recipe_utils.get_sauce_image(k),
                'text': "pooper"
            })
    # Generate JSON Datasource
    return {
        'sauceBossData': {
            'type': 'object',
            'properties': {
                'headerTitle': header_title,
                'hintText': hint_text,
                'items': sauces
            },
            'transformers': [
                {
                    'inputPath': 'hintText',
                    'transformer': 'textToHint'
                }
            ]
        }
    }
def generateRecipeScreenDatasource(handler_input, sauce_item, selected_recipe):
    """
    Compute the JSON Datasource associated to APL Recipe Screen
    """
    data = handler_input.attributes_manager.request_attributes["_"]
    # Get a random sauce name for hint
    random_sauce = recipe_utils.get_random_recipe(handler_input)
    # Define header title and hint
    header_title = data[prompts.RECIPE_HEADER_TITLE].format(
        selected_recipe['name'])
    hint_text = data[prompts.HINT_TEMPLATE].format(random_sauce['name'])
    sauce_ssml = "<speak>{}</speak>".format(selected_recipe['instructions'])
    # Generate JSON Datasource
    return {
        'sauceBossData': {
            'type':
            'object',
            'properties': {
                'headerTitle':
                header_title,
                'headerBackButton':
                (not handler_input.request_envelope.session.new),
                'hintText':
                hint_text,
                'sauceImg':
                sauce_item['image'],
                'sauceText':
                selected_recipe['instructions'],
                'sauceSsml':
                sauce_ssml
            },
            'transformers': [{
                'inputPath': 'sauceSsml',
                'transformer': 'ssmlToSpeech',
                'outputName': 'sauceSpeech'
            }, {
                'inputPath': 'hintText',
                'transformer': 'textToHint'
            }]
        }
    }