[英]Alexa Skill - How to make a voice pin authentication?
我是 Alexa 技能開發的新手。 我正在嘗試創建語音 pin 身份驗證。
這就是我想要實現的目標:
用戶:“開燈”
Alexa:“你的安全密碼是什么?”
用戶:“6456”(引腳錯誤)
Alexa:“身份驗證失敗!請重試。”
用戶:“1234”(正確的引腳)
Alexa:“開燈!”
如果用戶第一次告訴正確的 pin 沒有問題,但是如果用戶第一次告訴錯誤的 pin Alexa 只是說重新提示消息並且不接受新的 pin 值,我將如何獲得新的 pin 值並在同一個意圖處理程序中再次檢查該引腳?
這是我的代碼:
const RemoteControlIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& 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();
}
}
問題是您的RemoteControlIntent
沒有映射到 pin 話語。 因此,當您第二次嘗試使用實際 pin 時,alexa 不知道它應該映射到哪個意圖。
您需要一種使用實際引腳再次執行RemoteControlIntent
的方法。
它需要你的意圖模式來正確解決問題,但這里有一個可行的解決方案
const RemoteControlIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& 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
啟用自動委派並使用您的安全密碼是什么? 在securityPin
提示中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.