R
R
Rostislav2020-05-28 12:35:10
JavaScript
Rostislav, 2020-05-28 12:35:10

Telegram bot freezes (hiroku hosting)?

There is a bot (test - training)
Bot on js
The bot itself is uploaded to heroku.com It starts
, works and freezes
Here is the log:

2020-05-28T08:43:50.357758+00:00 app[web.1]: 
2020-05-28T08:43:50.357767+00:00 app[web.1]: > [email protected] start /app
2020-05-28T08:43:50.357767+00:00 app[web.1]: > node bot.js
2020-05-28T08:43:50.357768+00:00 app[web.1]: 
2020-05-28T08:43:50.855446+00:00 app[web.1]: Бот запущен
2020-05-28T08:43:51.418671+00:00 heroku[web.1]: State changed from starting to up
2020-05-28T09:15:25.299481+00:00 heroku[web.1]: Idling
2020-05-28T09:15:25.302593+00:00 heroku[web.1]: State changed from up to down
2020-05-28T09:15:26.699556+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2020-05-28T09:15:26.895990+00:00 heroku[web.1]: Process exited with status 143
2020-05-28T09:18:17.833275+00:00 heroku[web.1]: State changed from down to starting
2020-05-28T09:18:21.545626+00:00 heroku[web.1]: Starting process with command `npm start`
2020-05-28T09:18:23.710890+00:00 app[web.1]: 
2020-05-28T09:18:23.710905+00:00 app[web.1]: > [email protected] start /app
2020-05-28T09:18:23.710905+00:00 app[web.1]: > node bot.js
2020-05-28T09:18:23.710905+00:00 app[web.1]: 
2020-05-28T09:18:24.501667+00:00 heroku[web.1]: State changed from starting to up
2020-05-28T09:18:24.335618+00:00 app[web.1]: Бот запущен

Here is the bot code:
require('dotenv').config();
const { Telegraf } = require('telegraf');
const api = require('covid19-api');
const markup = require('telegraf/markup');
const COUNTRIES_LIST = require(`./constants`);
const bot = new Telegraf(process.env.BOT_TOKEN);

require('https')
  .createServer()
  .listen(process.env.PORT || 5000)
  .on('request', function (req, res) {
    res.end('');
  });

bot.start((ctx) =>
  ctx.reply(
    `
Привет ${ctx.message.from.first_name}!
Узнай статистику по Коронавирусу.
Введи на англ. название страны и получи статистику.
Посмотреть название всех стран: /help.
`,
    markup
      .keyboard([
        [`Ukraine`, `Russia`],
        [`US`, `Italy`],
        [`Canada`, `Portugal`],
      ])
      .resize()
      .extra()
  )
);
bot.help((ctx) => ctx.reply(COUNTRIES_LIST));

// bot.start((ctx) => console.log(ctx));

bot.on('text', async (ctx) => {
  let data = {};

  try {
    data = await api.getReportsByCountries(ctx.message.text);

    const formatData = `
Страна : ${data[0][0].country}
Заболевшие : ${data[0][0].cases}
Смертей : ${data[0][0].deaths}
Вылечились : ${data[0][0].recovered}
  `;
    ctx.reply(formatData);
  } catch {
    ctx.reply(`ошибка: такой страны нет. Смотри /help`);
  }
});

bot.launch();
console.log(`Бот запущен`);


the worker has not yet appeared in the Resources tab,
5ecf84b645716359944212.png
although the procfile file has been created and there is a worker line in it: npm start
5ecf850a1b84b516292338.png
Here is the bot stop log
5ecf8576c36ba978653561.png
Please help - how to add a worker and why does the bot crash?
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
a, 2020-05-28
@MZOK

If you use a free plan, then if there are no requests for the application for 30 minutes, then it turns itself off. In order for him not to fall asleep, use - wakemydyno.com.
To add a worker enter the command - heroku ps:scale worker=1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question