Executing code on chatbot session start

I have a backend server that maintains the details of the user of a particular session. I have a slot user_id in my domain.yml which I want to populate with the user id maintained in my server. Is there some way I can do this?

To be a little more precise I am looking to override some piece of code that runs as soon as the chatbot session starts

How are you starting your chatbot? Is it through a Python script or directly from a shell?