问题
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.
回答1:
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
回答2:
In nodejs you can use
if (this.event.request.dialogState != 'COMPLETED'){
//your logic
this.emit(':delegate');
} else {
this.response.speak(message);
this.emit(':responseReady');
}
回答3:
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');
}
}
来源:https://stackoverflow.com/questions/51723671/how-to-return-dialog-delegate-directive-to-alexa-skill-model