def launch_request(session, user, request):
	if not st.isValidStUser(user.getUserId()):
		genNewAlexaId(user.getUserId(),10)
		alexaId = getAlexaIdFormUserID(user.getUserId())
		output_speech = "Current user is not a valid smart things user. Please look at the Echo app for help. New Alexa ID has been generated."
		output_type = "PlainText"

		card_type = "Simple"
		card_title = "SmartThings Control"
		card_content = "Current user is not a valid SmartThings user. Please authenticate user with Alexa ID: " + alexaId + " to SmartThings as instructed in the README"

		response = {"outputSpeech": {"type":output_type,"text":output_speech},"card":{"type":card_type,"title":card_title,"content":card_content},'shouldEndSession':True}


		return response
	else:
		output_speech = "Welcome to Smart Things Control App. Please say a command."
		output_type = "PlainText"

		card_type = "Simple"
		card_title = "SmartThings Control - Welcome"
		card_content = "Welcome to SmartThings Control App. Please say a command."

		response = {"outputSpeech": {"type":output_type,"text":output_speech},"card":{"type":card_type,"title":card_title,"content":card_content},'shouldEndSession':False}

		return response
Example #2
0
def launch_request(sessionId, userId, request):
    global mongoST
    if not st.isValidStUser(userId):
        genNewAlexaId(userId, 10)
        alexaId = getAlexaIdFormUserID(userId)
        output_speech = "Current user is not a valid smart things user. Please look at the Echo app for help. New Alexa ID has been generated."
        output_type = "PlainText"

        card_type = "Simple"
        card_title = "SmartThings Control"
        card_content = "Current user is not a valid SmartThings user. Please authenticate user with Alexa ID: " + alexaId + " to SmartThings as instructed in the README"

        response = {
            "outputSpeech": {
                "type": output_type,
                "text": output_speech
            },
            "card": {
                "type": card_type,
                "title": card_title,
                "content": card_content
            },
            'shouldEndSession': True
        }

        return response
    else:
        output_speech = "Welcome to Smart Things Control App. Please say a command."
        output_type = "PlainText"

        card_type = "Simple"
        card_title = "SmartThings Control - Welcome"
        card_content = "Welcome to SmartThings Control App. Please say a command."

        response = {
            "outputSpeech": {
                "type": output_type,
                "text": output_speech
            },
            "card": {
                "type": card_type,
                "title": card_title,
                "content": card_content
            },
            'shouldEndSession': False
        }

        return response
def intent_request(session, user, request):
	print "intent_request"
	if debug: print json.dumps(request,sort_keys=True,indent=4)
	logger.write_log(str(json.dumps(request,sort_keys=True,indent=4)))
	if not st.isValidStUser(user.getUserId()):
		genNewAlexaId(user.getUserId(),10)
		alexaId = getAlexaIdFormUserID(user.getUserId())
		output_speech = "Current user is not a valid smart things user. Please look at the Echo app for help. New Alexa ID has been generated."
		output_type = "PlainText"

		card_type = "Simple"
		card_title = "SmartThings Control"
		card_content = "Current user is not a valid SmartThings user. Please authenticate user with Alexa ID: " + alexaId + " to SmartThings as instructed in the README"

		response = {"outputSpeech": {"type":output_type,"text":output_speech},"card":{"type":card_type,"title":card_title,"content":card_content},'shouldEndSession':True}


		return response

	else:
		try:
			if request['intent']['name'] ==  "STSetMode":
				mode = request['intent']['slots']['mode']['value']
				output_speech = "Setting Smart Things to " + mode + " mode"
				output_type = "PlainText"

				card_type = "Simple"
				card_title = "SmartThings Control - Setting Mode"
				card_content = "Setting Smart Things to " + mode + " mode"

				response = {"outputSpeech": {"type":output_type,"text":output_speech},"card":{"type":card_type,"title":card_title,"content":card_content},'shouldEndSession':True}

				result = st.set_mode(user.getUserId(), mode)

				if mode == result:
					return response
				else:
					st_doc.generateError(result, "Setting Mode")

			elif request['intent']['name'] ==  "STPhrase":
				phrase = request['intent']['slots']['phrase']['value']
				output_speech = "Telling Smart Things to say " + phrase 
				output_type = "PlainText"

				card_type = "Simple"
				card_title = "SmartThings Control - HelloHome"
				card_content = "Telling Smart Things to say " + phrase 

				response = {"outputSpeech": {"type":output_type,"text":output_speech},"card":{"type":card_type,"title":card_title,"content":card_content},'shouldEndSession':True}

				result = st.set_phrase(user.getUserId(), phrase)

				if phrase == result:
					return response
				else:
					st_doc.generateError(result, "Setting Phrase")

			elif request['intent']['name'] ==  "STSwitch":
				switchId = request['intent']['slots']['switch']['value']
				switchState = request['intent']['slots']['state']['value']

				result = st.st_switch(user.getUserId(), switchId, switchState)

				output_speech = "Telling " + switchId + " to turn " + result
				output_type = "PlainText"

				card_type = "Simple"
				card_title = "SmartThings Control - Switch"
				card_content = "Telling " + switchId + " to turn " + result

				response = {"outputSpeech": {"type":output_type,"text":output_speech},"card":{"type":card_type,"title":card_title,"content":card_content},'shouldEndSession':True}

				if switchState == 'toggle':
					if result.lower() != 'on' and result.lower() != 'off':
						return st_doc.generateError(result, "Switch")
					else:
						return response

				elif switchState == result.lower():
					return response
				else:
					st_doc.generateError(result, "Switch")

			elif request['intent']['name'] ==  "STSamples":
				genNewAlexaId(user.getUserId(),10)
				alexaId = getAlexaIdFormUserID(user.getUserId())
				output_speech = "Requesting new samples. New Alexa ID has been generated. Please see the Echo App."
				output_type = "PlainText"

				card_type = "Simple"
				card_title = "SmartThings Control"
				card_content = "New samples have been requested. Please authenticate user with Alexa ID: " + alexaId + " to https://alexa.zpriddy.com/alexa/samples"

				response = {"outputSpeech": {"type":output_type,"text":output_speech},"card":{"type":card_type,"title":card_title,"content":card_content},'shouldEndSession':True}


				return response

			else:
				output_speech = "Smart Things app did not understand your request. Please say it again."
				output_type = "PlainText"

				card_type = "Simple"
				card_title = "SmartThings Control - Welcome"
				card_content = "Welcome to SmartThings Control App. Please say a command."

				response = {"outputSpeech": {"type":output_type,"text":output_speech},"card":{"type":card_type,"title":card_title,"content":card_content},'shouldEndSession':False}

				return response
		except:
			return AlexaDidNotUnderstand()
Example #4
0
def intent_request(sessionId, userId, request):
    print "intent_request"
    if debug: print json.dumps(request, sort_keys=True, indent=4)
    logger.write_log(str(json.dumps(request, sort_keys=True, indent=4)))
    if not st.isValidStUser(userId):
        genNewAlexaId(userId, 10)
        alexaId = getAlexaIdFormUserID(userId)
        output_speech = "Current user is not a valid smart things user. Please look at the Echo app for help. New Alexa ID has been generated."
        output_type = "PlainText"

        card_type = "Simple"
        card_title = "SmartThings Control"
        card_content = "Current user is not a valid SmartThings user. Please authenticate user with Alexa ID: " + alexaId + " to SmartThings as instructed in the README"

        response = {
            "outputSpeech": {
                "type": output_type,
                "text": output_speech
            },
            "card": {
                "type": card_type,
                "title": card_title,
                "content": card_content
            },
            'shouldEndSession': True
        }

        return response

    else:

        if request['intent']['name'] == "STSetMode":
            mode = request['intent']['slots']['mode']['value']
            #output_speech = "Setting Smart Things to " + mode + " mode"
            output_speech = "Ok"
            output_type = "PlainText"

            card_type = "Simple"
            card_title = "SmartThings Control - Setting Mode"
            card_content = "Setting Smart Things to " + mode + " mode"

            response = {
                "outputSpeech": {
                    "type": output_type,
                    "text": output_speech
                },
                "card": {
                    "type": card_type,
                    "title": card_title,
                    "content": card_content
                },
                'shouldEndSession': True
            }

            result = st.set_mode(userId, mode)

            if mode == result:
                return response
            else:
                return st_doc.generateError(result, "Setting Mode")

        elif request['intent']['name'] == "STPhrase":
            genNewAlexaId(userId, 100)
            phrase = request['intent']['slots']['phrase']['value']
            #output_speech = "Telling Smart Things to say " + phrase
            output_speech = "Ok"
            output_type = "PlainText"

            card_type = "Simple"
            card_title = "SmartThings Control - HelloHome"
            card_content = "Telling Smart Things to say " + phrase

            response = {
                "outputSpeech": {
                    "type": output_type,
                    "text": output_speech
                },
                "card": {
                    "type": card_type,
                    "title": card_title,
                    "content": card_content
                },
                'shouldEndSession': True
            }

            result = st.set_phrase(userId, phrase)

            if phrase == result:
                return response
            else:
                return st_doc.generateError(result, "Setting Phrase")

        elif request['intent']['name'] == "STSwitch":
            genNewAlexaId(userId, 100)
            switchId = request['intent']['slots']['switch']['value']
            switchState = request['intent']['slots']['state']['value']

            result = st.st_switch(userId, switchId, switchState)

            #output_speech = "Telling " + switchId + " to turn " + result
            output_speech = "Ok"
            output_type = "PlainText"

            card_type = "Simple"
            card_title = "SmartThings Control - Switch"
            card_content = "Telling " + switchId + " to turn " + result

            response = {
                "outputSpeech": {
                    "type": output_type,
                    "text": output_speech
                },
                "card": {
                    "type": card_type,
                    "title": card_title,
                    "content": card_content
                },
                'shouldEndSession': True
            }

            if switchState == 'toggle':
                if result.lower() != 'on' and result.lower() != 'off':
                    return st_doc.generateError(result, "Switch")
                else:
                    return response

            elif switchState == result.lower():
                return response
            else:
                return st_doc.generateError(result, "Switch")

        elif request['intent']['name'] == "STSamples":
            genNewAlexaId(userId, 10)
            alexaId = getAlexaIdFormUserID(userId)
            output_speech = "Requesting new samples. New Alexa ID has been generated. Please see the Echo App."
            output_type = "PlainText"

            card_type = "Simple"
            card_title = "SmartThings Control"
            card_content = "New samples have been requested. Please authenticate user with Alexa ID: " + alexaId + " to https://alexa.zpriddy.com/alexa/samples"

            response = {
                "outputSpeech": {
                    "type": output_type,
                    "text": output_speech
                },
                "card": {
                    "type": card_type,
                    "title": card_title,
                    "content": card_content
                },
                'shouldEndSession': True
            }

            return response

        else:
            return AlexaDidNotUnderstand()