Search code examples
node.jsaws-lambdaalexa-skills-kitalexa-slot

How to return Dialog.Delegate directive to Alexa Skill model?


I want to create a simple multi-turn dialog with the Alexa Skill model. My intent consists of 3 slots, each of which are required to fulfill the intent. I prompt every slot and defined all of the needed utterances.

Now I want to handle the request with a Lambda function. This is my function for this specific Intent:

function getData(intentRequest, session, callback) {
    if (intentRequest.dialogState != "COMPLETED"){
        // return a Dialog.Delegate directive with no updatedIntent property.
    } else {
        // do my thing
    }
}

So how would I go on to build my response with the Dialog.Delegate directive, as mentioned in the Alexa documentation?

https://developer.amazon.com/docs/custom-skills/dialog-interface-reference.html#scenario-delegate

Thank you in advance.


Solution

  • With Dialog.Delegate directive you cannot send outputSpeech or reprompt from your code. Instead those defined in interaction model will be used.

    Do not include outputSpeech or reprompt with the Dialog.Directive. Alexa uses the prompts defined in the dialog model to ask the user for the slot values and confirmations.

    What this means is that you cannot delegate and provide your own response, but instead you can use any other Dialog directive to provide your outputSpeech and reprompt.

    Ex: Dialog.ElicitSlot, Dialog.ConfirmSlot and Dialog.ConfirmIntent.

    At any point, you can take over the dialog rather than continuing to delegate to Alexa.

    ...
        const updatedIntent = handlerInput.requestEnvelope.request.intent;
        if (intentRequest.dialogState != "COMPLETED"){
           return handlerInput.responseBuilder
                  .addDelegateDirective(updatedIntent)
                  .getResponse();
        } else {
            // Once dialoState is completed, do your thing.
            return handlerInput.responseBuilder
                  .speak(speechOutput)
                  .reprompt(reprompt)
                  .getResponse();
        }
    ...
    

    The updatedIntent parameter in addDelegateDirective() is optional. It is an intent object representing the intent sent to your skill. You can use this property set or change slot values and confirmation status if necessary.

    More on Dialog directives here