Намерение ConfirmationStatus не может быть изменено с помощью директивы Dialog.Delegate - PullRequest
0 голосов
/ 24 января 2020

У меня есть диалог, в котором я делегирую Alexa, чтобы собрать два слота и запросить подтверждение. Если пользователь говорит «нет» в ответ на запрос подтверждения, я хочу перезапустить диалоговое окно, удалив значения слотов и установив для параметра translationStatus значение «NONE».

Пока Alexa начинает вызывать первый слот, статус подтверждения остается как «ОТКАЗ» , что приводит к значению al oop. Я использовал описанный здесь метод для сброса статуса.

Это обновленное намерение, отправленное обратно из моего навыка

{
  "name": "StartSingleGameIntent",
  "confirmationStatus": "NONE",
  "slots": {
    "player_one": {
      "name": "player_one",
      "confirmationStatus": "NONE",
      "source": "USER"
    },
    "player_two": {
      "name": "player_two",
      "confirmationStatus": "NONE",
      "source": "USER"
    }
  }
}

Но следующий запрос все еще имеет статус «ОТКАЗ»:

{
  "name": "StartSingleGameIntent",
  "confirmationStatus": "DENIED",
  "slots": {
    "player_one": {
      "name": "player_one",
      "value": "ben",
      "confirmationStatus": "NONE",
      "source": "USER"
    },
    "player_two": {
      "name": "player_two",
      "confirmationStatus": "NONE"
    }
  }
}

Вот мои обработчики:

const StartSingleGameStartedIntentHandler = {
  canHandle(handlerInput) {
    return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' &&
      Alexa.getIntentName(handlerInput.requestEnvelope) === 'StartGameIntent' &&
      Alexa.getDialogState(handlerInput.requestEnvelope) === 'STARTED';
  },
  handle(handlerInput) {
    return handlerInput.responseBuilder
             .addDelegateDirective(handlerInput.requestEnvelope.request.intent).getResponse();
  }
};
const StartSingleGameInProgressIntentHandler = {
  canHandle(handlerInput) {
    return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' &&
      Alexa.getIntentName(handlerInput.requestEnvelope) === 'StartGameIntent' &&
      Alexa.getDialogState(handlerInput.requestEnvelope) === 'IN_PROGRESS';
  },
  handle(handlerInput) {
    const currentIntent = handlerInput.requestEnvelope.request.intent;
    console.log("Dialog in progress %s", JSON.stringify(currentIntent));
    if (currentIntent.confirmationStatus === "DENIED") {
      let intent = handlerInput.requestEnvelope.request.intent;
      intent.confirmationStatus = "NONE";
      Object.keys(intent.slots).forEach(slotName => {
        const slot = intent.slots[slotName];
        delete slot.value;
      });
      console.log("New intent %s", JSON.stringify(intent));
      const speechText = "Ok, let's try again";
      return handlerInput.responseBuilder
        .speak(speechText)
        .addDirective({
          type: "Dialog.Delegate",
          updatedIntent: intent
        })
        .getResponse();

    }
    // if Intent is confirmed, delegate to complete dialog
    return handlerInput.responseBuilder.addDelegateDirective(currentIntent).getResponse();
  }
};
const StartSingleGameCompletedIntentHandler = {
  canHandle(handlerInput) {
    return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' &&
      Alexa.getIntentName(handlerInput.requestEnvelope) === 'StartGameIntent' &&
      Alexa.getDialogState(handlerInput.requestEnvelope) === 'COMPLETED';
  },
  handle(handlerInput) {
    console.log("Status COMPLETED");
    const currentIntent = handlerInput.requestEnvelope.request.intent;
    const playerOne = currentIntent.slots.player_one.value;
    const playerTwo = currentIntent.slots.player_two.value;
    const speech = 'Ok, ' + playerOne + ' versus ' + playerTwo + '!';
    return handlerInput.responseBuilder.speak(speech).withShouldEndSession(true).getResponse();
  }
};

А вот соответствующая часть из модели взаимодействия

{
  "interactionModel": {
    "languageModel": {
      "invocationName": "kicker tracker",
      "intents": [
        {
          "name": "StartSingleGameIntent",
          "slots": [
            {
              "name": "player_one",
              "type": "AMAZON.FirstName",
              "samples": [
                "{player_one}"
              ]
            },
            {
              "name": "player_two",
              "type": "AMAZON.FirstName",
              "samples": [
                "{player_two}"
              ]
            }
          ],
          "samples": [
            "{player_one} versus {player_two}",
            "{player_one} against {player_two}"
          ]
        }
      ],
      "types": []
    },
    "dialog": {
      "intents": [
        {
          "name": "StartGameIntent",
          "delegationStrategy": "SKILL_RESPONSE",
          "confirmationRequired": true,
          "prompts": {
            "confirmation": "Confirm.Intent.331442628749"
          },
          "slots": [
            {
              "name": "player_one",
              "type": "AMAZON.FirstName",
              "confirmationRequired": false,
              "elicitationRequired": true,
              "prompts": {
                "elicitation": "Elicit.Slot.1074854715089.1393950695631"
              }
            },
            {
              "name": "player_two",
              "type": "AMAZON.FirstName",
              "confirmationRequired": false,
              "elicitationRequired": true,
              "prompts": {
                "elicitation": "Elicit.Slot.1074854715089.404108193608"
              }
            }
          ]
        }
      ],
      "delegationStrategy": "ALWAYS"
    },
    "prompts": [
      {
        "id": "Elicit.Slot.1074854715089.1393950695631",
        "variations": [
          {
            "type": "PlainText",
            "value": "Who is the first player?"
          }
        ]
      },
      {
        "id": "Elicit.Slot.1074854715089.404108193608",
        "variations": [
          {
            "type": "PlainText",
            "value": "Who plays against {player_one} ?"
          }
        ]
      },
      {
        "id": "Confirm.Intent.331442628749",
        "variations": [
          {
            "type": "PlainText",
            "value": "{player_one} versus {player_two}, correct?"
          }
        ]
      }
    ]
  }
}
...