Alexa Node JS:使用 Dialog.Delegate 并且对话状态不会更改为“完成”

Alexa Node JS: Using Dialog.Delegate and dialog state won't change to COMPLETE

我能在这里找到的最接近的问题:

但解决方案是将 Dialog.Delegate 发送到 Alexa Skill,我已经在这样做了。

我了解到技能测试存在潜在错误,因此我在 Echosim 和 Alexa 应用程序上进行了尝试,但无济于事。

下面是我的代码,后面是在 Lambda 控制台中测试生成的 JSON 响应。

我好像赶不上--console.log("You've made it in the else statement containing the switches")--

此外,我希望 --console.log("Current dialog state before switches" + request.dialogState);-- 打印两次,因为我有两个插槽要填充,但它只在控制台中显示一次。

提前致谢。

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();
 }
 },
};

这是我的 JSON 回复:

Response:
{
  "version": "1.0",
  "response": {
    "directives": [
      {
        "type": "Dialog.Delegate",
        "updatedIntent": {
          "name": "HobbyIntent",
          "confirmationStatus": "NONE",
          "slots": {
            "hobbyType": {
              "name": "hobbyType",
              "value": "general",
              "resolutions": {
                "resolutionsPerAuthority": [
                  {
                    "authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.a0b76b45-13ff-4be6-aff3-5b9bf60068d1.hobbieType",
                    "status": {
                      "code": "ER_SUCCESS_MATCH"
                    },
                    "values": [
                      {
                        "value": {
                          "name": "general",
                          "id": "958153f1b8b96ec4c4eb2147429105d9"
                        }
                      }
                    ]
                  }
                ]
              },
              "confirmationStatus": "NONE",
              "source": "USER"
            },
            "hobbyLocation": {
              "name": "hobbyLocation",
              "value": "indoors",
              "resolutions": {
                "resolutionsPerAuthority": [
                  {
                    "authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.a0b76b45-13ff-4be6-aff3-5b9bf60068d1.hobbyLocation",
                    "status": {
                      "code": "ER_SUCCESS_MATCH"
                    },
                    "values": [
                      {
                        "value": {
                          "name": "indoor",
                          "id": "b276393840653779e270ecb76ba4db12"
                        }
                      }
                    ]
                  }
                ]
              },
              "confirmationStatus": "NONE",
              "source": "USER"
            }
          }
        }
      }
    ]
  },
  "userAgent": "ask-node/2.3.0 Node/v8.10.0",
  "sessionAttributes": {}
}

Request ID:
"eafe99b7-f994-11e8-8fcf-dfe94cfc1e14"

Function Logs:
START RequestId: eafe99b7-f994-11e8-8fcf-dfe94cfc1e14 Version: $LATEST
2018-12-06T20:24:23.009Z    eafe99b7-f994-11e8-8fcf-dfe94cfc1e14    Current dialog state before switchesIN_PROGRESS
END RequestId: eafe99b7-f994-11e8-8fcf-dfe94cfc1e14
REPORT RequestId: eafe99b7-f994-11e8-8fcf-dfe94cfc1e14  Duration: 95.26 ms  Billed Duration: 100 ms     Memory Size: 128 MB Max Memory Used: 21 MB  

一旦我注释掉 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{