Custom State not loading data that is saved to data Store












0















I am busy writing a bot that interacts with both anonymous and authenticated users. It stores user data in a custom object and persists that object to the UserState Store.



When the bot starts and the user joins the conversation it creates the custom object and the IStatePropertyAccessor for the custom object. the bot then determines if this is a authenticated or anonymous user. If its authenticated, it loads the required information from the backend system and we are able to use this data in all dialogs without issue.



If it is an anonymous user we direct them to a basic dialog that gets their name, phone number, and email. The last step in this dialog is to pull the above custom object and update it with the information collected so we can attach it when saving requests to the backend system.



The problem is that the updated information is saved to the store (I am able to view the raw data in the cosmosDB), but when getting the custom object from the store in other dialogs it always returns an empty object. If I trigger the onboarding dialog again, it pulls the correclty populated custom object fine.



Why is that this one dialog can see the data it saved to the store but other dialogs see it as an empty object?



Below is my code for the final step in the onboarding WaterfallStep dialog:



public async Task<DialogTurnResult> ProcessOnBoardingAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
_form = await _accessor.GetAsync(stepContext.Context);
_form.Firstname = (string)stepContext.Result;

UserProfile profile = await _userAccessor.GetAsync(stepContext.Context);

profile.FullName = String.Format("{0} {1}", _form.Firstname, _form.Lastname);

await _userAccessor.SetAsync(stepContext.Context, profile);

MainResponses view = new MainResponses();
await view.ReplyWith(stepContext.Context, MainResponses.Menu);

return await stepContext.EndDialogAsync();
}


After this step, the raw data is correct, the Fullname is set correctly. It can be viewed in the raw data stored in CosmosDB.



the next dialog's constructor is as follows and the IStatePropertyAccessor<UserProfile> userAccessor that is passed in to this constructor is the same one passed into the Onboarding Dialog constructor:



public LeadDialog(BotServices botServices, IStatePropertyAccessor<LeadForm> accessor, IStatePropertyAccessor<UserProfile> userAccessor)
: base(botServices, nameof(LeadDialog))
{
_accessor = accessor;
_userAccessor = userAccessor;

InitialDialogId = nameof(LeadDialog);

var lead = new WaterfallStep
{
LeadPromptForTitleAsync,
LeadPromptForDescriptionAcync,
LeadProcessFormAsync
};

AddDialog(new WaterfallDialog(InitialDialogId, lead));
AddDialog(new TextPrompt("LeadTopic"));
AddDialog(new TextPrompt("LeadDescription"));
}


and the code that is trying to use the accessor is:



public async Task<DialogTurnResult> LeadProcessFormAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
_form = await _accessor.GetAsync(stepContext.Context);
_form.Description = (string)stepContext.Result;

await _responder.ReplyWith(stepContext.Context, LeadResponses.LeadFinish);
await _responder.ReplyWith(stepContext.Context, LeadResponses.LeadSummary, new { _form.Topic, _form.Description });

UserProfile profile = await _userAccessor.GetAsync(stepContext.Context);


var LeadDetail = new CRMLead
{
ks_chatid = profile.Chatid,
parentcontactid =profile.ContactId,
topic = _form.Topic,
description = _form.Description
};
}


In this last bit of code, the returned UserProfile is an empty object with default values, but would have expected to at minimum pulled the Fullname that is correctly stored in the CosmosDB.










share|improve this question



























    0















    I am busy writing a bot that interacts with both anonymous and authenticated users. It stores user data in a custom object and persists that object to the UserState Store.



    When the bot starts and the user joins the conversation it creates the custom object and the IStatePropertyAccessor for the custom object. the bot then determines if this is a authenticated or anonymous user. If its authenticated, it loads the required information from the backend system and we are able to use this data in all dialogs without issue.



    If it is an anonymous user we direct them to a basic dialog that gets their name, phone number, and email. The last step in this dialog is to pull the above custom object and update it with the information collected so we can attach it when saving requests to the backend system.



    The problem is that the updated information is saved to the store (I am able to view the raw data in the cosmosDB), but when getting the custom object from the store in other dialogs it always returns an empty object. If I trigger the onboarding dialog again, it pulls the correclty populated custom object fine.



    Why is that this one dialog can see the data it saved to the store but other dialogs see it as an empty object?



    Below is my code for the final step in the onboarding WaterfallStep dialog:



    public async Task<DialogTurnResult> ProcessOnBoardingAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
    {
    _form = await _accessor.GetAsync(stepContext.Context);
    _form.Firstname = (string)stepContext.Result;

    UserProfile profile = await _userAccessor.GetAsync(stepContext.Context);

    profile.FullName = String.Format("{0} {1}", _form.Firstname, _form.Lastname);

    await _userAccessor.SetAsync(stepContext.Context, profile);

    MainResponses view = new MainResponses();
    await view.ReplyWith(stepContext.Context, MainResponses.Menu);

    return await stepContext.EndDialogAsync();
    }


    After this step, the raw data is correct, the Fullname is set correctly. It can be viewed in the raw data stored in CosmosDB.



    the next dialog's constructor is as follows and the IStatePropertyAccessor<UserProfile> userAccessor that is passed in to this constructor is the same one passed into the Onboarding Dialog constructor:



    public LeadDialog(BotServices botServices, IStatePropertyAccessor<LeadForm> accessor, IStatePropertyAccessor<UserProfile> userAccessor)
    : base(botServices, nameof(LeadDialog))
    {
    _accessor = accessor;
    _userAccessor = userAccessor;

    InitialDialogId = nameof(LeadDialog);

    var lead = new WaterfallStep
    {
    LeadPromptForTitleAsync,
    LeadPromptForDescriptionAcync,
    LeadProcessFormAsync
    };

    AddDialog(new WaterfallDialog(InitialDialogId, lead));
    AddDialog(new TextPrompt("LeadTopic"));
    AddDialog(new TextPrompt("LeadDescription"));
    }


    and the code that is trying to use the accessor is:



    public async Task<DialogTurnResult> LeadProcessFormAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
    {
    _form = await _accessor.GetAsync(stepContext.Context);
    _form.Description = (string)stepContext.Result;

    await _responder.ReplyWith(stepContext.Context, LeadResponses.LeadFinish);
    await _responder.ReplyWith(stepContext.Context, LeadResponses.LeadSummary, new { _form.Topic, _form.Description });

    UserProfile profile = await _userAccessor.GetAsync(stepContext.Context);


    var LeadDetail = new CRMLead
    {
    ks_chatid = profile.Chatid,
    parentcontactid =profile.ContactId,
    topic = _form.Topic,
    description = _form.Description
    };
    }


    In this last bit of code, the returned UserProfile is an empty object with default values, but would have expected to at minimum pulled the Fullname that is correctly stored in the CosmosDB.










    share|improve this question

























      0












      0








      0








      I am busy writing a bot that interacts with both anonymous and authenticated users. It stores user data in a custom object and persists that object to the UserState Store.



      When the bot starts and the user joins the conversation it creates the custom object and the IStatePropertyAccessor for the custom object. the bot then determines if this is a authenticated or anonymous user. If its authenticated, it loads the required information from the backend system and we are able to use this data in all dialogs without issue.



      If it is an anonymous user we direct them to a basic dialog that gets their name, phone number, and email. The last step in this dialog is to pull the above custom object and update it with the information collected so we can attach it when saving requests to the backend system.



      The problem is that the updated information is saved to the store (I am able to view the raw data in the cosmosDB), but when getting the custom object from the store in other dialogs it always returns an empty object. If I trigger the onboarding dialog again, it pulls the correclty populated custom object fine.



      Why is that this one dialog can see the data it saved to the store but other dialogs see it as an empty object?



      Below is my code for the final step in the onboarding WaterfallStep dialog:



      public async Task<DialogTurnResult> ProcessOnBoardingAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
      {
      _form = await _accessor.GetAsync(stepContext.Context);
      _form.Firstname = (string)stepContext.Result;

      UserProfile profile = await _userAccessor.GetAsync(stepContext.Context);

      profile.FullName = String.Format("{0} {1}", _form.Firstname, _form.Lastname);

      await _userAccessor.SetAsync(stepContext.Context, profile);

      MainResponses view = new MainResponses();
      await view.ReplyWith(stepContext.Context, MainResponses.Menu);

      return await stepContext.EndDialogAsync();
      }


      After this step, the raw data is correct, the Fullname is set correctly. It can be viewed in the raw data stored in CosmosDB.



      the next dialog's constructor is as follows and the IStatePropertyAccessor<UserProfile> userAccessor that is passed in to this constructor is the same one passed into the Onboarding Dialog constructor:



      public LeadDialog(BotServices botServices, IStatePropertyAccessor<LeadForm> accessor, IStatePropertyAccessor<UserProfile> userAccessor)
      : base(botServices, nameof(LeadDialog))
      {
      _accessor = accessor;
      _userAccessor = userAccessor;

      InitialDialogId = nameof(LeadDialog);

      var lead = new WaterfallStep
      {
      LeadPromptForTitleAsync,
      LeadPromptForDescriptionAcync,
      LeadProcessFormAsync
      };

      AddDialog(new WaterfallDialog(InitialDialogId, lead));
      AddDialog(new TextPrompt("LeadTopic"));
      AddDialog(new TextPrompt("LeadDescription"));
      }


      and the code that is trying to use the accessor is:



      public async Task<DialogTurnResult> LeadProcessFormAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
      {
      _form = await _accessor.GetAsync(stepContext.Context);
      _form.Description = (string)stepContext.Result;

      await _responder.ReplyWith(stepContext.Context, LeadResponses.LeadFinish);
      await _responder.ReplyWith(stepContext.Context, LeadResponses.LeadSummary, new { _form.Topic, _form.Description });

      UserProfile profile = await _userAccessor.GetAsync(stepContext.Context);


      var LeadDetail = new CRMLead
      {
      ks_chatid = profile.Chatid,
      parentcontactid =profile.ContactId,
      topic = _form.Topic,
      description = _form.Description
      };
      }


      In this last bit of code, the returned UserProfile is an empty object with default values, but would have expected to at minimum pulled the Fullname that is correctly stored in the CosmosDB.










      share|improve this question














      I am busy writing a bot that interacts with both anonymous and authenticated users. It stores user data in a custom object and persists that object to the UserState Store.



      When the bot starts and the user joins the conversation it creates the custom object and the IStatePropertyAccessor for the custom object. the bot then determines if this is a authenticated or anonymous user. If its authenticated, it loads the required information from the backend system and we are able to use this data in all dialogs without issue.



      If it is an anonymous user we direct them to a basic dialog that gets their name, phone number, and email. The last step in this dialog is to pull the above custom object and update it with the information collected so we can attach it when saving requests to the backend system.



      The problem is that the updated information is saved to the store (I am able to view the raw data in the cosmosDB), but when getting the custom object from the store in other dialogs it always returns an empty object. If I trigger the onboarding dialog again, it pulls the correclty populated custom object fine.



      Why is that this one dialog can see the data it saved to the store but other dialogs see it as an empty object?



      Below is my code for the final step in the onboarding WaterfallStep dialog:



      public async Task<DialogTurnResult> ProcessOnBoardingAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
      {
      _form = await _accessor.GetAsync(stepContext.Context);
      _form.Firstname = (string)stepContext.Result;

      UserProfile profile = await _userAccessor.GetAsync(stepContext.Context);

      profile.FullName = String.Format("{0} {1}", _form.Firstname, _form.Lastname);

      await _userAccessor.SetAsync(stepContext.Context, profile);

      MainResponses view = new MainResponses();
      await view.ReplyWith(stepContext.Context, MainResponses.Menu);

      return await stepContext.EndDialogAsync();
      }


      After this step, the raw data is correct, the Fullname is set correctly. It can be viewed in the raw data stored in CosmosDB.



      the next dialog's constructor is as follows and the IStatePropertyAccessor<UserProfile> userAccessor that is passed in to this constructor is the same one passed into the Onboarding Dialog constructor:



      public LeadDialog(BotServices botServices, IStatePropertyAccessor<LeadForm> accessor, IStatePropertyAccessor<UserProfile> userAccessor)
      : base(botServices, nameof(LeadDialog))
      {
      _accessor = accessor;
      _userAccessor = userAccessor;

      InitialDialogId = nameof(LeadDialog);

      var lead = new WaterfallStep
      {
      LeadPromptForTitleAsync,
      LeadPromptForDescriptionAcync,
      LeadProcessFormAsync
      };

      AddDialog(new WaterfallDialog(InitialDialogId, lead));
      AddDialog(new TextPrompt("LeadTopic"));
      AddDialog(new TextPrompt("LeadDescription"));
      }


      and the code that is trying to use the accessor is:



      public async Task<DialogTurnResult> LeadProcessFormAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
      {
      _form = await _accessor.GetAsync(stepContext.Context);
      _form.Description = (string)stepContext.Result;

      await _responder.ReplyWith(stepContext.Context, LeadResponses.LeadFinish);
      await _responder.ReplyWith(stepContext.Context, LeadResponses.LeadSummary, new { _form.Topic, _form.Description });

      UserProfile profile = await _userAccessor.GetAsync(stepContext.Context);


      var LeadDetail = new CRMLead
      {
      ks_chatid = profile.Chatid,
      parentcontactid =profile.ContactId,
      topic = _form.Topic,
      description = _form.Description
      };
      }


      In this last bit of code, the returned UserProfile is an empty object with default values, but would have expected to at minimum pulled the Fullname that is correctly stored in the CosmosDB.







      c# botframework






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 26 '18 at 13:25









      MrThirstyMrThirsty

      108111




      108111
























          1 Answer
          1






          active

          oldest

          votes


















          0














          It turns out that a fellow developer had made the set properties on the User Profile class as internal so the accessor could not set the properties when reading the store.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53482132%2fcustom-state-not-loading-data-that-is-saved-to-data-store%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            It turns out that a fellow developer had made the set properties on the User Profile class as internal so the accessor could not set the properties when reading the store.






            share|improve this answer




























              0














              It turns out that a fellow developer had made the set properties on the User Profile class as internal so the accessor could not set the properties when reading the store.






              share|improve this answer


























                0












                0








                0







                It turns out that a fellow developer had made the set properties on the User Profile class as internal so the accessor could not set the properties when reading the store.






                share|improve this answer













                It turns out that a fellow developer had made the set properties on the User Profile class as internal so the accessor could not set the properties when reading the store.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 7 '18 at 9:44









                MrThirstyMrThirsty

                108111




                108111
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53482132%2fcustom-state-not-loading-data-that-is-saved-to-data-store%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

                    Calculate evaluation metrics using cross_val_predict sklearn

                    Insert data from modal to MySQL (multiple modal on website)