We've had a task in our backlog for a long time - to show avatars of users, groups, and channels in the personal account and on the victory page. It seems like a small thing, but a small thing that always bothered me.

You probably know these standard Telegram avatars - the first letter of the name on a beautiful gradient background. But when you request them via the API, you get null in response. Telegram simply doesn't store them on servers; the client app draws them itself.

So we made our own simple placeholders a long time ago and lived with them. But it always bothered me - it didn't look like Telegram, so it wasn't beautiful). Yesterday I finally figured out how it works - we haven't implemented it yet, but at least it became clear what to do.

I know there are TMA builders on the channel - this tip might save you time.

Telegram has open source code and literally everything you need is hardcoded: 7 gradients and one formula:
color_index = abs(peer_id) % 7
Take peer_id, divide by 7, take the remainder - you get a color index from 0 to 6:
0 - 🔴 red-pink
1 - 🟠 orange-yellow
2 - 🟣 purple-blue
3 - 🟢 green
4 - 🩵 turquoise
5 - 🔵 blue
6 - 🩷 purple-pink


Another nuance: for supergroups/channels, the Bot API returns chat_id with the prefix -100, but the color should be calculated from the real peer_id without it. Without this, the color will not be the one the user sees in the app.

〰️〰️〰️
If you don't have an avatar, mark yourself in the comments 😄