def lambda_handler(event, context): #Checks to make sure application id is same as alexa skill (links) if (event['session']['application']['applicationId'] != #Change to application id listed under your alexa skill in the developer portal "amzn1.ask.skill.XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"): raise ValueError("Invalid Application ID") if event["session"]["new"]: on_session_started({"requestId": event["request"]["requestId"]}, event["session"]) #check event types and call appropriate response if event["request"]["type"] == "LaunchRequest": return on_launch(event["request"], event["session"]) elif event["request"]["type"] == "IntentRequest": return on_intent(event["request"], event["session"]) elif event["request"]["type"] == "SessionEndedRequest": return on_session_ended(event["request"], event["session"]) #################################################################### def on_session_started(session_started_request, session): print "Starting new." #################################################################### def on_launch(launch_request, session): return get_welcome_response() #################################################################### def on_intent(intent_request, session): intent = intent_request["intent"] intent_name = intent_request["intent"]["name"] if intent_name == "Hello": return say_hello() elif intent_name == "AMAZON.HelpIntent": return get_welcome_response() elif intent_name == "AMAZON.CancelIntent" or intent_name == "AMAZON.StopIntent": return handle_session_end_request() else: raise ValueError("Invalid intent") #################################################################### def on_session_ended(session_ended_request, session): print "Ending session." #################################################################### def say_hello(): session_attributes = {} card_title = "Hello World" speech_output = "Hello World" reprompt_text = "" should_end_session = True return build_response(session_attributes, build_speechlet_response( card_title, speech_output, reprompt_text, should_end_session)) #################################################################### def build_response(session_attributes, speechlet_response): return { "version": "1.0", "sessionAttributes": session_attributes, "response": speechlet_response } #################################################################### def build_speechlet_response(title, output, reprompt_text, should_end_session): #return data in json format to alexa skills kit return { "outputSpeech": { "type": "PlainText", "text": output }, "card": { "type": "Simple", "title": title, "content": output }, "reprompt": { "outputSpeech": { "type": "PlainText", "text": reprompt_text } }, "shouldEndSession": should_end_session } ####################################################################