Как получить значение слота намерения, сводить меня с ума - PullRequest
0 голосов
/ 04 июля 2019

Я просто хочу восстановить значение слота в коде, я хочу попробовать сделать простой навык, который реагирует по-разному в зависимости от дня, когда говорят пользователи.

Это мой пример кода, я пытаюсь в пустом проекте, чтобы не было другой проблемы.

Цель - "HelloWorldIntent", слот - "день"

JSON:

{
    "interactionModel": {
        "languageModel": {
            "invocationName": "try",
            "intents": [
                {
                    "name": "AMAZON.CancelIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.HelpIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.StopIntent",
                    "samples": []
                },
                {
                    "name": "HelloWorldIntent",
                    "slots": [
                        {
                            "name": "day",
                            "type": "AMAZON.DayOfWeek"
                        }
                    ],
                    "samples": [
                        "good {day}",
                        "hello",
                        "how are you",
                        "say hi world",
                        "say hi",
                        "hi",
                        "say hello world",
                        "say hello"
                    ]
                },
                {
                    "name": "AMAZON.NavigateHomeIntent",
                    "samples": []
                }
            ],
            "types": []
        }
    }
}

index.js:

const HelloWorldIntentHandler = {
    canHandle(handlerInput) {
        return handlerInput.requestEnvelope.request.type === 'IntentRequest'
            && handlerInput.requestEnvelope.request.intent.name === 'HelloWorldIntent';
    },
    handle(handlerInput) {
        var app = this.event.request.intent.slots.day.value;
        const speechText = app;
        return handlerInput.responseBuilder
            .speak(speechText)
            //.reprompt('add a reprompt if you want to keep the session open for the user to respond')
            .getResponse();
    }
};

Когда я спрашиваю добрый понедельник (или любой другой день), результат извинит, я не мог понять, что вы сказали.Пожалуйста, попробуйте еще раз.

Есть предложения?

1 Ответ

0 голосов
/ 05 июля 2019

Это ваша проблема:

var app = this.event.request.intent.slots.day.value;

Это похоже на код для v1 SDK.

Похоже, что вы на самом деле используете v2 - если у вас самая последняя версия, чтобы получить значение слота, вы можете сделать это:

// Require the SDK at the top of your file

const Alexa = require('ask-sdk');
// Then in your handle function where you want the slot value

handle (handlerInput) {
  const { requestEnvelope } = handlerInput;

  const speechText = Alexa.getSlotValue(requestEnvelope, 'day');

  return handlerInput.responseBuilder.speak(speechText).getResponse();
}

Кроме того, вы также можете получить это так:

const speechText = handlerInput.requestEnvelope.request.intent.slots['day'].value

Запрос конверта Utils - ASK SDK v2

...