Created
August 24, 2018 22:04
-
-
Save nikhilym/deea1c2b4a4c2341be678f4dad620662 to your computer and use it in GitHub Desktop.
Render Template usage in skill with ASK Python SDK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ask_sdk_core.dispatch_components import AbstractRequestHandler | |
from ask_sdk_core.handler_input import HandlerInput | |
from ask_sdk_core.utils import is_intent_name | |
from ask_sdk_core.response_helper import get_plain_text_content | |
from ask_sdk_model.response import Response | |
from ask_sdk_model.interfaces.display import ( | |
ImageInstance, Image, RenderTemplateDirective, | |
BackButtonBehavior, BodyTemplate2) | |
from ask_sdk_model import ui | |
class HelloIntentHandler(AbstractRequestHandler): | |
def can_handle(self, handler_input): | |
# type: (HandlerInput) -> bool | |
return is_intent_name("HelloIntent")(handler_input) | |
def handle(self, handler_input): | |
# type: (HandlerInput) -> Response | |
response_builder = handler_input.response_builder | |
speech = "This is a sample response" | |
response_builder.set_card( | |
ui.StandardCard( | |
title="Card Title", | |
text="Hey this is a sample card", | |
image=ui.Image( | |
small_image_url="<Small Image URL>", | |
large_image_url="<Large Image URL>" | |
) | |
) | |
) | |
if supports_display(handler_input): | |
img = Image( | |
sources=[ImageInstance(url="<Large Image URL>")]) | |
title = "Template Title" | |
primary_text = get_plain_text_content( | |
primary_text="some text") | |
response_builder.add_directive( | |
RenderTemplateDirective( | |
BodyTemplate2( | |
back_button=BackButtonBehavior.VISIBLE, | |
image=img, title=title, | |
text_content=primary_text))) | |
return response_builder.speak(speech).response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment