Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bot unable to restablish conversation link with state storage #1373

Closed
paulio opened this issue Mar 14, 2019 · 4 comments · Fixed by #1374
Closed

Bot unable to restablish conversation link with state storage #1373

paulio opened this issue Mar 14, 2019 · 4 comments · Fixed by #1374
Labels
Bug Your classic code defect P0 Must Fix. Release-blocker

Comments

@paulio
Copy link

paulio commented Mar 14, 2019

Version

What version of the Emulator are you using. 4.3.2

Describe the bug

The emulator connects the bot and the bot stores an object in state storage (tried with Cosmo or Memory) from the conversation update. The next message in the conversation returns null for the object from storage. Moving back to 4.3 and it all works fine.

To Reproduce

Steps to reproduce the behavior:

  1. Save an object to storage on Conversation Update
  2. Send another standard message from the emulator
  3. In the bot OnTurn attempt to fetch the same object
  4. actual, null is returned. expected the same object

[bug]

@tonyanziano
Copy link
Contributor

tonyanziano commented Mar 14, 2019

Hi @paulio ,

What data bag were you trying to store the object in? Conversation, User data, or are you trying to write directly to storage as shown in this example? I was able to repro this, but only when I tried to store the object in user data. When I tried to store the object in conversation data, it persisted no problem.

Here's a screenshot of my conversation:

image

Here is my bot's code:

const USER_DATA_PROPERTY = 'userData';
const CONVERSATION_DATA_PROPERTY = 'conversationData';

const { ActivityTypes } = require('botbuilder');

class MyBot {
  constructor(userState, conversationState) {
    this.userData = userState.createProperty(USER_DATA_PROPERTY);
    this.conversationData = conversationState.createProperty(CONVERSATION_DATA_PROPERTY);

    this.userState = userState;
    this.conversationState = conversationState;
  }

  /**
   *
   * @param {TurnContext} on turn context object.
   */
  async onTurn(turnContext) {
    if (turnContext.activity.type === ActivityTypes.Message) {
      // retrieve stored values from state
      const userData = await this.userData.get(turnContext);
      const convoData = await this.conversationData.get(turnContext);
      await turnContext.sendActivity(`Got back from state [user]: ${ userData }`);
      await turnContext.sendActivity(`Got back from state [convo]: ${ convoData.prop }`);
    } else {
      // store something in user state
      await this.userData.set(turnContext, { prop: 'I am some stored value!' });
      await this.userState.saveChanges(turnContext);

      // store something in conversastion state
      await this.conversationData.set(turnContext, { prop: 'I am some stored value!' });
      await this.conversationState.saveChanges(turnContext);

      // print out what value we are storing
      await turnContext.sendActivity(`[${ turnContext.activity.type } event detected]`);
      await turnContext.sendActivity(`Saving value of **${ 'I am some stored value!' }** in user and conversation state!`);
    }
  }
}

module.exports.MyBot = MyBot;

Regardless, this is still an issue, as I should be able to see the same object in the user state storage as well.

===

EDIT This is definitely a regression. Here's the same conversation in 4.2:

image

@tonyanziano tonyanziano added Bug Your classic code defect P0 Must Fix. Release-blocker 4.4 labels Mar 14, 2019
@tonyanziano
Copy link
Contributor

Hey @paulio, we figured out the issue and it was due to a mismatched userId which was preventing access to persisted user state created at the start of the conversation.

The fix is already merged in #1374, and we should have a 4.3.3 patch out later today!

@paulio
Copy link
Author

paulio commented Mar 14, 2019

Hero's :)

@tonyanziano
Copy link
Contributor

@paulio v4.3.3 is out and you can download it here. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Your classic code defect P0 Must Fix. Release-blocker
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants