Introduction
This article will discuss where and how to host a Telegram bot. I'll cover all available options, from free to fairly paid ones.
Also, I want to emphasize that I won't be discussing the bot deployment process here. This is merely an introductory article, intended to familiarize the reader with the various hosting options available. More detailed instructions will be available via the links in the relevant chapters.
How and where can I host a bot?
Generally, all locations where bots can be hosted fall into one of the following categories:
| Virtual server (VPS/VDS) | This is a computer to which you have full access to software with root rights. |
| Shared hosting | This is a computer that gives you limited access to software without root rights. |
| Free hosting (allegedly) | It's the same hosting, but free (allegedly). It's either temporary or has serious limitations. |
| Your own hosting | This is the same hosting, but on your own computer. Full controll. |
| Category | Short description |
|---|
Initially, all my bots were hosted on a VPS from beget—it wasn't cheap. But at least I had absolute control, and I could create bots of any complexity.
Hosting Bots on a VPS/VDS
I've already written about how to host a telegram bot on virtual servers using Beget as an example, and described in detail the deployment mechanism and subsequent support. So I won't go into too much detail here.
I'll just say that this option is one of the most expensive (right after self-hosting), but it provides complete control and everything necessary to create and maintain a bot of any complexity.
There are plenty of this type of hosting options online, so I'll highlight the main ones that are definitely worth trying. They're simply cheaper than shared VPS (like DigitalOcean or Hostinger):
- TeleBotHos - a specialized service specifically for hosting bots
- JustRunMyApp - also a service for hosting telegram bots, but it offers even more.
Hosting bots on shared hosting
I'll be honest, this method isn't suitable for all bots. Some bots may have dependencies that require updating and configuring the server. This, in turn, requires superuser privileges, which you won't have.
Also, you need to consider the very serious space constraints. Web hosting services allocate very little space. Therefore, adhering to best practices won't work, meaning each bot will need its own virtual environment.
And one more thing. I'm not sure if this is the case with all web hosting providers, but on mine (Beget), launching a bot requires writing a script, and this script can only run for 10 hours.
Consequently, you'll also need to use a command like Crontab to ensure the bot can run continuously.
We'll need it to restart this script:
Let the script be called start.sh
This script launches the bot. Note that I'm launching the bot from a shared directory, and the virtual environment there is the same for everyone. Now let's add a crontab rule.
Typically, on any web hosting service, you can configure such rules through a graphical interface, specifying when to run the command. But if you don't have such an interface, you can write the rule manually:
This rule tells the scheduler to execute this script at the start of every hour, every day.
This way, you can launch and update bots on web hosting services not designed for this. Of course, this method has its own nuances and peculiarities, but a beggar can't be choosers.
Hosting Bots on *Free Hosting Services
There are also specialized services called PAAS services. Among them, I would include PythonAnywhere, which I've worked with and tested, as well as Replit, Heroku, Railway, Glitch, and Render...
It's important to understand that all of these services are shareware; some have limited RAM, some have a time limit, and some limit the number of programs that can be run. They are good for testing (and only for simple bots). This is a temporary solution that should eventually lead you either to setting up your own VPS or even further, to hosting bots on your own server. That is, of course, if you do anything more complex than a standard Echo Bot.
Hosting Bots on Your Own Server
This type of hosting is where any bot developer begins. Yes, running a bot from the console on your computer already qualifies as hosting it on your own server.
You could take this idea further and buy a Raspberry Pi, connect it and configure the network, install a basic server OS, like Debian, and run your bot there. It will be more expensive, probably 3–4 times more than a regular VPS, but you'll have complete control over your system.
You don't even have to buy anything; you can just use your old laptop, PC, or phone and run it from there. The main thing is that it's always staying online and has high bandwidth, otherwise... Well, I think that's obvious, it won't work.
There aren't any such experts on the internet yet; at least, Google hasn't shown me any. Well, as soon as I get rich, I'll get into this. But for now, let's move on to conclusions.
Results and Conclusions
Initially, I hosted the bots on a Beget VPS, and everything was fine until, due to objective circumstances, I ran out of money. I had to find a way around it and host the bots elsewhere.
At the time of writing this article, I've hosted the bots on a shared hosting service next to this website; they're literally in the next folder. This is a temporary solution that prevents me from running some bots. But soon I'll be moving the bots back to the VPS with full control and management of the environment.
What conclusions can I draw? Well, you need to have more money for your needs. Consider your capabilities. Try to design bots with the environment in mind when you plan to run them.