def generate_recipe_output(self, handler_input, sauce_item):
        _ = handler_input.attributes_manager.request_attributes["_"]
        locale = handler_input.request_envelope.request.locale
        # Sauce exists
        if (sauce_item['id']):
            # Load i18n strings
            recipes = recipe_utils.get_locale_specific_recipes(locale)
            selected_recipe = recipes[sauce_item['id']]
            # Add image
            sauce_item['image'] = recipe_utils.get_sauce_image(
                sauce_item['id'])
            # Add a card (displayed in the Alexa app)
            cardTitle = _(data.DISPLAY_CARD_TITLE).format(
                _(data.SKILL_NAME), selected_recipe['name'])
            # Add speak output and reprompt
            handler_input.response_builder.speak(
                selected_recipe['instructions']).ask(
                    _(data.RECIPE_REPEAT_MESSAGE))
            handler_input.response_builder.set_card(
                StandardCard(title=cardTitle,
                             text=selected_recipe['instructions'],
                             image=Image(small_image_url=sauce_item['image'],
                                         large_image_url=sauce_item['image'])))
            # Add APL Template if device is compatible
            apl_utils.recipeScreen(handler_input, sauce_item, selected_recipe)
        else:
            # Spoken Sauce does not exist
            # Add prompt : Is the item slot is filled with a value ?
            if (sauce_item['spoken']):
                # Use spoken value to let user know no recipe exists for this value
                handler_input.response_builder.speak(
                    _(data.RECIPE_NOT_FOUND_WITH_ITEM_NAME).format(
                        sauce_item['spoken']))
            else:
                # No spoken value
                handler_input.response_builder.speak(
                    _(data.RECIPE_NOT_FOUND_WITHOUT_ITEM_NAME))

        # add reprompt
        handler_input.response_builder.ask(_(data.RECIPE_NOT_FOUND_REPROMPT))

        # Generate JSON response
        return handler_input.response_builder.response
예제 #2
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'
                }
            ]
        }
    }