当我确认用户说了什么后,为什么我的技能会转到错误处理程序?

问题描述 投票:0回答:1

[我正在使用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;
      }
};
node.js alexa-skills-kit alexa-skill
1个回答
1
投票

您可能想重新访问attributes.done和attributes.err。我看不到您将其设置为true。您的canHandle方法期望其中一个对Yes Intent为true。]

祝你好运!

© www.soinside.com 2019 - 2024. All rights reserved.