If your server is in Iran, you probably know this problem: your Telegram bot works on your laptop, then you deploy it and every request to api.telegram.org just hangs or fails. The server can't reach Telegram.

I ran into this again and again, so a while ago I made a tiny proxy. It got more stars than I expected (over 100), so I decided to make it properly easy to use.

The idea

Instead of calling Telegram directly, your server calls your own small proxy. The proxy passes the request to Telegram and sends the answer back. You only change one thing in your bot: the base URL.

- https://api.telegram.org/bot<TOKEN>/sendMessage + https://<your-proxy>/bot<TOKEN>/sendMessage 

It works with any library that lets you change the API URL (python-telegram-bot, Telegraf, node-telegram-bot-api, or plain HTTP calls from PHP/Laravel).

What's new

You can now deploy it on three free platforms, no credit card needed:

  • Cloudflare Workers: one click, or paste one file.
  • Vercel: one click.
  • Google Apps Script: paste the file, press Deploy.

Other things I added:

  • An optional ACCESS_KEY, so strangers can't use your proxy. You put it in the URL: https://<your-proxy>/<ACCESS_KEY>/bot<TOKEN>/...
  • Your cookies and your server's IP are not sent to Telegram.
  • Tests for all three versions, with no dependencies (npm test).

Things you should know

  • Your bot token goes through the proxy, so deploy your own. Don't use someone else's for a real bot.
  • Google Apps Script can't upload or download files, and it always answers with HTTP 200 (check the ok field). Use Cloudflare or Vercel if your bot sends photos or documents.
  • On Vercel, long polling is capped at 20 seconds. Webhooks or Cloudflare are better there.
  • This is for bots and servers. If you want the Telegram app itself to connect, that needs an MTProto proxy on a VPS. I added a one-command setup for that too, but I'll be honest: you need a server outside Iran for it.

Try it

Code and setup steps (in Persian and English): https://github.com/soheylfarzanedev/TelegramByapss

If it helps you, a star on GitHub makes my day. Issues and pull requests are welcome.