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

Session Timeout Feature? Infinite loop fix for sms integration with state persistence

Open jeffreyhyun opened this issue 10 years ago • 3 comments

First off, the botbuilder is awesome with great integration options, v1 fixed so many issues I was having.

In the case of an sms bot, it was essential to write a sessionTimeout module so that a user who randomly stopped somewhere not at the expected end of a typical callstack would timeout calling an end dialog and start back at the beginning the next time they texted. The integration with twillio seemed to persist state. This caused huge issues in the beginning in pre v1, where if I didn't handle my responses, flow, or endDialogs correctly, I'd end up in an infinite loop via text with literally no way to escape. I basically had to figure out a way to break the code to get me out of a dialog. Just figure it'd be sweet if the functionality was built in.

This was my quick and dirty solution before I knew that lastAccess existed

var SessionManager = function( endSessionCb, sessionWatcher ) {
    var _self = this;

    var timerEngine;
    var timeLeft;
    var sessionTime;

    this.setSessionLength = function(time) {
        sessionTime = time;
    };

    this.getSessionTime = function() {
        return sessionTime;
    };

    this.getSessionTimeLeft = function() {
        return timeLeft;
    };

    this.startSession = function() {
        _self.resetSession();
    };

    this.extendSession = function( callback ) {
        if( callback ) callback();

        _self.resetSession();
    };

    this.killSession = function() {
        clearInterval(timerEngine);
    };

    this.resetSession = function() {
        _self.killSession();
        timeLeft = this.getSessionTime();
        timerEngine =   setInterval(timer, 1000);
    };

    var timer = function() {
        timeLeft--;

        if( timeLeft === 0 ) {
            endSessionCb();
            _self.killSession();
        } else {
            if( sessionWatcher ) {
                sessionWatcher();
            }
        }
    };
};

I just pretty much called start on entry to the dialog and called extend on each new route's onBegin, onDefault, and before each prompt if it wasn't hadled by the previous two.

jeffreyhyun avatar Jun 20 '16 14:06 jeffreyhyun

wondering about this on C# too

what is the current way that an token set on session.userdata will expire? is it possible to set session timeout? it's pretty opaque how the sessions are stored but seems to use KeyVault?

Then why not do away with using the session api altogether and just store stuff on KV directly and pull data from there?

whatsdis avatar Jun 21 '16 01:06 whatsdis

Closing this issue due to age. @jeffreyhyun @whatsdis - please open a new issue if this issue needs further discussion. Thanks!

v-thgratMSGit avatar Jul 26 '16 20:07 v-thgratMSGit

Was hoping for some input on how you guys handle it....

jeffreyhyun avatar Jul 26 '16 23:07 jeffreyhyun