def intent_task_specified(self, intent): # check to see if we parsed a value content_present = intent['slots']['TASK'].get('resolutions') task = None if content_present: resolution = intent['slots']['TASK']['resolutions'][ 'resolutionsPerAuthority'][0] # if we have a task match if resolution.get('values'): values = resolution['values'][0] task = values['value']['id'] # caught an incorrect value if task == None: self.session_attributes = self.session_attributes card_title = "Invalid Task" speech_output = "We could not understand your exercise. Could you please repeat?" should_end_session = False return helper.build_response( self.session_attributes, helper.build_speechlet_response(card_title, speech_output, None, should_end_session)) # Store task preemptively to pass to pg.generate self.session_attributes['state']['task'] = task card_title = "Task Chosen" speech_output = pg.generate(self.session_attributes, 'specifying_a_task') reprompt_text = "I'm ready for your input." should_end_session = False # Assign the next state self.session_attributes['state'] = { 'value': 'attempt_task', 'task': task, 'word': self.word, 'sen': self.sen_complete, 'dfn': self.def_complete, 'syn': self.syn_complete } # Populate prev_state self.session_attributes = helper.dump_state(self.session_attributes) return helper.build_response( self.session_attributes, helper.build_speechlet_response(card_title, speech_output, reprompt_text, should_end_session))
def intent_task_specified(self, intent): resolution = intent['slots']['TASK']['resolutions']['resolutionsPerAuthority'][0] values = resolution['values'][0] task = values['value']['id'] # Store task preemptively to pass to pg.generate self.session_attributes['state']['task'] = task card_title = "Task Chosen" speech_output = pg.generate(self.session_attributes, 'specifying_a_task') reprompt_text = "I'm ready for your input." should_end_session = False # Assign the next state self.session_attributes['state'] = { 'value': 'attempt_task', 'task' : task, 'word' : self.word, 'sen' : '0', 'dfn' : '0', 'syn' : '0' } # Populate prev state self.session_attributes = helper.dump_state(self.session_attributes) return helper.build_response(self.session_attributes, helper.build_speechlet_response( card_title, speech_output, reprompt_text, should_end_session))
def intent_try_again(self): session_attributes = {} card_title = "Agree to Try Again" # Introduce the task attempt speech_output = pg.generate(self.session_attributes, 'agreeing_to_try_again') reprompt_text = "I'm ready for your input." should_end_session = False # Assign the next state self.session_attributes['state'] = { 'value': 'attempt_task', 'task': self.task, 'word': self.word, 'sen': self.sen_complete, 'dfn': self.def_complete, 'syn': self.syn_complete } # Populate prev_state self.session_attributes = helper.dump_state(self.session_attributes) return helper.build_response( self.session_attributes, helper.build_speechlet_response(card_title, speech_output, reprompt_text, should_end_session))
def basic_light(intent, session): slot = intent["slots"] my_state = "" if "State" in slot and "value" in slot["State"]: my_state = slot['State'] if "pcState" in slot and "value" in slot["pcState"]: my_state = slot['pcState'] my_state = my_state["value"] print(my_state) if my_state == "on" or my_state == "off": speech_output = "Light is now " + my_state reprompt_text = "Light is now " + my_state publish(my_state) elif my_state == "sleep" or my_state == "wake up": speech_output = "The pc is now " + my_state reprompt_text = "The pc is now " + my_state publish(my_state) else: speech_output = "Please try again." reprompt_text = "Please try again." return helper.build_response({}, helper.build_speechlet_response( intent['name'], speech_output, reprompt_text, True))
def intent_word_skipped(self, intent): #Get User data words = db.getUserData(self.userId) # Get a new word from the database word = db.get_random_word(self.userId) #update user info #db.addUserData(self.userId, word) # Assign that word to the state before passing to speech_output self.session_attributes['state']['word'] = word card_title = "Word Skipped" speech_output = pg.generate(self.session_attributes, 'skip_word') reprompt_text = "Is this word satisfactory?" should_end_session = False # Initialize the select word class self.session_attributes['state'] = { 'value': 'select_word', 'word': word } # Dump the state to prev_state self.session_attributes = helper.dump_state(self.session_attributes) return helper.build_response( self.session_attributes, helper.build_speechlet_response(card_title, speech_output, reprompt_text, should_end_session))
def intent_exit(self): card_title = "Session Ended" speech_output = pg.generate(self.session_attributes, 'stop') # Setting this to true ends the session and exits the skill. should_end_session = True return helper.build_response({}, helper.build_speechlet_response( card_title, speech_output, None, should_end_session))
def switch_light(intent, session): import lambda_function speech_output = "Light is switched" reprompt_text = "Light is switched" publish("switch") return helper.build_response({}, helper.build_speechlet_response( intent['name'], speech_output, reprompt_text, True))
def handle_session_end_request(): card_title = "Session Ended" speech_output = "" # Setting this to true ends the session and exits the skill. should_end_session = True return helper.build_response({}, helper.build_speechlet_response( card_title, speech_output, None, should_end_session))
def intent_help(self): card_title = "Help" speech_output = pg.generate(self.session_attributes, 'help') should_end_session = False self.session_attributes = self.session_attributes return helper.build_response( self.session_attributes, helper.build_speechlet_response(card_title, speech_output, None, should_end_session))
def intent_cancel(self): card_title = "Cancel" speech_output = "Bringing you back to the previous step" should_end_session = False # Go back to the last state self.session_attributes['state'] = self.session_attributes[ 'prev_state'] return helper.build_response( self.session_attributes, helper.build_speechlet_response(card_title, speech_output, None, should_end_session))
def get_welcome_response(): """ If we wanted to initialize the session to have some attributes we could add those here """ session_attributes = {} card_title = "Welcome" speech_output = "Indicates action." reprompt_text = "Indicates action." return helper.build_response( session_attributes, helper.build_speechlet_response(card_title, speech_output, reprompt_text, False))
def intent_help(self): card_title = "Repeat Tasks" speech_output = pg.generate(self.session_attributes, 'what_are_the_tasks') should_end_session = False # Stay in state self.session_attributes = self.session_attributes return helper.build_response( self.session_attributes, helper.build_speechlet_response(card_title, speech_output, None, should_end_session))
def intent_unhandled(self): card_title = "Unhandled Intent" speech_output = ( "We weren't able to understand what you were saying. " + "Would you mind saying it another way?") reprompt_text = ( "We still weren't able to understand what you were saying. " + "Please say it another way.") should_end_session = False return helper.build_response( self.session_attributes, helper.build_speechlet_response(card_title, speech_output, reprompt_text, should_end_session))
def intent_help(self): example = db.get_word_info(self.word)[self.task][0] card_title = "Example" # Just use the value in the database speech_output = pg.generate(self.session_attributes, 'give_an_example_answer', example) should_end_session = False # Stay in state self.session_attributes = self.session_attributes return helper.build_response(self.session_attributes, helper.build_speechlet_response( card_title, speech_output, None, should_end_session))
def intent_word_confirmed(self, intent): card_title = "Word Confirmed" speech_output = pg.generate(self.session_attributes, 'confirming_word') reprompt_text = "Please select a task." should_end_session = False # Assign the next state self.session_attributes['state'] = { 'value': 'select_task', 'word' : self.word, 'sen' : '0', 'dfn' : '0', 'syn' : '0' } # Populate prev_state self.session_attributes = helper.dump_state(self.session_attributes) return helper.build_response(self.session_attributes, helper.build_speechlet_response( card_title, speech_output, reprompt_text, should_end_session))
def intent_unhandled(self): card_title = "Try Again" speech_output = pg.generate(self.session_attributes, 'try_again') reprompt_text = "Would you like to try again?" should_end_session = False # Assign the next state self.session_attributes['state'] = { 'value': 'try_again', 'task' : self.task, 'word' : self.word, 'sen' : self.sen_complete, 'dfn' : self.def_complete, 'syn' : self.syn_complete } # Dump the state to prev_state self.session_attributes = helper.dump_state(self.session_attributes) return helper.build_response(self.session_attributes, helper.build_speechlet_response( card_title, speech_output, reprompt_text, should_end_session))
def intent_next_task(self): card_title = "Next Task after Fail" # Just use the value in the database speech_output = pg.generate(self.session_attributes, 'go_to_next_task') should_end_session = False # Assign the next state self.session_attributes['state'] = { 'value': 'select_task', 'word': self.word, 'sen': self.sen_complete, 'dfn': self.def_complete, 'syn': self.syn_complete } # Dump the state to prev_state self.session_attributes = helper.dump_state(self.session_attributes) return helper.build_response( self.session_attributes, helper.build_speechlet_response(card_title, speech_output, None, should_end_session))
def intent_verify(self, intent): # Get the answer from the intent answer = intent['slots']['ANSWER']['value'] # Query the database for the correct answer set query = db.get_word_info(self.word) # Set the query to the value for this task query_task = query[self.task] # Set the query_syn to the synonym list of the word query_syn = query['syn'] # Call the verification function with this info success = True try: verifier = Verification(self.word, query_syn, answer, query_task) if self.task == 'syn': success = verifier.synonym() if self.task == 'exa': success = verifier.sample() if self.task == 'def': success = verifier.definition() except: success = True self.session_attributes = self.session_attributes card_title = "" speech_output = "" should_end_session = False if (success): # Set the task as completed if (self.task == "syn"): self.syn_complete = '1' elif (self.task == "def"): self.def_complete = '1' else: self.sen_complete = '1' # Check to see if all tasks are completed if (self.sen_complete == '1' and self.def_complete == '1' and self.syn_complete == '1'): #Get User data words = (db.getUserData(self.userId)) # Get a new word from the database self.word = db.get_random_word(self.userId) #update user info #db.addUserData(self.userId, self.word) # Update the word for the session attributes self.session_attributes['state']['word'] = self.word card_title = "Tasks Complete" speech_output = pg.generate(self.session_attributes, 'tasks_complete') reprompt_text = "Is this word satisfactory?" # Initialize the select word class self.session_attributes['state'] = { 'value': 'select_word', 'word' : self.word } # Dump the state to prev_state self.session_attributes = helper.dump_state(self.session_attributes) # Move on to the next task for this word else: card_title = "Next Task" speech_output = pg.generate(self.session_attributes, 'next_task') reprompt_text = "Please choose a new task for this word." # Assign the next state self.session_attributes['state'] = { 'value': 'select_task', 'word' : self.word, 'sen' : self.sen_complete, 'dfn' : self.def_complete, 'syn' : self.syn_complete } # Dump the state to prev_state self.session_attributes = helper.dump_state(self.session_attributes) # Prompt the user to try again else: card_title = "Try Again" speech_output = pg.generate(self.session_attributes, 'try_again') reprompt_text = "Would you like to try again?" # Assign the next state self.session_attributes['state'] = { 'value': 'try_again', 'task' : self.task, 'word' : self.word, 'sen' : self.sen_complete, 'dfn' : self.def_complete, 'syn' : self.syn_complete } # Dump the state to prev_state self.session_attributes = helper.dump_state(self.session_attributes) # Return return helper.build_response(self.session_attributes, helper.build_speechlet_response( card_title, speech_output, reprompt_text, should_end_session))