You can make your python code into a REST API (using flask, it's super simple) and configure your custom chatbot to send over http requests to that API.
Your API could be on the same server as your wordpress app and under a different subdomain or on another server, so you can install python and all its dependencies there.
That's what I did in my case, I hope this helps.