当我确认用户所说的内容时,为什么我的技能会转到我的错误处理程序?
Why does my Skill go to my error handler when I confirm what user said?
我正在制作一项使用 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.Your canHandle 方法期望其中之一对于 Yes Intent 为真。
祝你好运!
我正在制作一项使用 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.Your canHandle 方法期望其中之一对于 Yes Intent 为真。
祝你好运!