Telegram bot stops working after some period of time.
I uploaded a simple telegram bot to google-aplication-engine. And after uploading it works as expected some time. Then it stoped respond to request from telegram. The bot is very simple, it uses github.com/go-telegram-bot-api/telegram-bot-api package.
func main() {
bot, err := tba.NewBotAPI("apitockenhere")
var ucfg tba.UpdateConfig = tba.NewUpdate(0)
ucfg.Timeout = 60
uchan, err := bot.GetUpdatesChan(ucfg)
if err != nil {
log.Println(err)
}
...
for {
select {
case update := <-uchan:
...
}
}
}
If I open web application in browser (it doesnot contais any handlers so it opens nothing) then telegram bot again starts working some time and then stops.
It works as expected localy but there is probably some issues with GAE.
How to modify the code to prevent it from stopping?
I noticed that if I close browser then after some period of time telegram bot also stops working.
It sounds like you bumped into GAE’s scheduling control, where if the app is unattended (idle) for more than 30 seconds, that app will be shut-down automatically and enters wake-up request mode.
You have a choice:
Set a minimum idle instance (under manual scaling which cost $$$)
Use application like Kaffine for Heroku or cron job machine to periodically ping the bot server for avoiding shutdown mode.
Use GCE VM instead of GAE.
You can bring this matter to your Google Cloud tech assistant in your Google Cloud Console for advice.