Import PhBot API from another script

Hey,

I want to create another application on the top of PhBot to manage all accounts in custom made Python application. My question is that can I just import PhBot and use its API somehow in another runtime?

Thnx.

You would have to create an API with Python in order to communicate with your external application.

How so? Say that I have an API app called X with user interface to manage characters with own db. Can I just launch a PhBot and use its API with the X app? I just wanna simply use the bot as python package to import into my app and consume its API.

It doesn’t export an API. It doesn’t work like that. You have to create your own Python plugin that exposes an API that you can use with your own application.

Hmm, kinda adapter plugin to call external API endpoints. This can work but not ideal tho. Also, It would be one-way communication as there is no possibility to send a command to the bot from the application.

Exactly. You could communicate both ways with sockets.

Good idea, have concerns to use PhBot as client and the API application as server. As far as I know there is one way to communicate (server) → (client). In this case, the API would be the server, and each PhBots are clients. I am not sure it is possible to send data from client to server?

Another idea: Twisted. Can I use twisted within PhBot?

It is possible. You have to install the package through pip then you can load it in a plugin.

1 Like

Cool, it sounds nice weekend project :slight_smile: Thnx for the clarification. Good work!