Latest Notes

Roman Grossi • Founder

Indie hacking, startups, resilient systems - and staying sane while building a small company

Back to articles

Kicking Off Project X: Custom Telegram Bot API Setup and File Caching Pipeline

· 2 min read · 9 views

I figured it out. I will do what happens in one of my favorite movies, 'The Social Network': periodically write about my progress on a new project. And while in the movie Zuckerberg is documenting work on the rather non‑ethical FaceMash, I will be sharing updates on a much more ethical project of my own. Let us call it Project X.

Here we go.

I have built and launched a telegram-bot-api server that lets me bypass some of the limitations of the default api.telegram.org, especially the ones that really matter to me:

1. Maximum upload file size

2. Maximum number of webhook connections

3. Ability to use a local directory to access files

I wrote a Python script that exposes the bot files over the web (so I do not have to rewrite a lot of code) and caches them in S3 for further processing, so they do not take up space on the server.

While writing this post, I realized this project will probably generate a lot of open-source code on GitHub, like this script.

Here is a short breakdown of how it works.

On first request:

0. telegram-bot-api server saves the file to a local directory on the server

1. The script checks whether the local file exists

2. Returns it

3. Uploads it to S3

4. If the used space exceeds the configured threshold, it deletes the file from the server

On subsequent requests:

0. Checks if the local file exists (in case it has not been deleted yet)

1. If there is no local file, checks whether it is in S3

2. Returns it

Notes to self for later: telegram-bot-api server exposes server statistics, which the 'Petersburg olympiad kids' of course return in a custom format instead of a Prometheus Exporter format that would make it easy to build graphs and alerts. I will have to write a Python parser/converter to translate these metrics into the format I need.

More to explore