How to regain control after dialogState == COMPLETED, Alexa delegateDialog

117 Views Asked by At

I have a dialog that works correctly, I delegate this dialog to Alexa for the intent BeginDiagnosisIntent which prompts the user to fill the slot values for age and gender, which are slots of BeginDiagnosisIntent. However, when the last slot value is filled and dialogState == "COMPLETED", instead of being caught by the handler for intent BeginDiagnosisIntent and then I perform the behavior that I intended to perform, with the given slot values filled. The response is caught by the ErrorHandler and an error is thrown.

How can I control the dialog such that when dialogState is COMPLETED, I am able to perform the functionality that I wish to perform with the given slots filled?

{
  "interactionModel": {
    "languageModel": {
      "invocationName": "diagnose",
      "intents": [
        {
          "name": "BeginDiagnosisIntent",
          "slots": [
            {
              "name": "age",
              "type": "AMAZON.NUMBER"
            },
            {
              "name": "gender",
              "type": "GENDER"
            }
          ],
          "samples": [
            "{age}",
            "I am {age}",
            "I'm {age}",
            "I am {age} years",
            "I'm {age} years",
            "I am {age} years old",
            "I'm {age} years old",
            "I was born {age} years ago",
            "I am the old age of {age}",
            "I am the ripe old age of {age}",
            "I am {gender}"
          ]
        },
        {
          "name": "AMAZON.RepeatIntent"
        },
        {
          "name": "AMAZON.HelpIntent"
        },
        {
          "name": "AMAZON.StopIntent"
        },
        {
          "name": "AMAZON.CancelIntent"
        }
      ],
      "types": [
        {
          "name": "GENDER",
          "values": [
            {
              "name": {
                "value": "female",
                "synonyms": [
                  "girl",
                  "woman"
                ]
              }
            },
            {
              "name": {
                "value": "male",
                "synonyms": [
                  "boy",
                  "man"
                ]
              }
            }
          ]
        }
      ]
    },
    "dialog": {
      "delegationStrategy": "ALWAYS",
      "intents": [
        {
          "name": "BeginDiagnosisIntent",
          "prompts": {},
          "slots": [
            {
              "name": "age",
              "type": "AMAZON.NUMBER",
              "confirmationRequired": false,
              "elicitationRequired": true,
              "prompts": {
                "elicitation": "Elicit.Slot.1323207333291.854898796228"
              }
            },
            {
              "name": "gender",
              "type": "GENDER",
              "confirmationRequired": false,
              "elicitationRequired": true,
              "prompts": {
                "elicitation": "Elicit.Slot.1323207333291.563366041005"
              }
            }
          ]
        }
      ]
    },
    "prompts": [
      {
        "id": "Elicit.Slot.1323207333291.854898796228",
        "variations": [
          {
            "type": "PlainText",
            "value": "How old are you?"
          }
        ]
      },
      {
        "id": "Elicit.Slot.1323207333291.563366041005",
        "variations": [
          {
            "type": "PlainText",
            "value": "Are you male of female?"
          }
        ]
      }
    ]
  }
}

In the launchHandler, I delegate the dialog to BeginDiagnosisIntent. I then wish for Alexa to handle this dialog, and then when the slots are filled, I can continue from BeginDiagnosisIntentHandler. However, when the dialogState is COMPLETED. My error handler catches the response. Why does this happen? How can I regain the context after the dialog is completed?

public class LaunchHandler implements LaunchRequestHandler {

    @Override
    public boolean canHandle(HandlerInput handlerInput, LaunchRequest launchRequest) {
        return true;
    }

    @Override
    public Optional<Response> handle(HandlerInput handlerInput, LaunchRequest launchRequest) {
        Intent chainedIntent = Intent.builder().withName("BeginDiagnosisIntent").build();
        return handlerInput.getResponseBuilder()
                .addDelegateDirective(chainedIntent)
                .build();
    }
}


public class BeginDiagnosisIntentHandler implements IntentRequestHandler {

    @Override
    public boolean canHandle(HandlerInput input, IntentRequest intentRequest) {
        return intentRequest.getIntent().getName().equals("BeginDiagnosisIntent");
    }

    @Override
    public Optional<Response> handle(HandlerInput handlerInput, IntentRequest intentRequest) {
        Intent currentIntent = intentRequest.getIntent();

        if (intentRequest.getDialogState().equals("COMPLETED")) {
            return handlerInput.getResponseBuilder()
                    .withSpeech("I have all the information I need.")
                    .build();
        } else {
                return handlerInput.getResponseBuilder()
                        .addDelegateDirective(currentIntent)
                        .build();
        }

    }

}
0

There are 0 best solutions below