Skip to content

Reset current state #159

Closed
Closed

Description

@ysak-y

Overview

I use DynamoDB in this sdk. This saves current state to DynamoDB if I set state to this.handler.state.
But I can't find how reset state because when I set empty string('') to this.handler.state, sdk ignore to update.
https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/blob/master/lib/response.js#L206
https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/blob/master/lib/response.js#L225

What should I do if I want to reset current state. If there are no ways, I'll implement.

Activity

  1. benedekh commented on Jul 26, 2017

    @benedekh

    Empty string is a falsy (evaluates to false) value in JS. See https://dorey.github.io/JavaScript-Equality-Table/

  2. ysak-y commented on Jul 26, 2017

    @ysak-y
    Author

    Yes, I know, so how do I reset state ?
    Delete STATE key & value in DynamoDB directory?

  3. valentinkostadinov commented on Aug 23, 2017

    @valentinkostadinov

    I'm having the exact same problem. Any updates on this?

    How do I reset state? This is especially bothersome since the official README makes an example out of it:

    var guessModeHandlers = Alexa.CreateStateHandler(states.GUESSMODE, {
    
        'NewSession': function () {
            this.handler.state = '';
            this.emitWithState('NewSession'); // Equivalent to the Start Mode NewSession handler
        },
    
    

    And under Tips, it says:

    If the target state is "", then this.emit("TargetHandlerName") should be called.

  4. ysak-y commented on Aug 29, 2017

    @ysak-y
    Author

    If the target state is "", then this.emit("TargetHandlerName") should be called.

    This sample is correct if you call TargetHandlerName with no STATE. But after response, state will back to current state(not empty state).

    Now we don't have a way to reset current state.

  5. allthepies commented on Oct 28, 2017

    @allthepies

    I've having the same problem, an attempt to reset state to "empty" is ignored by the ASK.
    The following workaround does work for me:

      this.handler.state = constants.states.START_MODE;
      this.attributes.STATE = null;
    

    where constants.states is
    states: {
    START_MODE: '',
    DETAIL_DECISION_MODE: '_DETAIL_DECISION_MODE'
    }

    I have found that I need both of the "reset" code lines, the first used the documented approach and the second sets the state entry ("STATE") in the session attributes to NULL directly. This works for me.

  6. tianrenz commented on Nov 9, 2017

    @tianrenz
    Contributor

    issue closed.
    future discussion please refer to issue #69

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions