-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambda_function.py
39 lines (29 loc) · 1.23 KB
/
lambda_function.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# coding: utf-8
import os
from ask import alexa
from constants import SWITCH_AIR_CONDITIONER_SIGNAL
from irkit.api import InternetAPI
def lambda_handler(request_obj, context=None):
metadata = {
}
return alexa.route_request(request_obj, metadata)
@alexa.default_handler()
def default_handler(request):
""" The default handler gets invoked if no handler is set for a request type """
return alexa.create_response('Just ask')
@alexa.request_handler("LaunchRequest")
def launch_request_handler(request):
''' Handler for LaunchRequest '''
return alexa.create_response(message="hello")
@alexa.request_handler("SessionEndedRequest")
def session_ended_request_handler(request):
return alexa.create_response(message="Goodbye!")
@alexa.intent_handler('SwitchAirConditionerIntent')
def switch_air_conditioner_intent_handler(request):
client_key = os.environ['CLIENTKEY']
device_id = os.environ['DEVICEID']
print('client_key id %s device_id is %s' % (client_key, device_id))
api = InternetAPI()
result = api.messages.post(SWITCH_AIR_CONDITIONER_SIGNAL['data'], client_key, device_id)
print("result is %s" % str(result))
return alexa.create_response('Switch air conditioner', end_session=True)