question

duffrecords avatar image
duffrecords asked

call handler from another handler in Python SDK

I'm trying to write handlers for the AMAZON.YesIntent and AMAZON.NoIntent that will call one of several custom intents depending on session attributes. In the logs, it looks like the secondary intent is being invoked but it aborts with this NotImplementedError:

Traceback (most recent call last):
File "/opt/python/ask_sdk_runtime/dispatch.py", line 118, in dispatch
output = self.__dispatch_request(handler_input)
File "/opt/python/ask_sdk_runtime/dispatch.py", line 183, in __dispatch_request
handler_input=handler_input, handler=request_handler)
File "/opt/python/ask_sdk_runtime/dispatch_components/request_components.py", line 433, in execute
return handler.handle(handler_input)
File "/opt/python/ask_sdk_core/dispatch_components/request_components.py", line 69, in handle
raise NotImplementedErrorNotImplementedError

The code in question looks something like this:

class YesIntent(AbstractRequestHandler):
    def can_handle(self, handler_input):
        return is_intent_name("AMAZON.YesIntent")(handler_input)

    def handle(self, handler_input):
        session_attr = handler_input.attributes_manager.session_attributes
        if session_attr["game_state"] == "play again":
            handler_input.request_envelope.request.intent.name = "StartGame"
            second_handler = StartGameIntentHandler()
        elif session_attr["game_state"] == "next question":
            handler_input.request_envelope.request.intent.name = "NextQuestion"
            second_handler = NextQuestionIntentHandler()
        return second_handler.handle(handler_input)


class StartGameIntentHandler(AbstractRequestHandler):
    # code omitted here


class NextQuestionIntentHandler(AbstractRequestHandler):
    # code omitted here

Is this possible or should I handle the "yes" and "no" utterances as part of other intents, delegating the dialog to Alexa or eliciting slots?

alexa skills kitintentspythondialog directivesdk v2
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

duffrecords avatar image
duffrecords answered

I think I know what the problem is. The StartGame intent uses the ElicitSlotDirective to prompt the user for the answer to a question. Control then returns to the AMAZON.YesIntent, which has no slots nor can it include any. The SessionEndedRequest contains the following message:

A valid slot of the intent being should be specified for slotToElicit "Dialog.ElicitSlot" directive
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

duffrecords avatar image
duffrecords answered

I ended up creating my own custom YesIntent that contains the same slot required by the StartGame intent, but in the YesIntent the slot is optional and is not present in any of the sample utterances.

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.