我可以在这里找到最近的问题:
Alexa Dialog Model Step and dialogState is never in COMPLETED
但是解决方案是将Dialog.Delegate发送给我已经在做的Alexa Skill。
我读到,技能测试可能存在错误,因此我在Echosim和Alexa App上尝试了此操作,但没有成功。
下面是我的代码,然后是Lambda控制台中的测试生成的JSON响应。
我似乎无法做到---- this.state.drag.getLayout()
-
此外,我希望-console.log("You've made it in the else statement containing the switches")
-可以打印两次,因为我要填充两个插槽,但是在控制台中只显示一次。
谢谢。
console.log("Current dialog state before switches" + request.dialogState);
这是我的JSON响应:
const HobbyIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'HobbyIntent';
},
handle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
const responseBuilder = handlerInput.responseBuilder;
const currentIntent = request.intent;
if (request.dialogState !== 'COMPLETED'){
//const speechText = 'Would you like your hobby to be general,
competetive, observational, or do you want to collect something?';
console.log("Current dialog state before switches" + request.dialogState);
return handlerInput.responseBuilder
.addDelegateDirective(currentIntent)
.getResponse();
} else{
console.log("You've made it in the else statement containing the
switches")
const speechText = '';
var randomHobby = '';
console.log("Here are the current slots' contents: " + currentIntent.slots)
if (currentIntent.slots.hobbyType && currentIntent.slots.hobbyLocation){
var typeOfHobby = currentIntent.slots.hobbyType.resolutions.resolutionsPerAuthority[0].values[0].value.name;
var locationOfHobby = currentIntent.slots.hobbyLocation.resolutions.resolutionsPerAuthority[0].values[0].value.name;
switch(typeOfHobby){
case "competetive":
typeOfHobby = "CompetetiveHobbies";
break;
case "collection":
typeOfHobby = "CollectionHobbies";
break;
case "observational":
typeOfHobby = "ObservationalHobbies";
break;
default:
typeOfHobby = "GeneralHobbies"
break;
}
switch(locationOfHobby){
case "indoor":
locationOfHobby = "Indoors";
break;
case "outdoor":
locationOfHobby = "Outdoors";
break;
default:
return handlerInput.responseBuilder
.speak("I don't know any hobbies like that. Please try again.")
.addDelegateDirective(currentIntent)
.getResponse();
}
//randomHobby =
Hobbies.typeOfHobby.locationOfHobby[Math.floor(Math.random() *
Hobbies.typeOfHobby.locationOfHobby.length)];
//speechText = `You should definitely do ${randomHobby}`;
speechText = "you have reached the point after the switch statements"
} // end if for slot-matching
else{
speechText = "Something went wrong with the slots"
}
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.withSimpleCard('Hello World', speechText)
.getResponse();
}
},
};
答案 0 :(得分:0)
一旦我注释掉if (request.dialogState !== COMPLETED
,并在委派是否未满的情况下手动检查每个插槽,它就会起作用。
handle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
const responseBuilder = handlerInput.responseBuilder;
const currentIntent = request.intent;
let slots = currentIntent.slots;
//if (request.dialogState !== 'COMPLETED'){ ------------ this will not work for some reason
if(!(slots.hobbyType.value)){
return handlerInput.responseBuilder
.addDelegateDirective(currentIntent)
.getResponse()
}else if(!(slots.hobbyLocation.value)){
return handlerInput.responseBuilder
.addDelegateDirective(currentIntent)
.getResponse()
}else{