Passing user session id in rasa webhook calls

I am wondering how its expected we are able to associate a call from rasa to our backend (ie the “/webhook” and “/nlg” endpoints) with our backend’s user session. Rasa is technically a different client from the front end so we cannot access the user session when rasa makes a call to us, which we need so we can use user details when running actions.

I tried putting the session id in the rasa jwt but it seems rasa does not return the jwt in the returning header. Not sure if I missed something in the docs. Thanks.

Why do you need session id? Is it to maintain context of conversation or continue the conversation from last login?

to maintain context. I need to grab the session once rasa requests at my /webhook endpoint bc I need to use some session context when running my actions

I am able to maintain context for conversation using sender_id. Suppose user A1 logs in and then logs out. I assign the sender_id to be A1 and save the conversation in tracker store. Once user A1 logs in again ,his past conversation are fetched from the tracker store and then fed to the tracker. This sets the tracker to the last event occurred. And so the context is maintained.

I am not talking about trackers.

I have some psuedo code below. If I run any action or utter I need the most up to date information about the chat and session. Not sure how other apps are doing this. I don’t want to query my database, or even my session store at that matter for every rasa call to my backend.

@requestmapping("/webhook")
// I need the context here 
context = getContext(sessionId)
runAction(context)
saveContext(context)

@requestmapping("/nlg")
context = getContext(sessionId)
runUtter(context)
saveContext(context)
@app.route("/webhook/<session_id>/<sender_id>/",methods=["GET"])

def index(session_id,sender_id):

return redirect(“http://localhost:5005/conversations/<sender_id>/trackers”)

This will list out the tracker upon hitting the URL and thus u ll get context of the conversation using sender Id and session id

Hi @ashukrishna100

Can you let me know where this changes needs to be made, i am also trying for the scenario where multiple users can speak to Rasa bot at the same time but the chats should be independent.

Thanks, Pausali

If you are using the Rasa API, the “sender” is used to distinguish between conversations… for example, we have an API that processes a queue of messages to send to RASA. We use something like this to forward to Rasa (I’ve removed exception handling code to make it easier to understand):

CHATBOT = "http://localhost:5005/webhooks/rest/webhook"

payload = '{"sender": "' + user + '", "message": "' + message + '"}'
r = requests.post(CHATBOT, data=payload).encode('utf-8')

response = json.loads(r.content)

If you look in the rasa.conversations collection (mongoDB), there are separate entries for each sender.