In what environment should I write the code for the telegram bot so that it works even when the console is not running?
I tried to write code in an online environment, but when I turn it off, the bot does not work.
This depend from the OS you are using (es. Windows, Ubuntu 18.04 etc.), and also from which programming language and which version of it you are  using (es. "python 3.6"). 
If you want to have the code always available to be executed, you need to put the script or the scripts in a server (a dedicated computer) always turned on,you can rent one online or you can do it and set up one by yourself , but this need some knowledge before, and depends on which kind of things you want from your server.
If you're still in the early stage of the bot-development i suggest you to use your localhost or local environment in general to test your work, in this way you can focus to one thing at time , useful especially in your first experiences in developing and coding. If it's not strictly necessary i would focus at one thing at time to learn better step by step.
In what environment should I write the code for the telegram bot so that it works even when the console is not running?