def handle(self, handler_input): # type: (HandlerInput) -> Response #print("HandlerInput: ", handler_input.attributes_manager.session_attributes) print("HandlerInput with requestenvelope: ", handler_input.request_envelope.session.user.user_id) user_id = handler_input.request_envelope.session.user.user_id[18:] response = dynamo_helper.get_item_from_users(user_id) if 'Item' in response: if 'user_name' in response['Item'] and response['Item'][ 'user_name'] is not None: speech_text = "Hello, welcome back " + response['Item'][ 'user_name'] + "! How may I assist you?" else: speech_text = "Hello, welcome back! How may I assist you?" else: speech_text = "Hello, welcome to Henry by Greatle. I am here to give you encouragement, advice, and help set and maintain goals. You can say 'Help' to learn more." dynamo_helper.put_item_to_users(user_id) card_text = speech_text handler_input.attributes_manager.session_attributes[ "drunk_mode_state"] = speech_helper.get_drunk_mode_state(user_id) return speech_helper.build_response(handler_input, card_title, card_text, speech_text, img_tuple=get_meme())
def handle(self, handler_input): # type: (HandlerInput) -> Response speech_text = "I don't understand your command. Say 'help' for a list of commands." card_text = speech_text clearSessionAttributes(handler_input) return speech_helper.build_response(handler_input, card_title, card_text, speech_text)
def handle(self, handler_input): # type: (HandlerInput) -> Response user_id = handler_input.request_envelope.session.user.user_id[18:] response = dynamo_helper.get_item_from_users(user_id) with open("greetings.json") as f: data = json.load(f) goodbyes = data["goodbyes"] if 'Item' in response and 'user_name' in response['Item']: name = response['Item']['user_name'] response_options = [x.replace("$name", name) for x in goodbyes] else: response_options = [x.replace("$name", "") for x in goodbyes] speech_text = random.choice(response_options) card_text = speech_text clearSessionAttributes(handler_input) return speech_helper.build_response(handler_input, card_title, card_text, speech_text, end_session=True)
def handle(self, handler_input): speech_text = "I may not be the smartest bot out there, however, if you are having thoughts of suicide, " \ "please call the National Suicide Prevention Lifeline at 1-800-273-8255 (TALK) or go to " \ "SpeakingOfSuicide.com/resources for a list of additional resources." card_text = speech_text clearSessionAttributes(handler_input) return speech_helper.build_response(handler_input, card_title, card_text, speech_text)
def handle(self, handler_input): # type: (HandlerInput) -> Response speech_text = "I can help you keep a journal. Say 'Open Journal' to add a new journal entry. You can say 'Read " \ "me my journal' to access your journal entries.'" card_text = speech_text clearSessionAttributes(handler_input) return speech_helper.build_response(handler_input, card_title, card_text, speech_text)
def handle(self, handler_input): user_id = handler_input.request_envelope.session.user.user_id[18:] speech_text = "Fine" speech_helper.set_drunk_mode(user_id, handler_input, False) card_text = speech_text clearSessionAttributes(handler_input) return speech_helper.build_response(handler_input, card_title, card_text, speech_text)
def handle(self, handler_input): # type: (HandlerInput) -> Response user_id = handler_input.request_envelope.session.user.user_id[18:] speech_text = journal_helper.get_random_journal_entry_helper(user_id) card_text = speech_text return speech_helper.build_response(handler_input, card_title, card_text, speech_text)
def handle(self, handler_input): user_id = handler_input.request_envelope.session.user.user_id[18:] slots = handler_input.request_envelope.request.intent.slots speech_text = goal_helper.complete_goal_helper(user_id, slots) card_text = speech_text clearSessionAttributes(handler_input) return speech_helper.build_response(handler_input, card_title, card_text, speech_text)
def handle(self, handler_input): # type: (HandlerInput) -> Response speech_text = "If you want me to remember your name say something like call me Steven. If you liked a quote and" \ " want to know the author, just say who was the author. I can keep track of your mood, just ask " \ "how have I been. Also, you can say 'turn on drunk mode' to enable drunk mode." card_text = speech_text clearSessionAttributes(handler_input) return speech_helper.build_response(handler_input, card_title, card_text, speech_text)
def handle(self, handler_input): user_id = handler_input.request_envelope.session.user.user_id[18:] slots = handler_input.request_envelope.request.intent.slots name = string.capwords(slots['Name'].value) dynamo_helper.update_name_from_users(user_id, name) speech_text = "Okay, I will call you " + name + " from now on" card_text = speech_text clearSessionAttributes(handler_input) return speech_helper.build_response(handler_input, card_title, card_text, speech_text)
def handle(self, handler_input): # type: (HandlerInput) -> Response user_id = handler_input.request_envelope.session.user.user_id[18:] speech_text = goal_helper.list_completed_goal_helper(user_id) card_text = speech_text clearSessionAttributes(handler_input) return speech_helper.build_response(handler_input, card_title, card_text, speech_text)
def handle(self, handler_input): user_id = handler_input.request_envelope.session.user.user_id[18:] speech_text = "Okay" card_text = speech_text speech_helper.set_drunk_mode(user_id, handler_input, True) clearSessionAttributes(handler_input) return speech_helper.build_response(handler_input, card_title, card_text, speech_text, img_tuple=get_meme('drunk'))
def handle(self, handler_input): # type: (HandlerInput) -> Response speech_text = "I can help you keep track of your goals. You can add a new goal by saying something like 'I " \ "want to meet Hillary Clinton'. Then, if you achieve this, you can say 'I have" \ " completed my goal of meeting Hillary Clinton'. If you give up on your goal, you can say, " \ "'Delete my goal to meet Hillary Clinton'. You can ask me about your goals by saying 'List" \ " my goals' or 'List my completed goals.'" card_text = speech_text clearSessionAttributes(handler_input) return speech_helper.build_response(handler_input, card_title, card_text, speech_text)
def handle(self, handler_input): # type: (HandlerInput) -> Response user_id = handler_input.request_envelope.session.user.user_id[18:] slots = handler_input.request_envelope.request.intent.slots speech_text = journal_helper.create_journal_helper(user_id, slots) card_text = speech_text clearSessionAttributes(handler_input) return speech_helper.build_response(handler_input, card_title, card_text, speech_text)
def handle(self, handler_input): # type: (HandlerInput) -> Response speech_text = "I can give you life advice. You can ask me for advice by saying something like 'I want advice" \ " about love'. Once I learn more about you, I can give you personal advice, just say give me personal advice" \ " I can also help you manage your goals. Say 'goal help' to learn more. I can keep " \ "a journal for you. Say 'journal help' to learn about this feature. To learn about my other " \ "features, say 'more help'." card_text = speech_text clearSessionAttributes(handler_input) return speech_helper.build_response(handler_input, card_title, card_text, speech_text)
def handle(self, handler_input): user_id = handler_input.request_envelope.session.user.user_id[18:] slots = handler_input.request_envelope.request.intent.slots speech_text, goal_description = goal_helper.retrieve_goal_to_delete_helper( user_id, slots) handler_input.attributes_manager.session_attributes[ GOAL_TO_DELETE_SESSION_ATTRIBUTE] = goal_description card_text = speech_text clearSessionAttributes(handler_input, deleteGoalToDelete=False) return speech_helper.build_response(handler_input, card_title, card_text, speech_text)
def handle(self, handler_input): thanks = [ "You're welcome!", "No problem amigo!", "Aww shucks, you are making me blush.", "No, thank YOU!" ] speech_text = thanks[random.randint( 0, len(thanks) - 1)] + " Here is a funny picture from Reddit, I hope." card_text = speech_text clearSessionAttributes(handler_input) return speech_helper.build_response(handler_input, card_title, card_text, speech_text, img_tuple=get_meme('funny'))
def handle(self, handler_input): # type: (HandlerInput) -> Response user_id = handler_input.request_envelope.session.user.user_id[18:] slots = handler_input.request_envelope.request.intent.slots speech_text, is_remembered = goal_helper.create_goal_helper( user_id, slots) card_text = speech_text meme = get_meme('GetMotivated') if is_remembered else None clearSessionAttributes(handler_input) return speech_helper.build_response(handler_input, card_title, card_text, speech_text, img_tuple=meme)
def handle(self, handler_input): # type: (HandlerInput) -> Response print('session attributes:', handler_input.attributes_manager.session_attributes) print("Advice called") slots = handler_input.request_envelope.request.intent.slots print(slots) keywords = slots['AdviceTopic'].value print(keywords) handler_input.attributes_manager.session_attributes[ LAST_QUERY_SESSION_ATTRIBUTE] = keywords queryResults = discovery_helper.query(keywords) print('query results:', queryResults) if queryResults is not None and isinstance(queryResults, (tuple, list)): passage = queryResults[0] docId = queryResults[1] queryId = queryResults[2] author = queryResults[3] speech_text = passage + "<break time='1s'/> Was that helpful?" card_text = passage + "\nWas that helpful?" handler_input.attributes_manager.session_attributes[ LAST_QUERY_ID_SESSION_ATTRIBUTE] = queryId print('session attributes:', handler_input.attributes_manager.session_attributes) handler_input.attributes_manager.session_attributes[ LAST_DOCUMENT_ID_SESSION_ATTRIBUTE] = docId handler_input.attributes_manager.session_attributes[ LAST_AUTHOR_SESSION_ATTRIBUTE] = author print('session attributes:', handler_input.attributes_manager.session_attributes) elif queryResults is not None and isinstance(queryResults, str): speech_text = queryResults card_text = speech_text handler_input.attributes_manager.session_attributes[ LAST_AUTHOR_SESSION_ATTRIBUTE] = None else: speech_text = 'I was unable to find anything on that subject.' card_text = speech_text clearSessionAttributes(handler_input, deleteQueryID=False) return speech_helper.build_response(handler_input, card_title, card_text, speech_text)
def handle(self, handler_input): if handler_input.request_envelope.session.attributes is not None and handler_input.request_envelope.session.attributes.get( GOAL_TO_DELETE_SESSION_ATTRIBUTE) is not None: speech_text = "Okay, I will not delete that goal" elif handler_input.request_envelope.session.attributes is not None and handler_input.request_envelope.session.attributes.get( LAST_QUERY_ID_SESSION_ATTRIBUTE) is not None: speech_text = "Sorry, I'll take note of that." discovery_helper.rateQuery( handler_input.request_envelope.session. attributes[LAST_QUERY_ID_SESSION_ATTRIBUTE], handler_input.request_envelope.session. attributes[LAST_DOCUMENT_ID_SESSION_ATTRIBUTE], relevant=False) else: speech_text = "Sorry, I am unsure why you said no. Please start your intent over." card_text = speech_text clearSessionAttributes(handler_input) return speech_helper.build_response(handler_input, card_title, card_text, speech_text)
def handle(self, handler_input): # type: (HandlerInput) -> Response if handler_input.request_envelope.session.attributes is not None and \ handler_input.request_envelope.session.attributes.get(LAST_AUTHOR_SESSION_ATTRIBUTE) is not None: author = handler_input.attributes_manager.session_attributes[ LAST_AUTHOR_SESSION_ATTRIBUTE] speech_text = "The author of the last quote was " + author image_tuple = (author, 'https://avatars.io/twitter/' + "".join(author.split()) + '/large', 'From Twitter') else: speech_text = "There are no recent quotes or the author is unavailable." image_tuple = None card_text = speech_text clearSessionAttributes(handler_input) return speech_helper.build_response(handler_input, card_title, card_text, speech_text, img_tuple=image_tuple)
def handle(self, handler_input): # type: (HandlerInput) -> Response user_id = handler_input.request_envelope.session.user.user_id[18:] goal_list = dynamo_helper.list_goals(user_id) completed_goal_list = dynamo_helper.list_goals_with_status( user_id, "COMPLETED") journal_entries = journal_helper.get_all_entries(user_id) all_text = "" for goal in goal_list: all_text = all_text + goal + " " for goal in completed_goal_list: all_text = all_text + goal + " " for journal_entry in journal_entries: all_text = all_text + journal_entry["text"] + " " if all_text == "": speech_text = "You don't have any journal entries or goals. Add some so we know more about you." else: user_sentiment = sentiment_helper.sentiment_with_threshold( all_text) if user_sentiment == "HAPPY": speech_text = "You've been very happy. Keep it up! You're a positive force in the universe!" elif user_sentiment == "SLIGHTLY_HAPPY": speech_text = "You've been quite happy. That's pretty good." elif user_sentiment == "NEUTRAL": speech_text = "You've been feeling neutral. I have no feelings about this, one way or another." elif user_sentiment == "SLIGHTLY_SAD": speech_text = "It seems like you've been a little under the weather. That's okay. Tomorrow's a new day." elif user_sentiment == "SAD": speech_text = "It seems like you have not been feeling good. That's okay. Everybody feels sad " \ "sometimes." card_text = speech_text clearSessionAttributes(handler_input) return speech_helper.build_response(handler_input, card_title, card_text, speech_text)
def handle(self, handler_input): user_id = handler_input.request_envelope.session.user.user_id[18:] if handler_input.request_envelope.session.attributes is not None and \ handler_input.request_envelope.session.attributes.get(GOAL_TO_DELETE_SESSION_ATTRIBUTE) is not None: dynamo_helper.delete_goal( user_id, handler_input.request_envelope.session. attributes[GOAL_TO_DELETE_SESSION_ATTRIBUTE]) speech_text = "Okay, I deleted that goal" elif handler_input.request_envelope.session.attributes is not None and handler_input.request_envelope.session.attributes.get( LAST_QUERY_ID_SESSION_ATTRIBUTE) is not None: speech_text = "Good. I'll record that." discovery_helper.rateQuery( handler_input.request_envelope.session. attributes[LAST_QUERY_ID_SESSION_ATTRIBUTE], handler_input.request_envelope.session. attributes[LAST_DOCUMENT_ID_SESSION_ATTRIBUTE], relevant=True) else: speech_text = "Sorry, I am unsure why you said yes. Please start your intent over." card_text = speech_text clearSessionAttributes(handler_input) return speech_helper.build_response(handler_input, card_title, card_text, speech_text)
def handle(self, handler_input): user_id = handler_input.request_envelope.session.user.user_id[18:] goal_list = dynamo_helper.list_goals(user_id) completed_goal_list = dynamo_helper.list_goals_with_status( user_id, "COMPLETED") journal_entries = journal_helper.get_all_entries(user_id) all_text = "" user_sentiment = "" for goal in goal_list: all_text = all_text + goal + " " for goal in completed_goal_list: all_text = all_text + goal + " " for journal_entry in journal_entries: all_text = all_text + journal_entry["text"] + " " if all_text == "": speech_text = "You don't have any journal entries or goals. Tell me more about yourself so I can give you relevant advice" else: user_sentiment = sentiment_helper.sentiment_with_threshold( all_text) if user_sentiment != "": query_word = sentiment_helper.get_query_word_from_sentiment( user_sentiment) handler_input.attributes_manager.session_attributes[ LAST_QUERY_SESSION_ATTRIBUTE] = query_word queryResults = discovery_helper.query(query_word) print('query results:', queryResults) if queryResults is not None and isinstance(queryResults, (tuple, list)): passage = queryResults[0] docId = queryResults[1] queryId = queryResults[2] author = queryResults[3] speech_text = passage + "<break time='1s'/> Was that helpful?" card_text = passage + "\nWas that helpful?" handler_input.attributes_manager.session_attributes[ LAST_QUERY_ID_SESSION_ATTRIBUTE] = queryId print('session attributes:', handler_input.attributes_manager.session_attributes) handler_input.attributes_manager.session_attributes[ LAST_DOCUMENT_ID_SESSION_ATTRIBUTE] = docId handler_input.attributes_manager.session_attributes[ LAST_AUTHOR_SESSION_ATTRIBUTE] = author print('session attributes:', handler_input.attributes_manager.session_attributes) elif queryResults is not None and isinstance(queryResults, str): speech_text = queryResults card_text = speech_text handler_input.attributes_manager.session_attributes[ LAST_AUTHOR_SESSION_ATTRIBUTE] = None else: speech_text = 'Ask me later when you have used the skill more' card_text = speech_text clearSessionAttributes(handler_input, deleteQueryID=False) else: card_text = speech_text return speech_helper.build_response(handler_input, card_title, card_text, speech_text)