thedreamsaver
thedreamsaver

Reputation: 1384

How to use Intent Chaining with Intent Confirmation in Alexa?

I'm trying to mix dialog management and intent chaining. I have disabled auto delegation.

But I'm stuck at, When the user fills all the slot values and then I use intent confirmation and prompt him if the data is correct.

If the user says "No". I want to restart the dialog management for the same intent.

But the error I'm getting is, "Directive "Dialog.Delegate" can be used only when a dialog is active and hasn't been completed".

I tried replacing line 15 with some other intent, it works, but not when I send the directive for the same intent. Does anyone know what I'm missing?

const DeniedPostMessageIntentHandler = {
    canHandle(handlerInput) {
      return handlerInput.requestEnvelope.request.type === 'IntentRequest' &&
        handlerInput.requestEnvelope.request.intent.name === 'PostMessageIntent' &&
        handlerInput.requestEnvelope.request.dialogState === 'COMPLETED' &&
        handlerInput.requestEnvelope.request.intent.confirmationStatus === 'DENIED';
    },
    handle(handlerInput) {
        let speechText = ri('POST_MESSAGE.DENIED');
        return handlerInput.jrb
          .speak(speechText)
          .addDelegateDirective({
            name: 'PostMessageIntent',
            confirmationStatus: 'NONE',
            slots: {}
          })
          .getResponse();
    },
};

Upvotes: 3

Views: 1636

Answers (1)

thedreamsaver
thedreamsaver

Reputation: 1384

Note - I'm using dialog management with auto delegation disabled.

Alexa sends a request with dialogState = IN_PROGRESS and confirmationStatus = DENIED even before sending the same request with dialogState = COMPLETED and confirmationStatus = DENIED.

The error

"Directive "Dialog.Delegate" can be used only when a dialog is active and hasn't been completed"

kind of hints towards it, but one thing to note is that we can start the dialog delegation for a separate intent while in dialogState = COMPLETED but cannot do it for the same intent.

So if you want to restart the dialog for the same intent, when the intent confirmation is being denied then you have to do it while the dialogState is still IN_PROGRESS. If you want to handle intent confirmation being denied in any other way then you can also do it when dialogState is COMPLETED.

The solution for my above problem is simply changing the dialogState in canHandle function to IN_PROGRESS instead of COMPLETED.

canHandle(handlerInput) {
  return handlerInput.requestEnvelope.request.type === 'IntentRequest' &&
    handlerInput.requestEnvelope.request.intent.name === 'PostMessageIntent' &&
    handlerInput.requestEnvelope.request.dialogState === 'IN_PROGRESS' &&
    handlerInput.requestEnvelope.request.intent.confirmationStatus === 'DENIED';
}

Found this buried deep down in - https://forums.developer.amazon.com/comments/206243/view.html

Amazon should take note and add this in the documentation.

Upvotes: 1

Related Questions