4

My goal is to make a Telegram Bot using Python that does the following:

  1. The user types a command
  2. The bot explains what the user should type next.
  3. The user types certain information
  4. I use that info to fetch a value in a python dictionary.
  5. The bot replies with that info

I have already created the bot and set the command. The problem is that I don't know how to keep the bot "listening" . I have looked up in the docs but I have only found getUpdates, which gets the user's responses but only when you hit run.

res=requests.get(url=f"https://api.telegram.org/bot{bot_token}/getUpdates")

I would like to set a webhook, and I know there is a method for this but I'm not shure about how this works.

1 Answers1

1

When you are a PHP programmer, setting the webhook through a URL and using setWebhook would do the trick and telegram will send the result to this link whenever a user sends an update to the bot. But, Python programmers have to use a different approach, I think. The main, and while, the easiest approach to make the bot listen permanently to the request is to python-telegram-bot module.

There are a few links that can help to build your first pythonic bot that can respond to users' updates.:

TheFaultInOurStars
  • 3,464
  • 1
  • 8
  • 29
  • There's no language bias with setWebhook. It's just HTTP. A typical setup for Python is import a WSGI capable module like gevent or gunicorn, and have it listen for web requests, then use nginx proxy_pass directive to forward requests from your web server to the Python service. – copycat Jan 07 '23 at 10:44