'Trouble generating an Intent with delegateDirective from a TouchEvent handler (Alexa)

I need to confirm deleting a task from a button event. For this reason, I want Alexa to ask for confirmation, and therefore I need to generate a DeleteTaskIntent from my code.

I have tried this:

return handlerInput.responseBuilder.addDelegateDirective({
    name: 'DeleteTaskIntent',
    confirmationStatus: 'NONE',
    slots: {
        idTask:{
            name: 'idTask',
            value: idTask,
            confirmationStatus: 'NONE'
        }
    }

}).getResponse();

In my TouchEventHandler, but after checking the request in the requestEnvelope, I see this:

request: {
    type: 'System.ExceptionEncountered',
    requestId: 'amzn1.echo-api.request.9c2cf5f4-2f2c-419c-898c-05bd5f096810',
    timestamp: '2022-02-23T11:30:08Z',
    locale: 'es-ES',
    error: {
      type: 'INVALID_RESPONSE',
      message: 'Directive "Dialog.Delegate" cannot be used in response to an event'
    },
    cause: {
      requestId: 'amzn1.echo-api.request.0494d80d-c6ac-41d6-b3a2-dffd97f427b5'
    }
}

And the error

{
    "name": "AskSdk.GenericRequestDispatcher Error"
}

also appears, which suggests that no handler can handle this case.

Any idea about what I'm doing wrong when trying to generate the Intent?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source