echokit¶
Requests¶
For more info, see: JSON Interface Reference for Custom Skills
Handling Requests¶
Setup/verification¶
-
echokit.application_id¶ Set to your skill’s application ID, found in the Alexa dev portal.
-
echokit.verify_application_id= True¶ If True, will verify the application ID in each request against
echokit.application_id, logging an error and raising aValueErrorexception upon mismatch. If False, will ignore the ID and continue as normal.Type: bool
-
echokit.handler(event, context)¶ Handles incoming Lambda requests and routes them to the appropriate function based on the
@echokit.on_session_launch,@echokit.on_session_ended,@echokit.on_intent()and@echokit.fallbackdecorators.Assign
handler == echokit.handlerin your main module and set[your_module].handleras the handler in your Lambda function’s configuration.
Responding¶
-
echokit.ask(speech, reprompt=None, ssml=False, session_attributes=None)¶ Ask the user a question. By default, shouldEndSession is False
Parameters: - speech (str) – OutputSpeech text for response
- reprompt (str) – OutputSpeech text to reprompt the user
- ssml (bool) – True if speech text is in SSML format (default: False)
- session_attributes (dict) – Session attributes to set
-
echokit.tell(speech, ssml=False)¶ Tell the user something. By default, shouldEndSession is True. Additions can be made via the
ASKResponsemethods, such as adding a card likeechokit.tell('Hi').simple_card('Hello!', 'How are you?')Parameters: - speech (str) – OutputSpeech text for response
- ssml (bool) – True if speech text is in SSML format (default: False)
-
class
echokit.ASKResponse¶ Base class for responses.
echokit.ask()andechokit.tell()are convenience methods which generate this class.-
should_end_session(end_session)¶ Parameters: end_session (bool) – True or False to end the session
-
simple_card(title=None, content=None)¶ Attaches a Simple type card to your response
-
standard_card(title=None, text=None, small_image_url=None, large_image_url=None)¶ Attaches a Standard type card to your response
Parameters: - title (str) –
- text (str) –
- small_image_url (str) –
- large_image_url (str) –
-
link_account_card(content=None)¶ Attaches a LinkAccount type card to your response
-
session_attributes(session_attributes)¶ Parameters: session_attributes (dict) – Session attributes to set in your response
-
reprompt(speech, ssml=False)¶ Attaches a reprompt to your response
Parameters: - speech (str) – Speech text
- ssml (bool) – Set to True if using SSML
-
speech(text, ssml=False)¶ Attaches OutputSpeech to your response
Parameters: - text (str) – Speech text
- ssml (bool) – True if speech text is in SSML format
-
Example¶
import echokit
handler = echokit.handler
echokit.application_id = "my_app_id"
Decorators¶
-
@echokit.on_session_launch¶ Designates handler function for
LaunchRequest
-
@echokit.on_session_ended¶ Designates handler function for a
SessionEndedRequest
-
@echokit.on_intent(intent_name)¶ Designates handler function for an
IntentRequestmatching intent_nameParameters: intent_name (str) – Name of the intent to handle ( Intent.name)
-
@echokit.slot(name, dest=None)¶ Causes the value of the slot to be passed to your function as keyword param name, or one set in dest (ex: if an IntentRequest sends you a slot named ‘manufacturer‘ in your interaction model, set
@slot(name='manufacturer')and its value will be passed).Parameters: - name (str) – Name of the slot received in the request (by default, will be passed to your function as a keyword argument)
- dest (str) – (Default: None) Set to change the keyword argument passed to your function
-
@echokit.fallback¶ Designates the handler function for any
IntentRequestwhose name doesn’t have an associated handler via@echokit.on_intent(). If not used, will default to:-
echokit.fallback_default(request, session)¶ The default handler for incoming intent requests where the intent name doesn’t match anything handled via
@echokit.on_intent()and no handler has been specified via@echokit.fallback.Returns: PlainText speech: “Sorry, I didn’t understand your request“ Return type: Response
-
Usage¶
Handler functions should accept a single argument, which will be a wrapper for the request/session/context/version received. If you use the @slot decorator, it should accept the slot’s name or the value set for dest:
@echokit.on_session_launch
def session_started(request_wrapper):
return echokit.ask('You just started a new session!')
@echokit.on_intent('OrderIntent')
@echokit.slot('MenuItem', dest='menu_item')
def order_intent(request_wrapper, menu_item):
request = request_wrapper.request
return echokit.tell(f"You just ordered {menu_item}")\
.simple_card(title="Previous order", content=menu_item)