[Question] session.userData loses an Object type on waterfall step?
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.
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?
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. :)
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.
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.
Closing this issue as I've forwarded the issue to the docs team for a fix.
This was fixed in the documentation today. Cheers!
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.