Я делаю навык, который использует API Spotify, и если был результат с похожим именем, я спрашиваю пользователя, имели ли они в виду этого человека.
Мой обработчик работает, узнав, что имя отличается Однако после подтверждения (пользователь говорит да) программа переходит к моему обработчику ошибок.
Почему это так? Я словно потерян для слов.
Вот мой обработчик запуска и обработчик, который проверяет исполнителя:
{ //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;
}
};