def get_winner_intent_handler(request): winner =PickAWinner() print("[debug] Called the PickWinnerIntent Intent") card = r.create_card(title="Picking Winners!", subtitle=None, content="The winner is " + winner) return r.create_response(message="The winner is " + winner, end_session=True, card_obj=card)
def launch_request_handler(request): """ Annoatate functions with @VoiceHandler so that they can be automatically mapped to request types. Use the 'request_type' field to map them to non-intent requests """ return r.create_response(message="Hello Welcome to My Recipes!")
def get_welcome_intent_handler(request): response_text = "Welcome to the Los Angeles A.W.S Meetup. \ This month we're talking about A.W.S Lambda, and what better way to demo Lambda than to \ have Alexa call Lambda Functions. This demo function will call the Meetup A.P.I and check \ to see who R S V P'd for this event and randomly pick one of those members to win an Amazon Echo." return r.create_response(message=response_text, end_session=True)
def call_back_intent_handler(request): """ You can insert arbitrary business logic code here """ rap = get_rhyme(chains["toponehundredraps"], 8) upload_rap(rap[7:-94]) return r.create_response(is_ssml=True, message="<speak>Aight yo I'm gonna rap. Alexa <break time=\"1.5s\" /> start beatboxing <break time=\"1.5s\" /> " + rap + '<audio src="https://s3.amazonaws.com/danielgwilson.com/MLG+Horns+Sound+Effect.mp3" /></speak>')
def get_recipe_intent_handler(request): """ Use the 'intent' field in the VoiceHandler to map to the respective intent. You can insert arbitrary business logic code here """ # Get variables like userId, slots, intent name etc from the 'Request' object ingredient = request.get_slot_value("Ingredient") ingredient = ingredient if ingredient else "" #Use ResponseBuilder object to build responses and UI cards card = r.create_card(title="GetRecipeIntent activated", subtitle=None, content="asked alexa to find a recipe using {}" .format(ingredient)) return r.create_response(message="Finding a recipe with the ingredient {}".format(ingredient), end_session=False, card_obj=card)
def get_help_intent_handler(request): """ Use the 'intent' field in the VoiceHandler to map to the respective intent. You can insert arbitrary business logic code here """ # Get variables like userId, slots, intent name etc from the 'Request' object # ingredient = request.get_slot_value("Ingredient") # ingredient = ingredient if ingredient else "" #Use ResponseBuilder object to build responses and UI cards print("[debug] Called the HelpIntent Intent") card = r.create_card(title="Handy Helper", subtitle=None, content="Ok, you need some help") return r.create_response(message="Ok, you need some help", end_session=True, card_obj=card)
def get_rapper_intent_handler(request): """ Use the 'intent' field in the VoiceHandler to map to the respective intent. You can insert arbitrary business logic code here """ # Get variables like userId, slots, intent name etc from the 'Request' object rapper = request.get_slot_value("Rapper") rapper = rapper if rapper else "" with open("models/intros.json") as file: intros = json.load(file) try: intro = intros[rapper] except KeyError: intro = "" try: rap = get_rhyme(chains[rapper], 8) except KeyError: return r.create_response(message="I heard, %s, but I don't know that rapper." % rapper, end_session=False) rap = "<speak>Yo my name is {}. ".format(rapper) + intro + " " + rap + '<audio src="https://s3.amazonaws.com/danielgwilson.com/MLG+Horns+Sound+Effect.mp3" /></speak>' upload_rap(rap[7:-94]) # Use ResponseBuilder object to build responses and UI cards card = r.create_card(title="Rapping", subtitle=None, content=rap) return r.create_response(message=rap, is_ssml=True, end_session=False, card_obj=card)
def call_back_intent_handler(request): """ You can insert arbitrary business logic code here """ return r.create_response(message="Getting Next Recipe ... 123")
def session_ended_request_handler(request): return r.create_response(message="Goodbye!")
def default_handler(request): """ The default handler gets invoked if no handler is set for a request """ return r.create_response(message="Just ask")
def get_lyrical_intent_handler(request): ''' Handler when the user prompts alexa with lyrics ''' if request.verify_application(request.get_app_id()) == False: return httplib.responses[400] ''' The request_stage determines where we are currently at in the conversation ''' request_stage = request.get_req_attributes("request stage") if request_stage is None: request_stage = "Start" lyrics = request.get_slot_value("Lyrics") confirmation = request.get_slot_value("Confirmation") negation = request.get_slot_value("Negation") ''' Deals with the possibility that the user is thinking of lyrics that have the words yes or no and the beginning''' if lyrics is None and request_stage == "Start": return build_response(message=default_message_reprompt, end_session=False, reprompt_message=default_message_reprompt, sessionAttributes={"request stage" : "Start"}) if lyrics is None: if confirmation: lyrics = confirmation elif negation: lyrics = negation ''' Setting default values that will be changed in each stage ''' message = default_message end_session = False card_obj = None response_attributes = None reprompt_message = None if request_stage == "Start": message = knowledge_artist_name_message response_attributes = {"request stage" : "Add Artist Question", "lyrics" : lyrics} reprompt_message = knowledge_artist_name_reprompt elif request_stage == "Add Artist Question": ''' If the user knows the artists name, get the name and attach it to search query string ''' if confirmation: message = artist_name_message response_attributes = {"request stage" : "Artist Name Question", "lyrics" : request.get_req_attributes("lyrics")} reprompt_message = artist_name_reprompt elif negation: response_dict = build_song(request, request.get_req_attributes('lyrics'), '', 0) if response_dict: message = response_dict["message"] reprompt_message = response_dict["reprompt"] response_attributes = response_dict["response attributes"] else: return build_response(message=no_song_message, end_session=True, card_obj=card_obj) elif lyrics: ''' In the event the user does not give a confirmation or negation but instead gives the actual artist name''' response_dict = build_song(request, request.get_req_attributes('lyrics'), lyrics, 0) if response_dict: message = response_dict["message"] reprompt_message = response_dict["reprompt"] response_attributes = response_dict["response attributes"] else: return build_response(message=no_song_message, end_session=True, card_obj=card_obj) elif request_stage == "Artist Name Question": response_dict = build_song(request, request.get_req_attributes('lyrics'), lyrics, 0) if response_dict: message = response_dict["message"] reprompt_message = response_dict["reprompt"] response_attributes = response_dict["response attributes"] else: return build_response(message=no_song_message, end_session=True, card_obj=card_obj) elif request_stage == "Songs List": if negation: songs = request.get_req_attributes("songs") indexOfSong = request.get_req_attributes("index of song") indexOfSong = indexOfSong + 1 if indexOfSong > len(songs) - 1: message = out_of_song_message end_session = True else: song = songs[indexOfSong] artist = song[song.find('%') + 1:] song = song[:song.find('%')] message = potential_song_message % (song, artist) reprompt_message = potential_song_reprompt response_attributes = {"request stage" : "Songs List", "songs" : songs, "index of song" : indexOfSong, "lyrics" : request.get_req_attributes("lyrics"), "artist" : request.get_req_attributes("artist") } elif confirmation: end_session = True message = success_message songs = request.get_req_attributes("songs") indexOfSong = request.get_req_attributes("index of song") song = songs[indexOfSong] artist = song[song.find('%') + 1:] song = song[:song.find('%')] spoken_artist = request.get_req_attributes("artist") ''' If the user told Alexa the artists name ''' if spoken_artist == "": card_content = "Alexa heard: %s" % (request.get_req_attributes("lyrics")) else: card_content = "Alexa heard: %s by %s" % (request.get_req_attributes("lyrics"), request.get_req_attributes("artist")) card_obj = r.create_card(title="%s by %s" % (song, artist), subtitle=artist, content=card_content) else: message = invalid_utterance_message reprompt_message = potential_song_reprompt end_session = False card_obj = None response_attributes = {"request stage": "Songs List", "songs" : request.get_req_attributes("songs"), "index of song" : request.get_req_attributes("index of song"), "lyrics" : request.get_req_attributes("lyrics"), "artist": request.get_req_attributes("artist")} ''' After all manipulation, build the response and return it to Alexa ''' return build_response(message=message, end_session=end_session, card_obj=card_obj, sessionAttributes=response_attributes, reprompt_message=reprompt_message)
def build_response(message=None, end_session=False, card_obj=None, sessionAttributes={'session' : 'null'}, reprompt_message=help_message): ''' Method to build and return the response back to the user ''' response = r.create_response(message=message, end_session=end_session, card_obj=card_obj, reprompt_message=reprompt_message) response['sessionAttributes'] = sessionAttributes return response
def call_back_intent_handler(request): """ You can insert arbitrary business logic code here """ return r.create_response(message="boots and cats and boots and cats and boots and cats and boots and cats and boots and cats and boots and cats and boots and cats and boots and cats and boots and cats and boots and cats and boots and cats and boots and cats and boots and cats and boots and cats and boots and cats and ")
def session_ended_request_handler(request): print("[debug] Request type was SessionEndedRequest") return r.create_response(message="Goodbye!")
def default_handler(request): """ The default handler gets invoked if no handler is set for a request """ print("[debug] Didn't match any intents, therefore we invoked the default handler") return r.create_response(message="Just ask")