Reputation: 21
I'm making a skill that uses spotify's api, and if there was a result with a similar name I ask the user if they meant that person.
My handler works upon recognizing that the name is different, however upon confirmation (user saying yes) the program goes to my error handler.
Why is this? I'm kind of lost for words.
Here is my launch handler and handler that verifies the artist:
{ //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;
}
};
Upvotes: 0
Views: 36
Reputation: 357
You might want to revisit attributes.done & attributes.err. I don't see you setting it to true.Your canHandle method expects one of these to be true for the Yes Intent.
Good luck !
Upvotes: 1