How to return Dialog.Delegate directive to Alexa Skill model?
Asked Answered
A

3

5

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.

Astraddle answered 7/8, 2018 at 9:44 Comment(0)
P
13

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

Pakistan answered 7/8, 2018 at 10:21 Comment(3)
Perfect, thank you. I struggled with the alexa documentation, this was very helpful.Astraddle
@Cicil I would recommend you add how to get the currentIntent for referenceAgue
const currentIntent = handlerInput.requestEnvelope.request.intentAgue
B
5

In nodejs you can use

if (this.event.request.dialogState != 'COMPLETED'){
    //your logic
    this.emit(':delegate');
} else {
     this.response.speak(message);
     this.emit(':responseReady');
}
Beutler answered 7/8, 2018 at 11:36 Comment(2)
Thank you, that helped to get a grip of the mechanics at work.Astraddle
this is v1 code. the answer from Cicil uses v2 so it's preferableAgue
M
4

In nodeJS we can check the dialogState and act accordingly.

if (this.event.request.dialogState === 'STARTED') {
      let updatedIntent = this.event.request.intent;
      this.emit(':delegate', updatedIntent);
} else if (this.event.request.dialogState != 'COMPLETED'){
     if(//logic to elicit slot if any){
          this.emit(':elicitSlot', slotToElicit, speechOutput, repromptSpeech);
     } else {
          this.emit(':delegate');
     }
} else {
     if(this.event.request.intent.confirmationStatus == 'CONFIRMED'){
           //logic for message
           this.response.speak(message);
           this.emit(':responseReady');
     }else{
           this.response.speak("Sure, I will not create any new service request");
           this.emit(':responseReady');
     }
}
Melody answered 7/8, 2018 at 11:43 Comment(1)
Thank you for providing the code snippet. I went with another solution but it helped a lot to understand this elicitSlot functionality.Astraddle

© 2022 - 2024 — McMap. All rights reserved.