DEV Community


Posted on


ImgMacroBot — Telegram inline bot to generate image macros on the fly.

Sometimes I want to reply with a meme image in a Telegram conversation. You know, when a colleague asks you why did it take you so long to fix a simple issue, and you feel like:

One does not simply fix a bug

Maybe those images make you feel like it's 2007 and you are on an imageboard, but I still like some of them. At the same time, I am too lazy to open an online generator, find an appropriate template, generate a meme and post it as an answer.

So, I decided to automate that with an inline Telegram bot.

Meet @ImgMacroBot, a bot who can generate image macros on the fly in Telegram conversations.

The usage is simple. To generate an image above, just type "@ImgMacroBot one does not simply fix a bug" in any Telegram chat. If you've ever used inline bots like @pic, @youtube, or @imdb you should know what happens next. Your Telegram client will prompt you some of the results matching your query. You can select one of those results and post it in a conversation.

Like this:


That's basically it. The list of supported templates is short, but adding new macros is not a big deal due to the clean architecture I've used :) If you have an idea — just submit an issue.

Technically, the bot is written in Kotlin using Ktor and Koin. It's a single endpoint web service, listening for Telegram Bot API webhooks. Text is drawn using Oswald font (I need Cyrillic, not supported in Anton) with Skija library, a Java wrapper for Skia, a 2D library powering your phone and browser. It is really cool and next time you need to make something with graphics, consider using Skia and its wrapper for your language. Next, generated images are upload to Imgur via its API (the documentation could be better). The whole thing is running on a free VM in Oracle Cloud. So, yeah, next time you need to host something lightweight — check out their offering. Oracle also provides a free DB instance, which I'm using to cache the links. Monitoring: Grafana Cloud (also free). Deployments: GitHub Actions + Ansible. So it didn't cost me a penny, except for ~50 hours of coding in two weeks on the evenings.

Feel free to ask any questions on the tech stack, I'll be glad to help you with you Telegram bots.

Top comments (0)

Advice For Junior Developers

Advice from a career of 15+ years for new and beginner developers just getting started on their journey.