user8094488
user8094488

Reputation: 3

How to communicate to an always running python script

i'm developing a python telegram bot and i have a script that is always running (for receiving new command from telegram) and i want the bot to send messages when the user perform a action in a website. example: the user start the bot, the bot send a link to perform an action in the website (like login to the user's account and connect the telegram id with the user id) and then send a confirmation message on telegram that all's good.

my problem is how i can tell the python script that the action in the browser is done? for now i'm constantly query a database but my solution is pretty dumb because if the user don't perform any action the query can go forever.

any suggestion how to do it correctly? thx <3

Upvotes: 0

Views: 478

Answers (1)

CallMeStag
CallMeStag

Reputation: 7050

I see two viable solutions here:

  1. Send the message directly from the website. While only one process is allowed to fetch updates at a time, you can make other requests from as many servers as you like. Depending on how your website works, you can make a plain HTTP request to the Bot API or use an API wrapper like python-telegram-bot or a wrapper in a different language to make the request. e.g. if you're running a php-based website, you could use a php API wrapper.

  2. If for some reason 1. is not an option for you, you can try to inform your running process about the user login. the PTB FAQ have an entry that should help you get started. If your website & bot are running on the same server, it might be possible to make the update_queue directly available to the website process. If not, you can try to set up a webhook for your bot and post an update to the webhook that you then enqueue into the update_queue

Approach 1. has the downside that you don't have all the bot logic in one place, but it should be by far easier to implement than 2.


Disclaimer: I'm currently the maintainer of python-telegram-bot

Upvotes: 0

Related Questions