Telegram Bot - JS - Bot stops working after a while

Viewed 275

Devs! I created a simple bot for Telegram using JS language that when typing '/ tutorials' a txt list is loaded.

I deployed this bot to Heroku so that it goes online.

The problem is that the bot works for a while and then stops working, I don't know why.

Has anyone had this problem?

//Correction message error on console
process.env.NTBA_FIX_319 = 1;

var express = require('express');

var app = express();

app.set('port', (process.env.PORT || 5000));

const TelegramBot = require('node-telegram-bot-api')

const TOKEN = 'myToken'

const bot = new TelegramBot(TOKEN, { polling: true })

bot.on('message', (msg) => {

  const chatId = msg.chat.id;
  const text = msg.text;

  //read list txt
  var fs = require('fs');
  try {
    var data = fs.readFileSync('lista.txt', 'utf8');
  } catch (e) {
    console.log('Error:', e.stack);
  }

  //send message

  if (text.includes('/tutoriais')) {
    bot.sendMessage(chatId, `Olá, ${msg.chat.first_name}! \nLista de Tutoriais`)
    bot.sendMessage(chatId, data);
  }
});
1 Answers
Related