Last active
January 25, 2017 21:24
-
-
Save benrules2/e40ebb937e0062cd85a5d2a1167ef5e2 to your computer and use it in GitHub Desktop.
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
import boto3 | |
access_key = "YOUR_ACCESS_KEY" | |
access_secret = "YOUR_ACCCESS_SECRET" | |
region ="YOUR_REGION" | |
queue_url = "YOUR_QUEUE_URL" | |
def build_speechlet_response(title, output, reprompt_text, should_end_session): | |
return { | |
'outputSpeech': { | |
'type': 'PlainText', | |
'text': output | |
}, | |
'card': { | |
'type': 'Simple', | |
'title': "SessionSpeechlet - " + title, | |
'content': "SessionSpeechlet - " + output | |
}, | |
'reprompt': { | |
'outputSpeech': { | |
'type': 'PlainText', | |
'text': reprompt_text | |
} | |
}, | |
'shouldEndSession': should_end_session | |
} | |
def build_response(session_attributes, speechlet_response): | |
return { | |
'version': '1.0', | |
'sessionAttributes': session_attributes, | |
'response': speechlet_response | |
} | |
def post_message(client, message_body, url): | |
response = client.send_message(QueueUrl = url, MessageBody= message_body) | |
def lambda_handler(event, context): | |
client = boto3.client('sqs', aws_access_key_id = access_key, aws_secret_access_key = access_secret, region_name = region) | |
intent_name = event['request']['intent']['name'] | |
if intent_name == "MirrorOn": | |
post_message(client, 'on', queue_url) | |
message = "On" | |
elif intent_name == "MirrorOff": | |
post_message(client, 'off', queue_url) | |
message = "off" | |
else: | |
message = "Unknown" | |
speechlet = build_speechlet_response("Mirror Status", message, "", "true") | |
return build_response({}, speechlet) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment