def on_intent(intent_request, session, appdef, user_profile): #-------------------------------------------------------------------------- # Main intent handler function. # Called when Alexa receives a speech intent """ Called when the user specifies an intent for this skill """ myask_log.debug( 5, "on_intent requestId=" + intent_request['requestId'] + ", sessionId=" + session['sessionId']) intent = intent_request['intent'] current_intent = intent_request['intent']['name'] input_locale = intent_request['locale'] myask_log.debug(2, "Got user profile: " + str(user_profile.GetProfile())) if current_intent in ["AMAZON.YesIntent", "AMAZON.NoIntent"]: slots = myask_slots.parse_slots(intent, session, True, input_locale, appdef) if current_intent == "AMAZON.YesIntent": slots["Confirmed"] = True elif current_intent == "AMAZON.NoIntent": slots["Confirmed"] = False if 'prev_intent' in slots: if slots["prev_intent"] == "ChangeDefaultStation": return ConfirmChangeDefaultStation(slots, appdef, user_profile) else: myask_alexaout.createAlexaErrorOutput( "Oops, da ist was schiefgelaufen") else: myask_alexaout.createAlexaErrorOutput( "Sorry, das habe ich nicht verstanden") slots = myask_slots.parse_slots(intent, session, False, input_locale, appdef) slots['current_intent'] = current_intent #Now process the intent via the appropriate function myask_log.debug(3, "Handling current_intent='" + str(current_intent) + "'") if current_intent == "GetDeparturesFromFavorite": return process_GetDeparturesFromFavorite(slots, appdef, user_profile) elif current_intent == "GetDeparturesFromOther": return process_GetDeparturesFromOther(slots, appdef, user_profile) elif current_intent == "GetFavConnecionDepartures": return process_GetFavConnecionDepartures(slots, appdef, user_profile) elif current_intent == "FindConnectionFromFavorite": return process_FindConnectionFromFavorite(slots, appdef, user_profile) elif current_intent == "FindConnectionFromOther": return process_FindConnectionFromOther(slots, appdef, user_profile) elif current_intent == "ChangeDefaultStation": return process_ChangeDefaultStation(slots, appdef, user_profile) elif current_intent == "DeleteProfile": return process_DeleteProfile(slots, appdef, user_profile) elif current_intent == "AMAZON.HelpIntent": return bus_response.out_Help(user_profile) elif current_intent == "AMAZON.CancelIntent" or current_intent == "AMAZON.StopIntent": return bus_response.out_SessionEnd() else: raise ValueError("Invalid intent")
def _FetchConnections(slots, appdef, user_profile): #-------------------------------------------------------------------------- # Finds connections from one bus stop to another # # Requires the following slots to be set: # 'qorg_id' bus stop ID for the origin stop # 'qdest_is' bus stop ID for the destination stop # Optional slots (used to filter the results= # "Busline" : list only this buses for a specific line # "Next" : (future) List only next or next N connections # "Transport" : (future) Filter by Mode of Transport: Bus, Train, Direct # RETURNS: Alexa output structure #-------------------------------------------------------------------------- if myask_slots.checkslots(slots, ['lang', 'qorg_id', 'qdest_id'], "_FetchConnections") == False: return myask_alexaout.createAlexaErrorOutput( myask_slots.error_slots_missing("_FetchConnections"), slots) myask_log.debug( 3, "In Function _FindConnection " + str(slots['qorg_id']) + "-->" + str(slots['qdest_id'])) # prepare slots for call to aseag API # convert all times to localtime, independent of the AWS server location if 'utc_offset' in slots: utc_offset = slots['utc_offset'] else: utc_offset = 0 if 'Busline' in slots and slots['Busline'] != "?": linefilter = slots['Busline'] else: linefilter = '' if 'Transport' in slots: transport = slots['Transport'] else: transport = "" match, result_connections = aseag_api.GetFilteredConnections( slots['qorg_id'], slots['qdest_id'], linefilter, transport, utc_offset) myask_log.debug(2, "connection results from "+ str(slots['qorg_id'])+ " to " + str(slots['qdest_id'])+ \ "match:" +str(match)+":\n" + str(result_connections)) return bus_response.out_Connections(result_connections, slots, appdef, user_profile)
def ConfirmChangeDefaultStation(slots, appdef, user_profile): #--------------------------------------------------------------------------- # Handles confirmation of change of default slot # slot "Confirmed" contains the user answer #--------------------------------------------------------------------------- if myask_slots.checkslots(slots, ['lang', 'Confirmed'], "ConfirmChangeDefaultStation") == False: return myask_alexaout.createAlexaErrorOutput( myask_slots.error_slots_missing("ConfirmChangeDefaultStation"), slots) myask_log.debug(3, "Got command 'ConfirmChangeDefaultStation'") if "Origin" in slots: new_default_id = slots["Origin"] else: myask_log.error( "ConfirmChangeDefaultStation called without slot 'Origin'. How could this happen?" ) new_default_id = user_profile.GetDefaultStopId() if slots["Confirmed"] == True: # user confirmed myask_log.debug(5, "User has confirmed selection of new default station") myask_log.debug(2, "New default station is " + str(new_default_id)) result = user_profile.SetDefaultStopId(new_default_id) if result: myask_log.debug(1, "New favorite set successfully") else: myask_log.error("New favorite could not be set") return bus_response.out_DefaultChanged(slots, appdef, user_profile) else: # user did not confirm return bus_response.out_DefaultChangeCancelled(slots, appdef, user_profile) # if we are here, something went wrong return bus_response.out_ImplementationError( "process_GetFavConnecionDepartures", slots, appdef, user_profile)