197
Local Telegram Emulator
Have you ever written Telegram bots? To connect a local bot to Telegram, you have to wrestle a bit with SSH tunnels or port forwarding. Or you can use the API/long polling instead of webhooks, which isn't always convenient.
I'm currently building a personal income-and-expense tracking service — more precisely, the service itself was written by gpt-5 in Cursor during the free release week (burned through about $300 of free tokens, lol). I'm writing a bot for it. The previous version ran on Google Sheets; I still use it, but it's not very convenient for a number of reasons. The current one looks like this:

But the service is a story for another time, once I publish it. For now, let's dive into local bot development.
Usually, a bot is some script in Python/PHP/Go/etc developed locally. There are three ways to interact with Telegram:
- API — the bot periodically polls Telegram for updates, say every few seconds. The downside is obvious: latency.
- Long polling — the same API, but with a timeout parameter. During this timeout, if there are no updates, Telegram holds the connection until either an update arrives or the timeout elapses. Pros: you get updates immediately. Cons: you need to keep a persistent connection to Telegram and reconnect when the timeout hits.
- Webhooks — also via the API, but from the bot’s side: you implement an endpoint that Telegram will call to deliver updates. A message arrives → Telegram sends it to the bot → you handle it. Pros: no need to keep a connection open, minimal delay. Cons: the bot must provide a publicly accessible API endpoint.
I prefer webhooks (or hybrid approaches), which means I needed to solve the "public API" problem for the bot. In prod this is straightforward: deploy to a VPS and configure nginx to proxy requests to the proper port/service. But to make this work locally, you have to suffer a bit. Options include:
- A public static IP on your local machine — rare these days and often a paid add-on from your ISP. Even with it, exposing your PC to the internet just for this is at least unsafe. You need to constantly monitor open ports, security policies, update software, etc., so your PC doesn’t quietly become part of a botnet (and you might not even notice).
- Third-party tunneling services that provide temporary domains and forward to your local machine (a tunnel between your PC and the outside world) — e.g., ngrok or LocalTunnel. They usually offer some free tier and temporary domains. But functionality is limited, any network changes (VPN up/down, switching Wi‑Fi) can break the tunnel, and they aren’t available in all countries.
- Roll your own SSH tunnel. If you have a VPS and SSH access, you can forward a local port to the VPS with a single command. Then configure nginx there to route from your domain to a specific port. Same downside: the connection isn’t always stable.
On top of that, to test a bot you have to register it with Telegram, configure it, and then conduct all your interactions inside the official Telegram app.
Because of all this, I decided to run Telegram locally for bot development and testing. No internet, no external services — run the emulator locally, point the bot to its domain and port, and build your bot entirely on your machine.
You can check out what I ended up with in the repository: https://github.com/positron48/telegram-emulator
Initially, I thought I’d build some admin UI — pick bots, switch users — but I ended up with an almost full-fledged messenger (minus authentication/authorization), where you can chat as different users in separate browser windows:

Plus the usual and not-so-usual features. It supports English and Russian locales, and both light and dark themes:

You can switch the active sender and also create users:

You can create a new dialog between users, a user and a bot, or create a group with multiple users:

There are bot settings too — among other things, this is where you specify the API key and webhook URL that the emulator should call:

But that’s just UI. The whole point here is bot development. What’s covered:
- all interaction modes: API / long polling / webhooks;
- API methods: getMe, getUpdates, sendMessage, setWebhook, deleteWebhook, getWebhookInfo;
- inline and native keyboards;
- handling callbacks when keyboard buttons are pressed.
In my opinion, that’s more than enough to start building and cover the basics. For now there’s no editing/deleting messages, no media handling, and there may be some mismatches between the emulator and the real Telegram Bot API — I’m actively building my own bot on top of it, so I’ll fix whatever I find along the way.
There’s also a simple console bot example in Python that responds to simple commands and demonstrates the emulator’s features:

And how it looks in the emulator UI (partial):

Now about the implementation. Backend is Go, frontend is React. I’m only moderately familiar with both — I can’t code them from scratch by hand; I don’t really know Go syntax; and I’m not versed in React components’ internals (I have experience mainly with Vue.js).
And none of that stopped me from shipping a complete tool — in three days. Cursor and gpt-5-high work wonders. No matter how hard the conservatives push back against AI tools or call LLMs “stochastic parrots,” facts say otherwise.
You can already try building something of your own for your tasks — just ask for it in chat.
- Learning a language and dislike the toy-ish feel of DuoLingo? Build your own and let AI play the role of the teacher.
- Want a simple personal budget tracker and can’t find anything clean and straightforward? Build your own — even with uploading receipt photos to a Telegram bot and auto-categorizing purchases.
- Need firmware for an ESP8266 to pipe a simple sensor into Home Assistant? You know what to do.
These are just my personal examples and plans — you can build whatever fits your needs. Browser extensions, microcontroller firmware, calculators, UIs for ffmpeg or batch image processing — today it’s often easier to build your own than to try dozens of existing apps hunting for the right fit.
Yes, for now you either need some understanding of how things work, or the willingness to figure it out, or a relatively simple task.
And yet, the future is already here.
No comments yet
-
Goback - easy backups
I finally decided to properly tackle backups. Once again, I had to rely on cust… -
Project Watcher
This Halloween-timed project is a one‑eyed Cthulhu statue with a mechanized eye… -
Universal AI Telegram Bot
Want to launch your own AI Telegram bot in just a couple of steps? -
YouTube Watch History Analysis
Ever wondered how much time you spend watching videos? Let's count it. -
Image2model with Tripo3D and Blender
Sometimes you want a drawn or AI-generated character to become real. -
Reviving Coat Hanger Bases
We have a couple of coat hangers with hangers at home, where clothes are conven…