def data_handler(rawdata): global mongoNEST #currentSession = MyDataStore.getSession(rawdata['session']) #currentUser = MyDataStore.getUser(rawdata['session']) sessionId = rawdata['session']['sessionId'] userId = rawdata['session']['user']['userId'] print userId currentRequest = rawdata['request'] #Check for user in database if len([a for a in mongoNEST.find({'nest_amazonEchoID':userId})]) == 0: print "Need to add user into database" currentUser = {'_id':userId,'nest_amazonEchoID':userId,'authenticated':False} mongoNEST.update({'nest_amazonEchoID':userId},currentUser,True) #Check Timestamp of Request timestamp = currentRequest['timestamp'] if utils.datecheck(timestamp,5): response = request_handler(sessionId, userId, currentRequest) else: response = utils.alexaInvalidDate('Nest Control') if response is None: response = utils.alexaDidNotUnderstand('Nest Control') if debug: print json.dumps({"version":appVersion,"response":response},sort_keys=True,indent=4) logger.write_log(str(json.dumps({"version":appVersion,"response":response},sort_keys=True,indent=4))) return json.dumps({"version":appVersion,"response":response},indent=2,sort_keys=True)
def request_handler(session, userId, request): requestType = request['type'] if requestType == "LaunchRequest": return launch_request(session, userId, request) elif requestType == "IntentRequest": return intent_request(session, userId, request) else: return utils.alexaDidNotUnderstand('Nest Control')
def data_handler(rawdata): global mongoNEST #currentSession = MyDataStore.getSession(rawdata['session']) #currentUser = MyDataStore.getUser(rawdata['session']) sessionId = rawdata['session']['sessionId'] userId = rawdata['session']['user']['userId'] print userId currentRequest = rawdata['request'] #Check for user in database if len([a for a in mongoNEST.find({'nest_amazonEchoID': userId})]) == 0: print "Need to add user into database" currentUser = { '_id': userId, 'nest_amazonEchoID': userId, 'authenticated': False } mongoNEST.update({'nest_amazonEchoID': userId}, currentUser, True) #Check Timestamp of Request timestamp = currentRequest['timestamp'] if utils.datecheck(timestamp, 5): response = request_handler(sessionId, userId, currentRequest) else: response = utils.alexaInvalidDate('Nest Control') if response is None: response = utils.alexaDidNotUnderstand('Nest Control') if debug: print json.dumps({ "version": appVersion, "response": response }, sort_keys=True, indent=4) logger.write_log( str( json.dumps({ "version": appVersion, "response": response }, sort_keys=True, indent=4))) return json.dumps({ "version": appVersion, "response": response }, indent=2, sort_keys=True)