javascript - Alexa Skill - 如何进行语音密码验证?
问题描述
我是 Alexa 技能开发的新手。我正在尝试创建语音密码验证。
这就是我想要实现的目标:
用户:“开灯”
Alexa:“你的安全密码是什么?”
用户:“6456”(错误的引脚)
Alexa:“身份验证失败!请重试。”
用户:“1234”(正确的引脚)
Alexa:“开灯!”
如果用户第一次告诉了正确的 pin 没有问题,但是如果用户第一次告诉了错误的 pin Alexa 只是说 repromppt 消息并且没有采用新的 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 话语映射。因此,当您第二次尝试使用实际引脚时,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
提示中。
推荐阅读
- javascript - 向动态创建的 HTML 表添加新行
- sqlite - Ionic3 和 SQLite - 在查询中使用属性作为表名创建表
- javascript - 允许值 -9999 到 9999 的文本框
- django - django celery 无法启动工人
- python - 如何在 Python 中获取导入文件的路径(如果 __name__ == __main__ 和 Pytest)
- python - Python随机数学的测验生成器程序,需要调整
- android - How can BroadcastReceiver communicate with Service when ReceiverRestrictedContext cannot be cast to MyService?
- angular - Ionic 3 事件发射器性能
- django - 如何更改密码重置表单的页面标题?
- c# - C# 有一个无效的 SelectedIndex,因为它不存在于项目列表中