Core

Handler Input

class ask_sdk_core.handler_input.HandlerInput(request_envelope, attributes_manager=None, context=None, service_client_factory=None)

Bases: object

Input to Request Handler, Exception Handler and Interceptors.

Handler Input instantiations are passed to the registered instances of AbstractRequestHandler and AbstractExceptionHandler , during skill invocation. The class provides a AttributesManager and a ResponseFactory instance, apart from RequestEnvelope, Context and ServiceClientFactory instances, to utilize during the lifecycle of skill.

Parameters:
service_client_factory

Service Client Factory instance for calling Alexa services.

To use the Alexa services, one need to configure the API Client in the skill builder object, before creating the skill.

Request Dispatch Components

Abstract Classes

class ask_sdk_core.dispatch_components.request_components.AbstractRequestHandler

Bases: ask_sdk_runtime.dispatch_components.request_components.AbstractRequestHandler

Request Handlers are responsible for processing Request inside the Handler Input and generating Response.

Custom request handlers needs to implement can_handle and handle methods. can_handle returns True if the handler can handle the current request. handle processes the Request and may return a Response.

can_handle(handler_input)

Returns true if Request Handler can handle the Request inside Handler Input.

Parameters:handler_input (HandlerInput) – Handler Input instance with Request Envelope containing Request.
Returns:Boolean value that tells the dispatcher if the current request can be handled by this handler.
Return type:bool
handle(handler_input)

Handles the Request inside handler input and provides a Response for dispatcher to return.

Parameters:handler_input (HandlerInput) – Handler Input instance with Request Envelope containing Request.
Returns:Response for the dispatcher to return or None
Return type:Union[Response, None]
class ask_sdk_core.dispatch_components.request_components.AbstractRequestInterceptor

Bases: ask_sdk_runtime.dispatch_components.request_components.AbstractRequestInterceptor

Interceptor that runs before the handler is called.

The process method has to be implemented, to run custom logic on the input, before it is handled by the Handler.

process(handler_input)

Process the input before the Handler is run.

Parameters:handler_input (HandlerInput) – Handler Input instance.
Return type:None
class ask_sdk_core.dispatch_components.request_components.AbstractResponseInterceptor

Bases: ask_sdk_runtime.dispatch_components.request_components.AbstractResponseInterceptor

Interceptor that runs after the handler is called.

The process method has to be implemented, to run custom logic on the input and the response generated after the handler is executed on the input.

process(handler_input, response)

Process the input and the response after the Handler is run.

Parameters:
  • handler_input (HandlerInput) – Handler Input instance.
  • response (Union[None, ask_sdk_model.Response]) – Execution result of the Handler on handler input.
Return type:

None

class ask_sdk_core.dispatch_components.exception_components.AbstractExceptionHandler

Bases: ask_sdk_runtime.dispatch_components.exception_components.AbstractExceptionHandler

Handles exception types and optionally produce a response.

The abstract class is similar to Request Handler, with methods can_handle and handle. The can_handle method checks if the handler can support the input and the exception. The handle method processes the input and exception, to optionally produce a response.

can_handle(handler_input, exception)

Checks if the handler can support the exception raised during dispatch.

Parameters:
  • handler_input (HandlerInput) – Handler Input instance.
  • exception (Exception) – Exception raised during dispatch.
Returns:

Boolean whether handler can handle exception or not.

Return type:

bool

handle(handler_input, exception)

Process the handler input and exception.

Parameters:
  • handler_input (HandlerInput) – Handler Input instance.
  • exception (Exception) – Exception raised during dispatch.
Returns:

Optional response object to serve as dispatch return.

Return type:

Union[None, Response]

Response Builder Components

ask_sdk_core.response_helper.PLAIN_TEXT_TYPE = 'PlainText'

str: Helper variable for plain text type.

ask_sdk_core.response_helper.RICH_TEXT_TYPE = 'RichText'

str: Helper variable for rich text type.

class ask_sdk_core.response_helper.ResponseFactory

Bases: object

ResponseFactory is class which provides helper functions to help building a response.

speak(speech, play_behavior=None)

Say the provided speech to the user.

Parameters:
  • speech (str) – the output speech sent back to the user.
  • play_behavior (ask_sdk_model.ui.play_behavior.PlayBehavior) – attribute to control alexa’s speech interruption
Returns:

response factory with partial response being built and access from self.response.

Return type:

ResponseFactory

ask(reprompt, play_behavior=None)

Provide reprompt speech to the user, if no response for 8 seconds.

The should_end_session value will be set to false except when the video app launch directive is present in directives.

Parameters:
  • reprompt (str) – the output speech to reprompt.
  • play_behavior (ask_sdk_model.ui.play_behavior.PlayBehavior) – attribute to control alexa’s speech interruption
Returns:

response factory with partial response being built and access from self.response.

Return type:

ResponseFactory

set_card(card)

Renders a card within the response.

For more information about card object in response, click here: https://developer.amazon.com/docs/custom-skills/request-and-response-json-reference.html#card-object.

Parameters:card (ask_sdk_model.ui.card.Card) – card object in response sent back to user.
Returns:response factory with partial response being built and access from self.response.
Return type:ResponseFactory
add_directive(directive)

Adds directive to response.

Parameters:directive (ask_sdk_model.directive.Directive) – the directive sent back to Alexa device.
Returns:response factory with partial response being built and access from self.response.
Return type:ResponseFactory
set_should_end_session(should_end_session)

Sets shouldEndSession value to null/false/true.

Parameters:should_end_session (bool) – value to show if the session should be ended or not.
Returns:response factory with partial response being built and access from self.response.
Return type:ResponseFactory
set_can_fulfill_intent(can_fulfill_intent)

Sets CanFulfill intent to the response.

For more information on CanFulfillIntent, check the name-free interaction doc here: https://developer.amazon.com/docs/custom-skills/understand-name-free-interaction-for-custom-skills.html

Parameters:can_fulfill_intent (CanFulfillIntent) – CanFulfill Intent sent back in response.
Returns:response factory with partial response being built and access from self.response.
Return type:ResponseFactory
ask_sdk_core.response_helper.get_plain_text_content(primary_text=None, secondary_text=None, tertiary_text=None)

Responsible for building plain text content object using ask-sdk-model in Alexa skills kit display interface. https://developer.amazon.com/docs/custom-skills/display-interface-reference.html#textcontent-object-specifications.

Parameters:
  • primary_text ((optional) str) – Text for primary_text field
  • secondary_text ((optional) str) – Text for secondary_text field
  • tertiary_text ((optional) str) – Text for tertiary_text field
Returns:

Text Content instance with primary, secondary and tertiary text set as Plain Text objects.

Return type:

TextContent

Raises:

ValueError

ask_sdk_core.response_helper.get_rich_text_content(primary_text=None, secondary_text=None, tertiary_text=None)

Responsible for building plain text content object using ask-sdk-model in Alexa skills kit display interface. https://developer.amazon.com/docs/custom-skills/display-interface-reference.html#textcontent-object-specifications.

Parameters:
  • primary_text ((optional) str) – Text for primary_text field
  • secondary_text ((optional) str) – Text for secondary_text field
  • tertiary_text ((optional) str) – Text for tertiary_text field
Returns:

Text Content instance with primary, secondary and tertiary text set as Rich Text objects.

Return type:

TextContent

Raises:

ValueError

ask_sdk_core.response_helper.get_text_content(primary_text=None, primary_text_type='PlainText', secondary_text=None, secondary_text_type='PlainText', tertiary_text=None, tertiary_text_type='PlainText')

Responsible for building text content object using ask-sdk-model in Alexa skills kit display interface. https://developer.amazon.com/docs/custom-skills/display-interface-reference.html#textcontent-object-specifications.

Parameters:
  • primary_text ((optional) str) – Text for primary_text field
  • primary_text_type ((optional) str) – Type of the primary text field. Allowed values are PlainText and RichText. Defaulted to PlainText.
  • secondary_text ((optional) str) – Text for secondary_text field
  • secondary_text_type – Type of the secondary text field. Allowed values are PlainText and RichText. Defaulted to PlainText.
  • tertiary_text ((optional) str) – Text for tertiary_text field
  • tertiary_text_type – Type of the tertiary text field. Allowed values are PlainText and RichText. Defaulted to PlainText.
Returns:

Text Content instance with primary, secondary and tertiary text set.

Return type:

TextContent

Raises:

ValueError

Skill Components

class ask_sdk_core.skill.SkillConfiguration(request_mappers, handler_adapters, request_interceptors=None, response_interceptors=None, exception_mapper=None, persistence_adapter=None, api_client=None, custom_user_agent=None, skill_id=None)

Bases: ask_sdk_runtime.skill.RuntimeConfiguration

Configuration Object that represents standard components needed to build Skill.

Parameters:
class ask_sdk_core.skill.CustomSkill(skill_configuration)

Bases: ask_sdk_runtime.skill.AbstractSkill

Top level container for Request Dispatcher, Persistence Adapter and Api Client.

Parameters:skill_configuration (SkillConfiguration) – Configuration object that holds information about different components needed to build the skill object.
supports(request_envelope, context)

Check if request envelope is of the expected skill format.

Parameters:
  • request_envelope (Dict[str, Any]) – input instance containing request information.
  • context (Any) – Context passed during invocation
Returns:

boolean if this type of request can be handled by this skill.

Return type:

bool

invoke(request_envelope, context)

Invokes the dispatcher, to handle the request envelope and return a response envelope.

Parameters:
  • request_envelope (RequestEnvelope) – Request Envelope instance containing request information
  • context (Any) – Context passed during invocation
Returns:

Response Envelope generated by handling the request

Return type:

ResponseEnvelope

class ask_sdk_core.skill_builder.SkillBuilder

Bases: ask_sdk_runtime.skill_builder.AbstractSkillBuilder

Skill Builder with helper functions for building ask_sdk_core.skill.Skill object.

skill_configuration

Create the skill configuration object using the registered components.

create()

Create a skill object using the registered components.

Returns:a skill object that can be used for invocation.
Return type:Skill
lambda_handler()

Create a handler function that can be used as handler in AWS Lambda console.

The lambda handler provides a handler function, that acts as an entry point to the AWS Lambda console. Users can set the lambda_handler output to a variable and set the variable as AWS Lambda Handler on the console.

Returns:Handler function to tag on AWS Lambda console.
add_exception_handler(exception_handler)

Register input to the exception handlers list.

Parameters:exception_handler (ask_sdk_runtime.dispatch_components.request_components.AbstractExceptionHandler) – Exception Handler instance to be registered.
Returns:None
add_global_request_interceptor(request_interceptor)

Register input to the global request interceptors list.

Parameters:request_interceptor (ask_sdk_runtime.dispatch_components.request_components.AbstractRequestInterceptor) – Request Interceptor instance to be registered.
Returns:None
add_global_response_interceptor(response_interceptor)

Register input to the global response interceptors list.

Parameters:response_interceptor (ask_sdk_runtime.dispatch_components.request_components.AbstractResponseInterceptor) – Response Interceptor instance to be registered.
Returns:None
add_request_handler(request_handler)

Register input to the request handlers list.

Parameters:request_handler (ask_sdk_runtime.dispatch_components.request_components.AbstractRequestHandler) – Request Handler instance to be registered.
Returns:None
exception_handler(can_handle_func)

Decorator that can be used to add exception handlers easily to the builder.

The can_handle_func has to be a Callable instance, which takes two parameters and no varargs or kwargs. This is because of the ExceptionHandler class signature restrictions. The returned wrapper function can be applied as a decorator on any function that processes the exception raised during dispatcher and returns a response object by the skill. The function should follow the signature of the handle function in ask_sdk_runtime.dispatch_components.exception_components.AbstractExceptionHandler class.

Parameters:can_handle_func (Callable[[Input, Exception], bool]) – The function that validates if the exception can be handled.
Returns:Wrapper function that can be decorated on a handle function.
global_request_interceptor()

Decorator that can be used to add global request interceptors easily to the builder.

The returned wrapper function can be applied as a decorator on any function that processes the input. The function should follow the signature of the process function in ask_sdk_runtime.dispatch_components.request_components.AbstractRequestInterceptor class.

Returns:Wrapper function that can be decorated on a interceptor process function.
global_response_interceptor()

Decorator that can be used to add global response interceptors easily to the builder.

The returned wrapper function can be applied as a decorator on any function that processes the input and the response generated by the request handler. The function should follow the signature of the process function in ask_sdk_runtime.dispatch_components.request_components.AbstractResponseInterceptor class.

Returns:Wrapper function that can be decorated on a interceptor process function.
request_handler(can_handle_func)

Decorator that can be used to add request handlers easily to the builder.

The can_handle_func has to be a Callable instance, which takes a single parameter and no varargs or kwargs. This is because of the RequestHandler class signature restrictions. The returned wrapper function can be applied as a decorator on any function that returns a response object by the skill. The function should follow the signature of the handle function in ask_sdk_runtime.dispatch_components.request_components.AbstractRequestHandler class.

Parameters:can_handle_func (Callable[[Input], bool]) – The function that validates if the request can be handled.
Returns:Wrapper function that can be decorated on a handle function.
class ask_sdk_core.skill_builder.CustomSkillBuilder(persistence_adapter=None, api_client=None)

Bases: ask_sdk_core.skill_builder.SkillBuilder

Skill Builder with api client and persistence adapter setter functions.

skill_configuration

Create the skill configuration object using the registered components.

add_exception_handler(exception_handler)

Register input to the exception handlers list.

Parameters:exception_handler (ask_sdk_runtime.dispatch_components.request_components.AbstractExceptionHandler) – Exception Handler instance to be registered.
Returns:None
add_global_request_interceptor(request_interceptor)

Register input to the global request interceptors list.

Parameters:request_interceptor (ask_sdk_runtime.dispatch_components.request_components.AbstractRequestInterceptor) – Request Interceptor instance to be registered.
Returns:None
add_global_response_interceptor(response_interceptor)

Register input to the global response interceptors list.

Parameters:response_interceptor (ask_sdk_runtime.dispatch_components.request_components.AbstractResponseInterceptor) – Response Interceptor instance to be registered.
Returns:None
add_request_handler(request_handler)

Register input to the request handlers list.

Parameters:request_handler (ask_sdk_runtime.dispatch_components.request_components.AbstractRequestHandler) – Request Handler instance to be registered.
Returns:None
create()

Create a skill object using the registered components.

Returns:a skill object that can be used for invocation.
Return type:Skill
exception_handler(can_handle_func)

Decorator that can be used to add exception handlers easily to the builder.

The can_handle_func has to be a Callable instance, which takes two parameters and no varargs or kwargs. This is because of the ExceptionHandler class signature restrictions. The returned wrapper function can be applied as a decorator on any function that processes the exception raised during dispatcher and returns a response object by the skill. The function should follow the signature of the handle function in ask_sdk_runtime.dispatch_components.exception_components.AbstractExceptionHandler class.

Parameters:can_handle_func (Callable[[Input, Exception], bool]) – The function that validates if the exception can be handled.
Returns:Wrapper function that can be decorated on a handle function.
global_request_interceptor()

Decorator that can be used to add global request interceptors easily to the builder.

The returned wrapper function can be applied as a decorator on any function that processes the input. The function should follow the signature of the process function in ask_sdk_runtime.dispatch_components.request_components.AbstractRequestInterceptor class.

Returns:Wrapper function that can be decorated on a interceptor process function.
global_response_interceptor()

Decorator that can be used to add global response interceptors easily to the builder.

The returned wrapper function can be applied as a decorator on any function that processes the input and the response generated by the request handler. The function should follow the signature of the process function in ask_sdk_runtime.dispatch_components.request_components.AbstractResponseInterceptor class.

Returns:Wrapper function that can be decorated on a interceptor process function.
lambda_handler()

Create a handler function that can be used as handler in AWS Lambda console.

The lambda handler provides a handler function, that acts as an entry point to the AWS Lambda console. Users can set the lambda_handler output to a variable and set the variable as AWS Lambda Handler on the console.

Returns:Handler function to tag on AWS Lambda console.
request_handler(can_handle_func)

Decorator that can be used to add request handlers easily to the builder.

The can_handle_func has to be a Callable instance, which takes a single parameter and no varargs or kwargs. This is because of the RequestHandler class signature restrictions. The returned wrapper function can be applied as a decorator on any function that returns a response object by the skill. The function should follow the signature of the handle function in ask_sdk_runtime.dispatch_components.request_components.AbstractRequestHandler class.

Parameters:can_handle_func (Callable[[Input], bool]) – The function that validates if the request can be handled.
Returns:Wrapper function that can be decorated on a handle function.

Skill Attribute Components

class ask_sdk_core.attributes_manager.AttributesManager(request_envelope, persistence_adapter=None)

Bases: object

AttributesManager is a class that handles three level attributes: request, session and persistence.

Parameters:
request_attributes

Attributes stored at the Request level of the skill lifecycle.

Returns:request attributes for the request life cycle
Return type:Dict[str, object]
session_attributes

Attributes stored at the Session level of the skill lifecycle.

Returns:session attributes extracted from request envelope
Return type:Dict[str, object]
persistent_attributes

Attributes stored at the Persistence level of the skill lifecycle.

Returns:persistent_attributes retrieved from persistence adapter
Return type:Dict[str, object]
Raises:ask_sdk_core.exceptions.AttributesManagerException if trying to get persistent attributes without persistence adapter
save_persistent_attributes()

Save persistent attributes to the persistence layer if a persistence adapter is provided.

Return type:None
Raises:ask_sdk_core.exceptions.AttributesManagerException if trying to save persistence attributes without persistence adapter
delete_persistent_attributes()

Deletes the persistent attributes from the persistence layer. :rtype: None :raises: :py:class: ask_sdk_core.exceptions.AttributesManagerException

if trying to delete persistence attributes without persistence adapter

Abstract Classes

class ask_sdk_core.attributes_manager.AbstractPersistenceAdapter

Bases: object

Abstract class for storing and retrieving persistent attributes from persistence tier given request envelope.

User needs to implement get_attributes method to get attributes from persistent tier and save_attributes method to save attributes to persistent tier.

get_attributes(request_envelope)

Get attributes from persistent tier.

Parameters:request_envelope (RequestEnvelope) – Request Envelope from Alexa service
Returns:A dictionary of attributes retrieved from persistent tier
Return type:Dict[str, object]
save_attributes(request_envelope, attributes)

Save attributes to persistent tier.

Parameters:
  • request_envelope (RequestEnvelope) – request envelope.
  • attributes (Dict[str, object]) – attributes to be saved to persistent tier
Return type:

None

delete_attributes(request_envelope)

Delete attributes from persistent tier.

Parameters:request_envelope (RequestEnvelope) – request envelope.
Return type:None

API Client

class ask_sdk_core.api_client.DefaultApiClient

Bases: ask_sdk_model.services.api_client.ApiClient

Default ApiClient implementation of ask_sdk_model.services.api_client.ApiClient using the requests library.

invoke(request)

Dispatches a request to an API endpoint described in the request.

Resolves the method from input request object, converts the list of header tuples to the required format (dict) for the requests lib call and invokes the method with corresponding parameters on requests library. The response from the call is wrapped under the ApiClientResponse object and the responsibility of translating a response code and response/ error lies with the caller.

Parameters:request (ApiClientRequest) – Request to dispatch to the ApiClient
Returns:Response from the client call
Return type:ApiClientResponse
Raises:ask_sdk_core.exceptions.ApiClientException

SDK Exceptions

exception ask_sdk_core.exceptions.AttributesManagerException

Bases: ask_sdk_runtime.exceptions.AskSdkException

Class for exceptions raised during handling attributes logic

exception ask_sdk_core.exceptions.SerializationException

Bases: ask_sdk_runtime.exceptions.AskSdkException

Class for exceptions raised during serialization/deserialization.

exception ask_sdk_core.exceptions.PersistenceException

Bases: ask_sdk_runtime.exceptions.AskSdkException

Exception class for Persistence Adapter processing.

exception ask_sdk_core.exceptions.ApiClientException

Bases: ask_sdk_runtime.exceptions.AskSdkException

Exception class for ApiClient Adapter processing.

Default Serializer

class ask_sdk_core.serialize.DefaultSerializer

Bases: ask_sdk_model.services.serializer.Serializer

serialize(obj)

Builds a serialized object.

  • If obj is None, return None.
  • If obj is str, int, long, float, bool, return directly.
  • If obj is datetime.datetime, datetime.date convert to string in iso8601 format.
  • If obj is list, serialize each element in the list.
  • If obj is dict, return the dict with serialized values.
  • If obj is ask sdk model, return the dict with keys resolved from the union of model’s attribute_map and deserialized_types and values serialized based on deserialized_types.
  • If obj is a generic class instance, return the dict with keys from instance’s deserialized_types and values serialized based on deserialized_types.
Parameters:obj (object) – The data to serialize.
Returns:The serialized form of data.
Return type:Union[Dict[str, Any], List, Tuple, str, int, float, None]
deserialize(payload, obj_type)

Deserializes payload into an instance of provided obj_type.

The obj_type parameter can be a primitive type, a generic model object or a list / dict of model objects.

The list or dict object type has to be provided as a string format. For eg:

  • 'list[a.b.C]' if the payload is a list of instances of class a.b.C.
  • 'dict(str, a.b.C)' if the payload is a dict containing mappings of str : a.b.C class instance types.

The method looks for a deserialized_types dict in the model class, that mentions which payload values has to be deserialized. In case the payload key names are different than the model attribute names, the corresponding mapping can be provided in another special dict attribute_map. The model class should also have the __init__ method with default values for arguments. Check ask_sdk_model.request_envelope.RequestEnvelope source code for an example implementation.

Parameters:
  • payload (str) – data to be deserialized.
  • obj_type (Union[object, str]) – resolved class name for deserialized object
Returns:

deserialized object

Return type:

object

Raises:

ask_sdk_core.exceptions.SerializationException

General Utilities

ask_sdk_core.utils.predicate.is_canfulfill_intent_name(name)

A predicate function returning a boolean, when name matches the intent name in a CanFulfill Intent Request.

The function can be applied on a ask_sdk_core.handler_input.HandlerInput, to check if the input is of ask_sdk_model.intent_request.CanFulfillIntentRequest type and if the name of the request matches with the passed name.

Parameters:name (str) – Name to be matched with the CanFulfill Intent Request Name
Returns:Predicate function that can be used to check name of the request
Return type:Callable[[HandlerInput], bool]
ask_sdk_core.utils.predicate.is_intent_name(name)

A predicate function returning a boolean, when name matches the name in Intent Request.

The function can be applied on a ask_sdk_core.handler_input.HandlerInput, to check if the input is of ask_sdk_model.intent_request.IntentRequest type and if the name of the request matches with the passed name.

Parameters:name (str) – Name to be matched with the Intent Request Name
Returns:Predicate function that can be used to check name of the request
Return type:Callable[[HandlerInput], bool]
ask_sdk_core.utils.predicate.is_request_type(request_type)

A predicate function returning a boolean, when request type is the passed-in type.

The function can be applied on a ask_sdk_core.handler_input.HandlerInput, to check if the input request type is the passed in request type.

Parameters:request_type (str) – request type to be matched with the input’s request
Returns:Predicate function that can be used to check the type of the request
Return type:Callable[[HandlerInput], bool]
class ask_sdk_core.utils.viewport.OrderedEnum

Bases: enum.Enum

An enumeration.

class ask_sdk_core.utils.viewport.Density

Bases: ask_sdk_core.utils.viewport.OrderedEnum

An enumeration.

XLOW = 0
LOW = 1
MEDIUM = 2
HIGH = 3
XHIGH = 4
XXHIGH = 5
class ask_sdk_core.utils.viewport.Orientation

Bases: ask_sdk_core.utils.viewport.OrderedEnum

An enumeration.

LANDSCAPE = 0
EQUAL = 1
PORTRAIT = 2
class ask_sdk_core.utils.viewport.Size

Bases: ask_sdk_core.utils.viewport.OrderedEnum

An enumeration.

XSMALL = 0
SMALL = 1
MEDIUM = 2
LARGE = 3
XLARGE = 4
class ask_sdk_core.utils.viewport.ViewportProfile

Bases: enum.Enum

An enumeration.

HUB_ROUND_SMALL = 'HUB_ROUND_SMALL'
HUB_LANDSCAPE_MEDIUM = 'HUB_LANDSCAPE_MEDIUM'
HUB_LANDSCAPE_LARGE = 'HUB_LANDSCAPE_LARGE'
MOBILE_LANDSCAPE_SMALL = 'MOBILE_LANDSCAPE_SMALL'
MOBILE_PORTRAIT_SMALL = 'MOBILE_PORTRAIT_SMALL'
MOBILE_LANDSCAPE_MEDIUM = 'MOBILE_LANDSCAPE_MEDIUM'
MOBILE_PORTRAIT_MEDIUM = 'MOBILE_PORTRAIT_MEDIUM'
TV_LANDSCAPE_XLARGE = 'TV_LANDSCAPE_XLARGE'
TV_PORTRAIT_MEDIUM = 'TV_PORTRAIT_MEDIUM'
TV_LANDSCAPE_MEDIUM = 'TV_LANDSCAPE_MEDIUM'
UNKNOWN_VIEWPORT_PROFILE = 'UNKNOWN_VIEWPORT_PROFILE'
ask_sdk_core.utils.viewport.get_orientation(width, height)

Get viewport orientation from given width and height.

Returns:viewport orientation enum
Return type:Orientation
ask_sdk_core.utils.viewport.get_size(size)

Get viewport size from given size.

Returns:viewport size enum
Return type:Size
ask_sdk_core.utils.viewport.get_dpi_group(dpi)

Get viewport density group from given dpi.

Returns:viewport density group enum
Return type:Density
ask_sdk_core.utils.viewport.get_viewport_profile(request_envelope)

Utility method, to get viewport profile.

The viewport profile is calculated using the shape, current pixel width and height, along with the dpi.

If there is no viewport value in request_envelope.context, then an ViewportProfile.UNKNOWN_VIEWPORT_PROFILE is returned.

Parameters:request_envelope (ask_sdk_model.request_envelope.RequestEnvelope) – The alexa request envelope object
Returns:Calculated Viewport Profile enum
Return type:ViewportProfile
ask_sdk_core.utils.request_util.get_locale(handler_input)

Return locale value from input request.

The method returns the locale value present in the request. More information about the locale can be found here : https://developer.amazon.com/docs/custom-skills/request-and-response-json-reference.html#request-locale

Parameters:handler_input (ask_sdk_core.handler_input.HandlerInput) – The handler input instance that is generally passed in the sdk’s request and exception components
Returns:Locale value from the request
Return type:str
ask_sdk_core.utils.request_util.get_request_type(handler_input)

Return the type of the input request.

The method retrieves the request type of the input request. More information about the different request types are mentioned here : https://developer.amazon.com/docs/custom-skills/request-and-response-json-reference.html#request-body-parameters

Parameters:handler_input (ask_sdk_core.handler_input.HandlerInput) – The handler input instance that is generally passed in the sdk’s request and exception components
Returns:Type value of the input request
Return type:str
ask_sdk_core.utils.request_util.get_intent_name(handler_input)

Return the name of the intent request.

The method retrieves the intent name from the input request, only if the input request is an ask_sdk_model.intent_request.IntentRequest. If the input is not an IntentRequest, a TypeError is raised.

Parameters:handler_input (ask_sdk_core.handler_input.HandlerInput) – The handler input instance that is generally passed in the sdk’s request and exception components
Returns:Name of the intent request
Return type:str
Raises:TypeError
ask_sdk_core.utils.request_util.get_account_linking_access_token(handler_input)

Return the access token in the request.

The method retrieves the user’s accessToken from the input request. Once a user successfully enables a skill and links their Alexa account to the skill, the input request will have the user’s access token. A None value is returned if there is no access token in the input request. More information on this can be found here : https://developer.amazon.com/docs/account-linking/add-account-linking-logic-custom-skill.html

Parameters:handler_input (ask_sdk_core.handler_input.HandlerInput) – The handler input instance that is generally passed in the sdk’s request and exception components
Returns:User account linked access token if available. None if not available
Return type:Optional[str]
ask_sdk_core.utils.request_util.get_api_access_token(handler_input)

Return the api access token in the request.

The method retrieves the apiAccessToken from the input request, which has the encapsulated information of permissions granted by the user. This token can be used to call Alexa-specific APIs. More information about this can be found here : https://developer.amazon.com/docs/custom-skills/request-and-response-json-reference.html#system-object

The SDK already includes this token in the API calls done through the service_client_factory in ask_sdk_core.handler_input.HandlerInput.

Parameters:handler_input (ask_sdk_core.handler_input.HandlerInput) – The handler input instance that is generally passed in the sdk’s request and exception components
Returns:Api access token from the input request, which encapsulates any permissions consented by the user
Return type:str
ask_sdk_core.utils.request_util.get_device_id(handler_input)

Return the device id from the input request.

The method retrieves the deviceId property from the input request. This value uniquely identifies the device and is generally used as input for some Alexa-specific API calls. More information about this can be found here : https://developer.amazon.com/docs/custom-skills/request-and-response-json-reference.html#system-object

If there is no device information in the input request, then a None is returned.

Parameters:handler_input (ask_sdk_core.handler_input.HandlerInput) – The handler input instance that is generally passed in the sdk’s request and exception components
Returns:Unique device id of the device used to send the alexa request or None if device information is not present
Return type:Optional[str]
ask_sdk_core.utils.request_util.get_dialog_state(handler_input)

Return the dialog state enum from the intent request.

The method retrieves the dialogState from the intent request, if the skill’s interaction model includes a dialog model. This can be used to determine the current status of user conversation and return the appropriate dialog directives if the conversation is not yet complete. More information on dialog management can be found here : https://developer.amazon.com/docs/custom-skills/define-the-dialog-to-collect-and-confirm-required-information.html

The method returns a None if there is no dialog model added or if the intent doesn’t have dialog management. The method raises a TypeError if the input is not an IntentRequest.

Parameters:handler_input (ask_sdk_core.handler_input.HandlerInput) – The handler input instance that is generally passed in the sdk’s request and exception components.
Returns:State of the dialog model from the intent request.
Return type:Optional[ask_sdk_model.dialog_state.DialogState]
Raises:TypeError if the input is not an IntentRequest
ask_sdk_core.utils.request_util.get_slot(handler_input, slot_name)

Return the slot information from intent request.

The method retrieves the slot information ask_sdk_model.slot.Slot from the input intent request for the given slot_name. More information on the slots can be found here : https://developer.amazon.com/docs/custom-skills/request-types-reference.html#slot-object

If there is no such slot, then a None is returned. If the input request is not an ask_sdk_model.intent_request.IntentRequest, a TypeError is raised.

Parameters:
  • handler_input (ask_sdk_core.handler_input.HandlerInput) – The handler input instance that is generally passed in the sdk’s request and exception components
  • slot_name (str) – Name of the slot that needs to be retrieved
Returns:

Slot information for the provided slot name if it exists, or a None value

Return type:

Optional[ask_sdk_model.slot.Slot]

Raises:

TypeError if the input is not an IntentRequest

ask_sdk_core.utils.request_util.get_slot_value(handler_input, slot_name)

Return the slot value from intent request.

The method retrieves the slot value from the input intent request for the given slot_name. More information on the slots can be found here : https://developer.amazon.com/docs/custom-skills/request-types-reference.html#slot-object

If there is no such slot, then a ValueError is raised. If the input request is not an ask_sdk_model.intent_request.IntentRequest, a TypeError is raised.

Parameters:
  • handler_input (ask_sdk_core.handler_input.HandlerInput) – The handler input instance that is generally passed in the sdk’s request and exception components
  • slot_name (str) – Name of the slot for which the value has to be retrieved
Returns:

Slot value for the provided slot if it exists

Return type:

str

Raises:

TypeError if the input is not an IntentRequest. ValueError is slot doesn’t exist

ask_sdk_core.utils.request_util.get_supported_interfaces(handler_input)

Retrieves the supported interfaces from input request.

The method returns an ask_sdk_model.supported_interfaces.SupportedInterfaces object instance listing each interface that the device supports. For example, if supported_interfaces includes audio_player, then you know that the device supports streaming audio using the AudioPlayer interface. More information on supportedInterfaces can be found here : https://developer.amazon.com/docs/custom-skills/request-and-response-json-reference.html#system-object

Parameters:handler_input (ask_sdk_core.handler_input.HandlerInput) – The handler input instance that is generally passed in the sdk’s request and exception components
Returns:Instance of ask_sdk_model.supported_interfaces.SupportedInterfaces mentioning which all interfaces the device supports
Return type:ask_sdk_model.supported_interfaces.SupportedInterfaces
ask_sdk_core.utils.request_util.is_new_session(handler_input)

Return if the session is new for the input request.

The method retrieves the new value from the input request’s session, which indicates if it’s a new session or not. The ask_sdk_model.session.Session is only included on all standard requests except AudioPlayer, VideoApp and PlaybackController requests. More information can be found here : https://developer.amazon.com/docs/custom-skills/request-and-response-json-reference.html#session-object

A TypeError is raised if the input request doesn’t have the session information.

Parameters:handler_input (ask_sdk_core.handler_input.HandlerInput) – The handler input instance that is generally passed in the sdk’s request and exception components
Returns:Boolean if the session is new for the input request
Return type:bool
Raises:TypeError if the input request doesn’t have a session