Where should I write code to operate with/on session variable only once per session?
What I understand session is only accessible in bot.dialog(), If I do so outside in app.js I don't have access to session variable and if it do it inside dialog() I have to do it for each and every matching dialog(), but I need to perform such session related operations only once. please let me know whats the best practice.
You might consider using middleware (since it will run for every request, and it has access to the sesssion state) e.g. sendTyping:
https://github.com/Microsoft/BotBuilder/blob/0fb918065126b1208756d2e5be0c2d00ecb55451/Node/core/src/middleware/Middleware.ts#L106
Is there a function that will run the very first time the conversation is initiated? There are a couple things I'd like to do as setup the first time the conversation is initiated. What is the best way to do this?
you might consider the "firstRun" middleware: https://github.com/Microsoft/BotBuilder/blob/0fb918065126b1208756d2e5be0c2d00ecb55451/Node/core/src/middleware/Middleware.ts#L74
or you can hook the conversationUpdate event (though you won't have access to the session): https://github.com/Microsoft/BotBuilder/blob/a7370bdd38b81c9414bb8c22b047f6b3f7a5c54c/Node/examples/demo-skype/app.js#L58
"firstRun" does work for me but here's a scenario.
- User gets into bad state
- Types "reset" and dialog state is reset
- But now it does NOT run "firstRun" middleware Is there a way to run firstRun on a "reset"? @willportnoy thanks for your help so far btw
I think you'd have to modify reset to also clear the first run state in the user data bag. Generally "reset" does not clear the user data bag (I believe it clears the private conversation data bag, or perhaps just the dialog stack and state).
Hi @ishandutta2007, @suvamsh, was this solved?
@Andrea-Orimoto yup this was solved for me!
Great to hear! Closing this issue, feel free to reopen if needed. Thanks!