I am coding a telegram bot with nodejs using node-telegram-bot-api and I run the nodejs code on my windows 10 laptop, on command prompt, and it runs fine when my laptop is connected to Wifi but as soon I make my pc sleep, automatically my pc disconnects from the WiFi and my bot stops responding and i also receive some errors like:
error: [polling_error] {"code":"EFATAL","message":"EFATAL: Error: getaddrinfo ENOTFOUND api.telegram.org"}
.
I cannot keep my pc not in sleep mode all the time, so I wanted to know whether there is a way to prevent my pc from disconnecting from the Wifi even if it is in sleep mode. So that the bot runs all the time.
And also sometimes when my pc sleeps for a long time, the bot is stopped as soon I make my pc sleep but after few hours the bot is on again and my pc automatically connects to the wifi.
Also, I doubt that one more reason behind the stopping of my bot is that nodejs code stops when pc sleeps, so is this the case? And if yes then how to solve this?
And if there is no way to solve this, though I not prefer, is there any way in which I can run my bot on a server that is free and makes my bot run 24*7.
2
Answers
I don’t think that there is a solution to run your program in sleep mode. Though your node program can be run in sleep mode, but if you are requesting to online API then I think it is hard to work in sleep mode. So you can do one thing here.
You can host your app to http://www.heroku.com and this is free. you can use your bot 24X7. It is very simple to host your app.
This link has a great tutorial on bots and deployment to heroku. It is even written out on a gith https://dev.to/ishan0445/deploy-telegram-bot-to-heroku-for-free-telegram-bot-development-part-5-3p29