#javascript #node.js #alexa #alexa-skills-kit #alexa-skill
#javascript #node.js #alexa #alexa-skills-kit #alexa-навык
Вопрос:
Я новичок в развитии навыков Alexa. Я пытаюсь создать аутентификацию с помощью голосового PIN-кода.
Это то, чего я пытаюсь достичь:
Пользователь: «Включите свет»
Алекса: «Какой у вас защитный PIN-код?»
Пользователь: «6456» (неправильный PIN-код)
Alexa: «Ошибка аутентификации! Пожалуйста, попробуйте еще раз. «
Пользователь: «1234» (правильный PIN-код)
Алекса: «Включаю свет!»
Если пользователь с первого раза вводит правильный pin-код, проблем нет, но если пользователь в первый раз вводит неправильный pin-код, Alexa просто произносит сообщение reprompt и не принимает новое значение pin-кода, как я получу новое значение pin-кода и проверю этот pin-код еще раз в том же обработчике намерений?
Это мой код:
const RemoteControlIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
amp;amp; Alexa.getIntentName(handlerInput.requestEnvelope) === 'RemoteControlIntent';
},
handle(handlerInput) {
var speakOutput = '';
var userPin = handlerInput.requestEnvelope.request.intent.slots.securityPin.value;
if (userPin !== userSecurityPin) {
speakOutput = 'Authentication Failed! Please retry!';
return handlerInput.responseBuilder
.speak(speakOutput)
.reprompt(speakOutput)
.getResponse();
} else {
speakOutput = 'Turning ON the light!';
return handlerInput.responseBuilder
.speak(speakOutput)
.reprompt('add a reprompt if you want to keep the session open for the user to respond')
.getResponse();
}
}
Комментарии:
1. Есть ли какое-либо другое намерение, содержащее только FOUR_DIGIT_NUMBER?
2. Какую ошибку вы получаете, когда указываете второй PIN-код?
Ответ №1:
Проблема в том, что ваш RemoteControlIntent
не сопоставлен с произнесением PIN-кода. итак, когда вы пытаетесь использовать фактический PIN-код во второй раз, alexa не знает, с каким намерением он должен быть сопоставлен.
Вам нужен способ повторного выполнения RemoteControlIntent
с фактическим PIN-кодом.
Для правильного решения проблемы потребуется ваша схема намерений, но вот решение, которое будет работать
const RemoteControlIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
amp;amp; Alexa.getIntentName(handlerInput.requestEnvelope) === 'RemoteControlIntent';
},
handle(handlerInput) {
var speakOutput = '';
var userPin =handlerInput.requestEnvelope.request.intent.slots.securityPin.value;
const request = handlerInput.requestEnvelope.request;
if (userPin !== userSecurityPin) {
speakOutput = 'Authentication Failed! Please retry!';
return handlerInput.responseBuilder
.speak(speakOutput)
.addElicitSlotDirective('securityPin') // this line will ask for the pin again against the same intent
.getResponse();
} else {
speakOutput = 'Turning ON the light!';
return handlerInput.responseBuilder
.speak(speakOutput)
.reprompt('add a reprompt if you want to keep the session open for the
user to respond')
.withShouldEndSession(true)
.getResponse();
}
}
};
Помните, чтобы включить автоматическое делегирование RemoteControlIntent
и использовать Какой у вас защитный PIN-код?в securityPin
приглашении.