node.js - 当我确认用户所说的内容时,为什么我的技能会转到我的错误处理程序?
问题描述
我正在制作一项使用 spotify api 的技能,如果有类似名称的结果,我会询问用户他们是否指的是那个人。
我的处理程序在识别名称不同时工作,但是在确认(用户说是)后,程序转到我的错误处理程序。
为什么是这样?我有点说不出话来。
这是我的启动处理程序和验证艺术家的处理程序:
{ //makes sure that the yes intent is called or the program is just starting
canHandle(handlerInput)
{
const attributes = handlerInput.attributesManager.getSessionAttributes();
return (Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest')|| Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'YesIntent'&& (attributes.done=== true ||attributes.err === true);
},
async handle(handlerInput)
{
const attributes = handlerInput.attributesManager.getSessionAttributes();
const response = handlerInput.responseBuilder;
var speakOutput = '';
//different dialog if program is being restarted
if(attributes.err === true|| attributes.done === true)
{
speakOutput = "Welcome back! Which artist do you want to try this time?"
}
else
{
speakOutput = 'Welcome to Song Match. I can help you understand which song by your favorite artist best matches your life. Please tell me the name of your favorite artist.';
}
//initalizing attributes
attributes.lastSaid = speakOutput;
attributes.counter = 0;
attributes.artist = '';
attributes.tempArtist = '';
attributes.a1 = true;
attributes.a2 = true;
attributes.a3 = true;
attributes.q1 = false
attributes.q2 = false;
attributes.q3 = false;
attributes.actor = '';
attributes.activity = '';
attributes.sports = '';
attributes.s = '';
attributes.songIds = [];
attributes.songNames = [];
attributes.albIds = new Array(10);
attributes.token = '';
attributes.id = '';
attributes.check = false;
attributes.q = false;
attributes.done = false;
attributes.err = false;
attributes.question= [
"would you rather be a fan of the Los Angeles Lakers or Clippers?","On a regular Friday night, would you rather watch netflix or go out?" ,
"Would you rather talk to Mark Wahlberg or Kevin Hart?"];
attributes.add = ["Well, Let me ask now,", "Ok,", "Interesting,","hmm,"];
return handlerInput.responseBuilder
.speak(speakOutput)
.reprompt(speakOutput)
.getResponse();
}
};
const FavoriteArtistIntentHandler =
{ //makes sure correct intent is being called
canHandle(handlerInput)
{//checks if FavoriteArtistIntent handler is called and that the questions haven't started yet
const attributes = handlerInput.attributesManager.getSessionAttributes();
const request = handlerInput.requestEnvelope.request;
return (Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& ((Alexa.getIntentName(handlerInput.requestEnvelope) === 'FavoriteArtistIntent')||Alexa.getIntentName(handlerInput.requestEnvelope) === 'YesIntent') && attributes.q === false) &&(attributes.done=== false &&attributes.err === false);
},
async handle(handlerInput)
{
//sets attributes.artist to the artist slot value and calls the getArtistId method to see if that artist is valid
const attributes = handlerInput.attributesManager.getSessionAttributes();
const artist = handlerInput.requestEnvelope.request.intent.slots.artist.value;
//const yes = handlerInput.requestEnvelope.request.intent.slots.yes.value;
attributes.artist = artist;
const response = handlerInput.responseBuilder;
var speakOutput = '';
var repromptOutput = '';
var capitalArtist = capitalizedArtist(handlerInput,attributes.artist);
//var capitalizedArtist = attributes.artist.charAt(0).toUpperCase() + attributes.artist.slice(1);
if(attributes.check === true)
{
attributes.artist = attributes.tempArtist;
capitalArtist= attributes.tempArtist;
}
};
解决方案
您可能需要重新访问 attributes.done 和 attributes.err。我没有看到您将其设置为 true。您的 canHandle 方法期望其中之一对于 Yes Intent 是正确的。
祝你好运 !
推荐阅读
- python - 有没有办法让 Discord 机器人使用 Discord.py 来回应提及特定用户?
- c# - 我应该如何向 WPF 窗口添加多个控件?
- r - 对于预测和标签,交叉验证运行次数的误差必须相等
- cmake - 我设置了 CMAKE_BUILD_TYPE=Release,但我注意到未设置 NDEBUG 标志。这是否意味着它是一个调试版本?
- delphi - Delphi 10.4 Android Intent BroadcastReceiver 和斑马扫描仪
- javascript - 生成的密码未出现在指定框中
- javascript - 无法读取 null 的属性“requestDevice”
- python - 在字典中使用对象
- html - 为什么两个 H1 标头之间有间隙,如何调整?
- excel - BI 工具中的时间智能