How to create a Telegram bot that only responds to you, with long polling in Python
A Telegram bot is a convenient remote control for a script or AI agent on your own machine. It works on any mobile phone, it doesn't require its own app and it doesn't require a public server. The drawback is that a bot is public. Anyone can find its username and write to it, and the token only proves that your script is the bot; it says nothing about who is writing. The application of…
A Telegram bot can be controlled remotely using a script or AI agent on a personal machine. The bot is public and can be found by anyone, but the token only verifies the script, not the user. A Python script using the standard library was created to interact with the Telegram Bot API, allowing for long polling to receive messages without needing a public URL or server.
The script uses a pairing system with a one-time code to authorize users, storing the user's ID and chat ID to handle messages. The script can send messages and handle incoming messages, with the ability to run an agent or perform other actions.
Written by urgent.news from Dev.to's report — not a translation of it. Machine-written — may contain errors; check the original before relying on it.