예제 #1
0
def generateHelpScreenDatasource(handler_input):
    """
    Compute the JSON Datasource associated to APL Help Screen
    """
    data = handler_input.attributes_manager.request_attributes["_"]
    # Define header and sub titles
    header_title = data[prompts.HELP_HEADER_TITLE]
    header_subtitle = data[prompts.HELP_HEADER_SUBTITLE]
    # Define sauces to be displayed
    saucesIdsToDisplay = ["BBQ", "CRA", "HON",
                          "PES", "PIZ", "TAR", "THO", "SEC"]
    locale = handler_input.request_envelope.request.locale
    # Get recipes
    all_recipes = recipe_utils.get_locale_specific_recipes(locale)
    sauces = []
    for k in all_recipes.keys():
        if(k in saucesIdsToDisplay):
            sauces.append({
                'id': k,
                'primaryText': data[prompts.HINT_TEMPLATE].format(all_recipes[k]['name'])
            })
    # Generate JSON Datasource
    return {
        'sauceBossData': {
            'headerTitle': header_title,
            'headerSubtitle': header_subtitle,
            'headerBackButton': (not handler_input.request_envelope.session.new),
            'items': sauces
        }
    }
    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
예제 #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'
                }
            ]
        }
    }