简体   繁体   English

Alexa Skill - 如何进行语音密码验证?

[英]Alexa Skill - How to make a voice pin authentication?

I'm new to Alexa skill development.我是 Alexa 技能开发的新手。 I'm trying to create a voice pin authentication.我正在尝试创建语音 pin 身份验证。

This is what I'm trying to achieve:这就是我想要实现的目标:

User: "Turn ON the light"用户:“开灯”

Alexa: "What is your security pin?" Alexa:“你的安全密码是什么?”

User: "6456" (Wrong pin)用户:“6456”(引脚错误)

Alexa: "Authentication failed! Please try again." Alexa:“身份验证失败!请重试。”

User: "1234" (Correct pin)用户:“1234”(正确的引脚)

Alexa: "Turning ON the light!" Alexa:“开灯!”

If the user tells the correct pin the first time there is no issue, but if the user tells a wrong pin the first time Alexa just says the reprompt message and doesn't take the new pin value, how will I get the new pin value and check that pin once again in the same intent handler?如果用户第一次告诉正确的 pin 没有问题,但是如果用户第一次告诉错误的 pin Alexa 只是说重新提示消息并且不接受新的 pin 值,我将如何获得新的 pin 值并在同一个意图处理程序中再次检查该引脚?

This is my code:这是我的代码:

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

The problem is your RemoteControlIntent is not mapped with pin utterance.问题是您的RemoteControlIntent没有映射到 pin 话语。 so, when you tries with actual pin second time alexa does not know with which intent it should be mapped.因此,当您第二次尝试使用实际 pin 时,alexa 不知道它应该映射到哪个意图。

You need a way to again execute RemoteControlIntent with the actual pin.您需要一种使用实际引脚再次执行RemoteControlIntent的方法。

It would require your intent schema to properly solve the problem, but here is a solution that will work它需要你的意图模式来正确解决问题,但这里有一个可行的解决方案

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

Remeber to enable auto delegation for RemoteControlIntent and use What is your security pin?记得为RemoteControlIntent启用自动委派并使用您的安全密码是什么? in the securityPin prompt.securityPin提示中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM