From a bot to a Mini App: order of code matters
  • Telegram
  • Mini App
  • HTTPS
  • Caddy

From a bot to a Mini App: order of code matters

21
Today I added a Mini App to the habits bot — a full app that opens inside Telegram. You cannot do everything with a bot: showing a daily schedule, checking things off, statistics — all of that is awkward with buttons. First I simplified the bot. A lot of extra things had piled up in it, and I did not use half of them myself. Keeping unused code means putting an obstacle in your own way later. I deleted what was not needed. Then I wrote the Mini App. Telegram requires HTTPS for it; plain HTTP will not work. Since Caddy was already running on the server, that part went easily — one block added and the certificate was obtained automatically. Here is the bug that ate an hour of my time. When the bot starts, it sends the command list and the menu button to Telegram. I had written that code after starting the bot. The result: sometimes it worked, sometimes it did not. The reason is that the start call takes over control, and the lines after it wait their turn. I moved both calls before the start and the problem disappeared. At the end of the day I connected the Mini App to the real database — until then it had been running on sample data. Now it shows the actual schedule. The main lesson of the day: a "sometimes it works" bug is the worst kind, because it is hard to reproduce.