def handle(self, handler_input): # type: (HandlerInput) -> Response logger.info("In LaunchRequestHandler") # handler_input.response_builder.speak(WELCOME_MESSAGE).ask( # HELP_MESSAGE) response_builder = handler_input.response_builder speech = PRIMARY_TEXT viewport_state = handler_input.request_envelope.context.viewport if not viewport_state: speech = "La Skill funziona solo sui device con schermo" response_builder.speak(speech) return response_builder.set_should_end_session(True).response response_builder.speak(speech) if USE_CARDS_FLAG: response_builder.set_card( ui.StandardCard(title=TITLE, text=PRIMARY_TEXT, image=ui.Image( small_image_url=IMG_PATH, large_image_url=IMG_PATH, ))) if supports_display(handler_input) and not supports_APL(handler_input): logger.info("Supports Display") title = TITLE fg_img7 = Image(content_description=PRIMARY_TEXT, sources=[ImageInstance(url=IMG_PATH)]) response_builder.add_directive( RenderTemplateDirective( BodyTemplate7(back_button=BackButtonBehavior.HIDDEN, image=fg_img7, title=title))) if supports_APL(handler_input): logger.info("Supports APL") response_builder.add_directive( RenderDocumentDirective( token=APP_NAME + "_Token", document=_load_apl_document("RadarMeteoAPL.json"), datasources={"param": { 'url': IMG_PATH }})).add_directive( ExecuteCommandsDirective( token=APP_NAME + "_Token", commands=[ IdleCommand(delay=5, description="wait_a_bit") ])).add_directive( ExecuteCommandsDirective( token=APP_NAME + "_Token", commands=[ IdleCommand(delay=5, description="last command") ])) return response_builder.set_should_end_session(True).response
def recipeScreen(handler_input, sauce_item, selected_recipe): """ Adds Recipe Screen (APL Template) to Response """ data = handler_input.attributes_manager.request_attributes["_"] # Get prompt and reprompt speech speak_output = selected_recipe['instructions'] reprompt_output = data[prompts.RECIPE_REPEAT_MESSAGE] # Only add APL directive if User's device supports APL if (supports_apl(handler_input)): # Add APL Template amd Command (Speak Item to sync. Voice/Text) handler_input.response_builder.add_directive( RenderDocumentDirective( token="sauce-boss", document=APL_DOCS['recipe'], datasources=generateRecipeScreenDatasource( handler_input, sauce_item, selected_recipe))).add_directive( ExecuteCommandsDirective( token="sauce-boss", commands=[ SpeakItemCommand( component_id="recipeText", highlight_mode=HighlightMode.line) ])) # As speech will be done by APL Command (SpeakItem) Voice/Text sync # Save prompt and reprompt for repeat session_attributes = handler_input.attributes_manager.session_attributes session_attributes['speak_output'] = speak_output session_attributes['reprompt_output'] = reprompt_output else: # As APL is not supported by device # Provide prompt & reprompt instead of APL Karaoke handler_input.response_builder.speak(speak_output).ask(reprompt_output)
def handle(self, handler_input): # type: (HandlerInput) -> Response logger.info("In PagerIntent") speech = 'This is the pager template!' handler_input.response_builder.speak(speech).add_directive( RenderDocumentDirective( token="pagerToken", document=_load_apl_document("pager.json"), datasources={ 'pagerTemplateData': { 'type': 'object', 'properties': { 'hintString': 'try the blue cheese!' }, 'transformers': [{ 'inputPath': 'hintString', 'transformer': 'textToHint' }] } })).add_directive( ExecuteCommandsDirective( token="pagerToken", commands=[ AutoPageCommand(component_id="pagerComponentId", duration=5000) ])) return handler_input.response_builder.response
def label_info_handler(handler_input: HandlerInput): print('entered into LabelInfoIntent') speech = "The How2Recycle label is a voluntary, standardized labeling system that clearly communicates recycling instructions " +\ "to the public. It involves a coalition of forward thinking brands who want their packaging to be recycled and are empowering " +\ "consumers through smart packaging labels. A recycling Label has four parts. Part 1 tells How to Prepare Material for Recycling. " +\ "Part 2 is an icon which tells you whether the item falls into one of four categories - Widely Recycled, Check Locally, Not Yet Recycled and Store Drop-Off. " +\ "Part 3 Tells you what type of material the packaging is made of. and Part 4 Tells you the specific packaging component that the label is referring to." if is_apl_supported(handler_input): speech = speech + " Information about parts of label are displayed. To go back, you can say go home. To quit you can say Stop" print(speech) handler_input.response_builder.speak(speech).set_should_end_session( False).ask(launch_reprompt_text).add_directive( RenderDocumentDirective( token="pagerToken", document=load_apl_document( "apl_pager_labels.json")['document'], datasources=load_apl_document("apl_pager_labels.json") ['dataSources'])).add_directive( ExecuteCommandsDirective( token="pagerToken", commands=[ AutoPageCommand( component_id="pagerComponentId", duration=5000) ])) else: handler_input.response_builder.speak(speech).set_should_end_session( True).ask(launch_reprompt_text) return handler_input.response_builder.response
def handle(self, handler_input): language_prompts = handler_input.attributes_manager.request_attributes[ "_"] video_directive = ExecuteCommandsDirective(token="videoplayer", commands=[{ "type": "ControlMedia", "componentId": "videoPlayer", "command": "pause" }]) return (handler_input.response_builder.add_directive( video_directive).response)
def handle(self, handler_input): # type: (HandlerInput) -> Response logger.info("In Karaoke Intent") speech = 'This is the karaoke template!' speech_no_apl = ( 'This is a sample that shows a karaoke template. ' + 'Try it on an Echo Show, Echo Spot or Fire TV device.') if _supports_apl(handler_input): handler_input.response_builder.speak(speech).add_directive( RenderDocumentDirective( token="karaokeToken", document=_load_apl_document("karaoke.json"), datasources={ 'karaokeTemplateData': { 'type': 'object', 'objectId': 'karaokeSample', 'properties': { 'karaokeSsml': '<speak>We’re excited to announce a new video training series from A Cloud Guru on Alexa skill development. The free training series called Alexa Devs walks new developers and non-developers through how to build Alexa skills from start to finish. You’ll also learn how to enhance your skill using persistence, Speechcons, and SSML to create more engaging voice experiences for customers. Check out the first episode on how to build your first Alexa skill here.</speak>', 'hintString': 'try the blue cheese!' }, 'transformers': [{ 'inputPath': 'karaokeSsml', 'outputName': 'karaokeSpeech', 'transformer': 'ssmlToSpeech' }, { 'inputPath': 'karaokeSsml', 'outputName': 'karaokeText', 'transformer': 'ssmlToText' }, { 'inputPath': 'hintString', 'transformer': 'textToHint' }] } })).add_directive( ExecuteCommandsDirective( token="karaokeToken", commands=[ SpeakItemCommand( component_id="karaokespeechtext", highlight_mode=HighlightMode.LINE) ])) else: handler_input.response_builder.speak(speech_no_apl) return handler_input.response_builder.response
def handle(self, handler_input): # type: (HandlerInput) -> Response logger.info("In PagerIntent") speech = 'This is the pager template!' speech_no_apl = ( 'This is a sample that shows a pager template. ' + 'Try it on an Echo Show, Echo Spot or Fire TV device.') if _supports_apl(handler_input): handler_input.response_builder.speak(speech).add_directive( RenderDocumentDirective( token="pagerToken", document=_load_apl_document("pager.json"), datasources={ 'pagerTemplateData': { 'type': 'object', 'properties': { 'hintString': 'try the blue cheese!' }, 'transformers': [{ 'inputPath': 'hintString', 'transformer': 'textToHint' }] } })).add_directive( ExecuteCommandsDirective( token="pagerToken", commands=[ AutoPageCommand( component_id="pagerComponentId", duration=5000) ])) else: handler_input.response_builder.speak(speech_no_apl) return handler_input.response_builder.response
def handle(self, handler_input): # type: (HandlerInput) -> Response logger.info("In Math Trivia Intent") slots = handler_input.request_envelope.request.intent.slots if 'number_slot' in slots and slots['number_slot'].value != None: number = slots['number_slot'].value handler_input.attributes_manager.session_attributes[ 'number_slot_key'] = number math_string = str(number) fact = requests.get("http://numbersapi.com/" + math_string + "/math").content speech = "Here is something special about the number " + math_string + " in the world of mathematics!" reprompt = HELP_REPROMPT elif 'random_slot' in slots and slots['random_slot'].value != None: math_string = "random number" fact = requests.get("http://numbersapi.com/random/math").content speech = "Here is something special about a randomly generated number in the world of mathematics!" reprompt = HELP_REPROMPT elif 'number_slot_key' in handler_input.attributes_manager.session_attributes: number = handler_input.attributes_manager.session_attributes[ 'number_slot_key'] math_string = str(number) fact = requests.get("http://numbersapi.com/" + math_string + "/math").content speech = "Here is something special about the number " + math_string + " in the world of mathematics!" reprompt = HELP_REPROMPT else: fact = "Sorry! But it seems like you have not specified the number properly. Try saying \"What is the significance of number 42 in mathematics?\"" math_string = "unspecified number" speech = "Here is the result I got!" reprompt = HELP_REPROMPT handler_input.response_builder.speak(speech).ask( reprompt ).add_directive( RenderDocumentDirective( token="mathToken", document=_load_apl_document("trivia.json"), datasources={ 'triviaTemplateData': { 'type': 'object', 'objectId': 'mathSample', 'title': math_string, 'backgroundImage': { 'sources': [{ 'url': "https://raw.githubusercontent.com/Techievena/Techievena.github.io/master/img/post_images/numbers_trivia_background.jpg", 'size': "small", 'widthPixels': 0, 'heightPixels': 0 }, { 'url': "https://raw.githubusercontent.com/Techievena/Techievena.github.io/master/img/post_images/numbers_trivia_background.jpg", 'size': "large", 'widthPixels': 0, 'heightPixels': 0 }] }, 'image': { 'sources': [{ 'url': "https://dummyimage.com/16:9x1080/4c/00b0e6.png&text=" + math_string, 'size': "small", 'widthPixels': 0, 'heightPixels': 0 }, { 'url': "https://dummyimage.com/16:9x1080/4c/00b0e6.png&text=" + math_string, 'size': "large", 'widthPixels': 0, 'heightPixels': 0 }] }, 'properties': { 'triviaSsml': '<speak>' + fact + '</speak>' }, 'transformers': [{ 'inputPath': 'triviaSsml', 'outputName': 'triviaSpeech', 'transformer': 'ssmlToSpeech' }, { 'inputPath': 'triviaSsml', 'outputName': 'triviaText', 'transformer': 'ssmlToText' }], "logoUrl": "https://raw.githubusercontent.com/Techievena/Techievena.github.io/master/img/post_images/numbers_trivia_skill_logo.png", "hintText": "Try, \"Alexa, tell me something about any number.\"" } })).add_directive( ExecuteCommandsDirective( token="mathToken", commands=[ SetPageCommand(component_id="pagerComponentId", position=Position.RELATIVE, value=1, delay=3000), SpeakItemCommand(component_id="karaokeComponentId", highlight_mode=HighlightMode.LINE) ])) return handler_input.response_builder.response