A
A
Arsen Gabdulin2020-05-02 08:59:20
Node.js
Arsen Gabdulin, 2020-05-02 08:59:20

My telegram bot is crashing on Heroku. Who knows how to fix it?

Here are the logs:

2020-05-01T17:03:06.216123+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-01T17:08:01.589061+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=csguidesbot.herokuapp.com request_id=d9689bbd-f7a1-44ba-8434-2689514277ab fwd="5.34.73.29" dyno= connect= service= status=503 bytes= protocol=https
2020-05-01T17:08:02.330847+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=csguidesbot.herokuapp.com request_id=62de5dc1-7805-4f77-ae7d-f548e6e0e794 fwd="5.34.73.29" dyno= connect= service= status=503 bytes= protocol=https
2020-05-01T17:08:02.557764+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=csguidesbot.herokuapp.com request_id=c4c4f50a-be3b-45c5-8edb-36f5ce7dd4eb fwd="5.34.73.29" dyno= connect= service= status=503 bytes= protocol=https

Bot.js (the rest is bot logic):
const Telegram = require('node-telegram-bot-api');
const bot = new Telegram("Токен", {
polling: true
})

const API_PORT = process.env.PORT || 3000

console.log("Bot запущен")

Procfile:
web: node bot.js
package.json:
{
"name": "cs_guides",
"version": "1.0.0",
"description": "",
"main": "bot.js",
"scripts": {
"start": "node bot.js",
"test": "echo "Error: no test specified" && exit 1"
},
"engines": {
"node": "12.16.3"
},

"author": "",
"license": "ISC",
"dependencies": {
"node-telegram-bot-api": "^0.40.0"
},
"devDependencies": {
"nodemon": "^2.0.3"
}
}


The bot works on LAN without errors and crashes. Compiled on my VS code.

First, after uploading the commit, the bot works fine for ~5 minutes. After it crashes and from 1 minute to 5 minutes it does not work and starts. Who knows what can be done to solve the problem or at least reduce the time the bot is not working.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bittenmuskrat, 2020-05-02
@bittenmuskrat

Heroku is famous for its unstable work with telegram bots. You are not the only one experiencing such difficulties. Many bots get stuck or fall asleep while working.
Possible solutions:
1) Restart the bot on exit. I can not give the code - I write it myself in another language.
2) Use a different hosting for the bot. I use paid. There are no problems with sticking the bot.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question