M
M
muhasa2019-09-14 17:25:21
Heroku
muhasa, 2019-09-14 17:25:21

Heroku as hosting for a bot. What is the effect of the 30 minute limit?

Hello. The elementary host behind a hillock is necessary to send messages to clients on TG.
Heroku is advised, but I don’t quite understand - there in the free mode it says something about 30 minutes of downtime, supposedly the server goes to sleep if there is no activity.
My script is simple, it receives a message and sends it to a specific recipient. Of course it works in standby mode, not deamon. It turns out, according to such a restriction, the script will not be able to work correctly? Or did I misunderstand the limitation?
And if so, how do the rest of them host bots for free? Are the Daimons hooked to 24/7 pooling?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2019-09-14
@muhasa

General theory:
If a bot on Heroku goes to sleep, then it does not lose its internal state. When the sleeping bot is first accessed over the web, it will respond, as usual, but with a delay, to wake up from sleep. On the Internet they write that getting out of sleep takes a couple of seconds. I haven't checked the timings myself.
Practice: The
Heroku free plan can be successfully used for a Telegram bot, but you need to adapt:

  • Do long polling on Heroku using worker gyno. The documentation says that worker dynos do not go to sleep.
  • Make a bot on webhooks. In this case, the bot will go to sleep when idle, but the next request will wake it up. I did not check the timings, but I will assume that Telegram will not terminate the connection due to a response delay of a couple of seconds. Yes, for an external user, this request will take a few seconds to process due to waking up from sleep.
  • Make the bot as usual, but send web requests every 25 minutes to some end point of the bot via web cron so that it does not sleep.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question