question

newuserdeveloper avatar image
newuserdeveloper asked

Alexa Audio Player RESUME_DECISION_MODE to START_MODE State Change

I have been following the Alexa Audio Player example (https://github.com/alexa/skill-sample-nodejs-audio-player) and I am able to run it as built. However, I am attempting to allow a returning user who would otherwise be stuck in the RESUME_DECISION_MODE to return to the START_MODE state. I have attempted to do so by changing the state handler (this.handler.state = constants.states.START_MODE) and listening for user input. However, the state change is never recognized. In the case that I change the state handler and use emitWithState, I am able to send the user to a specific intent in START_MODE, however, whenever I start the skill again, I am brought back to the RESUME_DECISION_MODE state. I believe this may be due to how the current state is being saved, although I am not sure. How can I resolve this to allow users to fully return the START_MODE state from RESUME_DECISION_MODE?

alexa skills kitaudioaudioplayer
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

newuserdeveloper avatar image
newuserdeveloper answered

I realized that the problem appears to be due to START_MODE being represented by an empty string in the constants.js file (START_MODE : ''). DynamoDB does not allow storing empty string values (https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.NamingRulesDataTypes.html). Therefore, saving state changes works for states represented by non-empty strings.

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Anand@Amazon avatar image
Anand@Amazon answered

Hi there,

You can resolve this issue by passing a flag with state handler to find out whether it has to re-start again.

Ex.

const GAME_STATES = {
    RESUME: '_RESUMEMODE',
    START: '_STARTMODE',
};


const startStateHandlers = Alexa.CreateStateHandler(GAME_STATES.START,{
  'StartGame' : function(newGame){
    let speechOutput = newGame ? this.t(WELCOME_MESSAGE): '';

    // Put Skill logic here

    this.handler.state = GAME_STATES.RESUME;
    this.emit(':ask', speechOutput);
  }
});

const resumeStateHandler = Alexa.CreateStateHandler(GAME_STATES.RESUME,{
  'GoBackIntent': function(){
    this.handler.state = GAME_STATES.START;
    this.emitWithState('StartGame', true);
  },

  // Remaining skill handler functions

});

exports.handler = function(event,context){
  const alexa = Alexa.handler(event,context);
  alexa.registerHandlers(startStateHandlers,resumeStateHandler);
  alexa.execute();
};

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.