Skip to content Skip to sidebar Skip to footer

How To Delete Context/session_id At End Of Conversation In Wit.ai Bot

I've been having issues with Wit.ai where my Python bot will retain the context after ending a conversation. This behaviour is the same in the Facebook client and the pywit interac

Solution 1:

You can generate new Session Ids using uuid. Session ID has to be any text that is unique, it can even be system date. I suggest you use uuid

Check here as to how to generate it.

Solution 2:

I was confronted with the same issue and I solved it in the following way.

I first created a simple end_session action, to be called at the end of each conversation path:

defend_session(request):    
    return {'end_session': True}

Then I inserted the following code just after returning from run_actions:

if'end_session'in context:
    context = {}
    session_hash = uuid.uuid1().hex

As you see, in addition to clearing the context, as you do, I also recreate a new session id (as per Swapnesh Khare's suggestion).

I'm not sure this is the best solution, but it works for me.

Post a Comment for "How To Delete Context/session_id At End Of Conversation In Wit.ai Bot"