def lambda_handler(event, context): print event if event["request"]["type"] == "LaunchRequest": return alexaHelper.get_welcome_response(SKILLNAME, INITIALSPEECH, REPEATSPEECH) elif event["request"]["type"] == "IntentRequest": return on_intent(event["request"], event["session"])
def on_intent(intent_request, session): print str(session) intent = intent_request["intent"] intent_name = intent_request["intent"]["name"] try: question = session['attributes']['question'] except: question = "" if intent_name == "startDiagnosis": while len(question) < 3: question = random.choice(sentences) idNum = str(random.randint(100,999)) return createResponse("Repeat the following sentence. {}".format(question), False, idNum=idNum, question=question) elif intent_name == "readSentence": try: e = session['attributes']['counter'] except: e = 0 count = e + 1 try: question = session['attributes']['question'] except: question = "" try: idNum = session['attributes']['ID'] except: idNum = '0' print getAllSlots(intent_request) if count > 3: return createResponse("End session", True, sessionCount=count) else: while len(question) < 3: question = random.choice(sentences) try: print session['attributes']['Question'] value = levenshtein(str(session['attributes']['Question']).translate(None, string.punctuation).lower(), str(getAllSlots(intent_request))) results = getAllMisTypes(str(getAllSlots(intent_request)), str(session['attributes']['Question']).translate(None, string.punctuation).lower(), countDict = session['attributes']['countDict']) print results except Exception as exp: print traceback.print_exc() value = 0 if count != 3: return createResponse("Repeat the following sentence. {}".format(question), False, sessionCount=count, question=question, countDict=results, idNum=idNum) else: countDict=results requests.post("https://reportgeneration.herokuapp.com/report/{}".format(idNum), data=str(json.dumps(results))) print("Request made") return createResponse("Your diagnosis has been generated... Your Report Identification number: {}".format(' '.join(list(idNum))), True, sessionCount=count, question=question, countDict=results, idNum=idNum) elif intent_name == 'aboutDev': return alexaHelper.devInfo() elif intent_name == "AMAZON.HelpIntent": return alexaHelper.get_welcome_response() elif intent_name == "AMAZON.CancelIntent" or intent_name == "AMAZON.StopIntent": return alexaHelper.handle_session_end_request()
def lambda_handler(event, context): appID = event['session']['application']['applicationId'] try: appPerson = appInfo[appID] except: appInfo = updateAfterIntent.updateAppInfo() appPerson = appInfo[appID] if event["request"]["type"] == "LaunchRequest": return alexaHelper.get_welcome_response( SKILLNAME.replace("$NAME", appPerson), INITIALSPEECH.replace("$NAME", appPerson), REPEATSPEECH) elif event["request"]["type"] == "IntentRequest": return on_intent(event["request"], event["session"], appPerson)
def on_intent(intent_request, session): print str(session) intent = intent_request["intent"] intent_name = intent_request["intent"]["name"] try: question = session['attributes']['question'] except: question = "" if intent_name == "startDiagnosis": while len(question) < 3: question = random.choice(sentences) return createResponse( "Repeat the following sentence. {}".format(question), False, question=question) elif intent_name == "readSentence": try: e = session['attributes']['counter'] except: e = 0 count = e + 1 try: question = session['attributes']['question'] except: question = "" print getAllSlots(intent_request) if count > 3: return createResponse("End session", True, sessionCount=count) else: while len(question) < 3: question = random.choice(sentences) try: print session['attributes']['Question'] value = levenshtein( str(session['attributes']['Question']).translate( None, string.punctuation).lower(), str(getAllSlots(intent_request))) results = getAllMisTypes( str(getAllSlots(intent_request)), str(session['attributes']['Question']).translate( None, string.punctuation).lower(), countDict=session['attributes']['countDict']) print results except Exception as exp: print traceback.print_exc() value = 0 if count != 3: return createResponse( "Stutter: {}. Partial: {}. M to P: {}. T H to W: {}. Levenshtein: {} . Repeat the following sentence. {}" .format(results["Stutter"], results["Partial"], results["MN"], results["WP"], value, question), False, sessionCount=count, question=question, countDict=results) else: countDict = results return createResponse( "Stutter: {}. Partial: {}. M to P: {}. T H to W: {}. Levenshtein: {} . Generating Report..." .format(results["Stutter"], results["Partial"], results["MN"], results["WP"], value), True, sessionCount=count, question=question, countDict=results) elif intent_name == 'aboutDev': return alexaHelper.devInfo() elif intent_name == "AMAZON.HelpIntent": return alexaHelper.get_welcome_response() elif intent_name == "AMAZON.CancelIntent" or intent_name == "AMAZON.StopIntent": return alexaHelper.handle_session_end_request()