botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

[Question] session.userData loses an Object type on waterfall step?

Open akontsevich opened this issue 9 years ago • 7 comments

System Information

  • SDK Language: Node.js
  • SDK Version: 3.9
  • Development Environment: localhost

Issue Description

Assign Date object to my custom variable session.userData.start, however on next waterfall step or parent dialog this variable become string.

Waterfall Code Example

[
function (session, results) {
        session.userData.city = results.response;
        builder.Prompts.time(session, "What are Your travel dates?");
    },
    function (session, results) {
        // Get booking start time
        session.userData.start = builder.EntityRecognizer.resolveTime([results.response]);
        // On this step session.userData.start is Date

        // Prompt for rooms
        builder.Prompts.text(session, "How many rooms?");
    },
    function (session, results) {
        // On this step session.userData.start become string
    }
]

Expected Behavior

Hope variable remains as Date type with Date() constructor and Date methods.

akontsevich avatar Aug 17 '17 01:08 akontsevich

Because the data is saved in JSON, complex objects (like Date) cannot be stored in the session.userData object. What you can do instead is something like calling Date.toISOString() and storing that inside of session.userData.

When you need to use the Date again, you would simply take the string from session.userData and convert it back to a Date object.

var start = new Date(session.userData.start);

Does this help?

stevengum avatar Aug 17 '17 01:08 stevengum

Yeah, this helped: https://stackoverflow.com/q/45724975/630169 of course.

However documentation mentioned:

Since the Bot Builder SDK for Node.js implements each storage container as a JavaScript object, you can store any type of data that a JavaScript object supports.

So thought any type is allowed. Need to fix either code or documentation then. :)

akontsevich avatar Aug 17 '17 02:08 akontsevich

Thank you for providing the link! I was hoping that our documentation was correct, but it obviously needs to be updated. I'm going to leave this open until a PR is filed for the docs.

stevengum avatar Aug 17 '17 02:08 stevengum

Probably it is good session saved in JSON - it is possible to leave conversation, jump to some other resource (web site for ex.) and back to same session via RESTful request.

akontsevich avatar Aug 17 '17 19:08 akontsevich

Closing this issue as I've forwarded the issue to the docs team for a fix.

stevengum avatar Aug 18 '17 22:08 stevengum

This was fixed in the documentation today. Cheers!

RobStand avatar Aug 22 '17 02:08 RobStand

Cool! Thanks!

Good if they extend other documentation and examples, for example for buttons, cards, their actions, etc: to understand and SEE how they work need to go to the doc, examples, github issues, stackowerflow, blogs, etc. Good if doc will be enough.

akontsevich avatar Aug 22 '17 11:08 akontsevich