def on_intent(intent_request, session, deviceID=None, apiKEY=None, locationInfo=None): intent = intent_request["intent"] intent_name = intent_request["intent"]["name"] if intent_name == "active_Busses_Clemson_Area_Transit": # This returns info on nearby active busses return nearbyBusses(locationInfo) elif intent_name == 'distance_To_Stop_Clemson_Area_Transit': return nearbyStops(deviceID, apiKEY) elif intent_name == 'findStop': # This finds the nearest bus stop return nearbyStops(locationInfo) elif intent_name == 'selectSchool': school = intent_request["intent"]['slots']['schoolName'][ 'resolutions']['resolutionsPerAuthority'][0]["values"][0]['value'][ 'name'] agencyID = getAgencyID(school) return returnSpeech( "Are you sure you want to change the school to {}? The new Agency ID will be {}." .format(school, agencyID)) elif intent_name == 'test_Environment_Clemson_Area_Transit': return testEnvironment() elif intent_name == 'aboutDev': return alexaHelper.devInfo() elif intent_name == "AMAZON.HelpIntent": return get_help_response() elif intent_name == "AMAZON.CancelIntent" or intent_name == "AMAZON.StopIntent": return handle_session_end_request()
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 on_intent(intent_request, session): intent = intent_request["intent"] intent_name = intent_request["intent"]["name"] if intent_name == "whatMoves": return returnComment() elif intent_name == 'aboutDev': return alexaHelper.devInfo() elif intent_name == "AMAZON.HelpIntent": return get_welcome_response() elif intent_name == "AMAZON.CancelIntent" or intent_name == "AMAZON.StopIntent": return handle_session_end_request()
def on_intent(intent_request, session, author): intent = intent_request["intent"] intent_name = intent_request["intent"]["name"] if 'get' in str(intent_name) and 'Quote' in str(intent_name): personName = str(' '.join( re.findall( '[A-Z][^A-Z]*', str(intent_name).replace('get', '').replace('Quote', '')))).lower() print personName return alexaHelper.returnSpeech(quoteAPI.get_author_quotes(personName)) elif intent_name == 'aboutDev': return alexaHelper.devInfo() elif intent_name == "AMAZON.HelpIntent": return alexaHelper.get_help_response(REPEATSPEECH) elif intent_name == "AMAZON.CancelIntent" or intent_name == "AMAZON.StopIntent": return alexaHelper.handle_session_end_request()
def on_intent(intent_request, session): intent = intent_request["intent"] # This is all of the info regarding the intent' intent_name = intent_request["intent"]["name"] # This is specifically the name of the intent you created if intent_name == 'siriVoice': return echoLinguistics.speak("I don't think you'd understand a joke in my language They are not so funny anyway", siri=True) # This is the function that says something without modifying accent if intent_name == 'useAccent': # alexa say something in german with a spanish accent languageName = returnLanguageSlotValue(intent, default="English") # Full name of the language sent in the request: ie, English, Spanish, etc. languageAbbr = echoLinguistics.returnLanguageAbbrFromFull(languageName) #Defines the abbreviated version of the language sent in the request accentVal = intent['slots']['accentVal']['value'] # defines the accent language accentAbbr = echoLinguistics.returnLanguageAbbrFromFull(accentVal) # returns accent abbreviation return echoLinguistics.speak(TEXT_TO_SAY.format(languageName, accentVal), accent=accentAbbr, toLanguage=languageAbbr) # This is the function that says something without modifying accent if intent_name == 'saySomething': # example: alexa say something in german languageName = returnLanguageSlotValue(intent) # Full name of the language sent in the request: ie, English, Spanish, etc. languageAbbr = echoLinguistics.returnLanguageAbbrFromFull(languageName) # This is the abbreviation of language name: ie, English to en return echoLinguistics.speak(TEXT_TO_SAY.format(languageName, languageName), accent=languageAbbr, toLanguage=languageAbbr) # This is the function that says something without modifying accent elif intent_name == 'aboutDev': # Alexa tell me about the developer return alexaHelper.devInfo() elif intent_name == "AMAZON.HelpIntent": # Alexa help return alexaHelper.get_help_response(REPEATSPEECH) elif intent_name == "AMAZON.CancelIntent" or intent_name == "AMAZON.StopIntent": # Alexa stop / Alexa cancel return alexaHelper.handle_session_end_request()
def on_intent(intent_request, session): print("This works") intent = intent_request["intent"] intent_name = intent_request["intent"]["name"] if intent_name == 'searchClass': return searchClasses() elif intent_name == 'selectClass': try: a = intent_request["intent"]['slots']['class']['resolutions'][ 'resolutionsPerAuthority'][0]["values"][0]['value']['name'] sessionVal.type = str(a) except: return colaHacksTemplate( "Are you sure that's the class you're looking for? It doesn't seem to exist at the University of South Carolina" ) return colaHacksTemplate( "Searching for a {} class. What course number?".format(str(a))) elif intent_name == 'selectNum': a = intent_request["intent"]['slots']['courseNum']['value'] sessionVal.num = str(a) try: try: cval = convertToAbbr(str(sessionVal.type)) except: return colaHacksTemplate("abbreviation not valid {}".format( str(sessionVal.type))) sessionVal.crn = Courses.searchCourses(cval, sessionVal.num) courseInfo = Courses.grabCourse(str(sessionVal.crn)) if courseInfo == None: return colaHacksTemplate( "This class is currently in a closed enrollment phase") else: return colaHacksTemplate("Yaaaboy", str(courseInfo)) except: e = getInfo("{}{}".format(sessionVal.type, sessionVal.num)) if e != None: return colaHacksTemplate( "{} {} session number 1 currently has {} seats available for enrollment" .format(str(sessionVal.type), str(sessionVal.num), e['Remaining']), endSession=True) else: return colaHacksTemplate( "This class is currently in a closed enrollment phase") elif intent_name == 'aboutDev': return alexaHelper.devInfo() elif intent_name == 'RestaurantRecommendations': restaurants = [ 'Topio\'s', 'Moe\'s', 'Taco Bell', 'Chick-fil-A', 'Maddio\'s', 'Community Table', 'Top of Carolina' ] return colaHacksTemplate( "You should check out {} in Downtown Columbia! It's one of my favorite places to eat around campus!" .format(choice(restaurants)), endSession=True) elif intent_name == 'Events': events = [ "River Rocks Festival", "2018 Indie Grits Festival", "2018 World Famous Hip Hop Family Day", "Columbia International Festival" ] return colaHacksTemplate( "You can check out the {} in {} this weekend!".format( choice(events), choice(["Downtown Columbia", "Greenville", "Spartanburg"])), endSession=True) elif intent_name == "AMAZON.HelpIntent": return alexaHelper.get_help_response(REPEATSPEECH) elif intent_name == "AMAZON.CancelIntent" or intent_name == "AMAZON.StopIntent": return alexaHelper.handle_session_end_request()
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()