I have attempted to create a custom slot (called 'poll_response') that accepts only values in the given set ("Yes","No", etc.). The dialog delegation begins correctly; the required slot is prompted for, and if you give a valid response it works as expected. However, if you give an invalid response, the original prompt (not the error message prompt) is said again. If you give another incorrect response there is silence.
Here's an example of output:
And here are the settings for the slot:
And here is the relevant code:
class VoteIntentHandler(AbstractRequestHandler): """Called when a user says 'vote now'. Gets the first poll from the list of unanswered polls and asks it. Puts this poll in the current_poll attribute of the response.""" def can_handle(self, handler_input): # type: (HandlerInput) -> bool return ask_utils.is_intent_name("VoteIntent")(handler_input) def handle(self, handler_input): # get the list of polls for the current session polls = get_session_attr(handler_input, "unanswered_polls") # default message speak_output = "Unable to find an unanswered poll. Now exiting." done = True # if there are polls to take # this shouldn't ever be true as this is checked in LaunchRequest # remove? if polls and len(polls) > 0: poll = polls.pop(0) speak_output = "Ok. Here's your poll. " speak_output = append_poll_options(poll, speak_output) done = False # create response to point to the Response intnent handler_input.attributes_manager.session_attributes['unanswered_polls'] = polls handler_input.attributes_manager.session_attributes['current_poll'] = poll directive = DelegateDirective(updated_intent='ResponseIntent') return ( handler_input.response_builder .speak(speak_output) .add_directive(directive) .set_should_end_session(done) .response ) class ResponseIntentHandler(AbstractRequestHandler): """Attached to this intent is the required slot for the poll_response. This poll_response is added to the database, and the results of the poll are given to the user.""" def can_handle(self, handler_input): # type: (HandlerInput) -> bool return ask_utils.is_intent_name("ResponseIntent")(handler_input) def handle(self, handler_input): speak_output = "There was an error with your response. Exiting" done = True # check the response against the current poll poll_response = get_slot(handler_input, "poll_response") poll = get_session_attr(handler_input, 'current_poll') valid = check_valid_response(poll, poll_response) # this validity check will be unnecessary if the validation is working if valid: speak_output = "Your vote has been submitted. " # add the response to the database user_id = get_user_id(handler_input) add_response(user_id, poll_response, poll) # add the results to the output speak_output = append_tally(poll,speak_output) # check if they have more polls they can take unanswered_polls = get_session_attr(handler_input, 'unanswered_polls') if unanswered_polls and (len(unanswered_polls) > 0): speak_output += "If you would like to take another poll, say vote now. Otherwise say exit." done = False else: speak_output += "You have taken all unanswered polls, exiting." done = True return ( handler_input.response_builder .speak(speak_output) .set_should_end_session(done) .response )
Any ideas as to why the reprompt is not being activated?