Websocket goes to sleep after a while

websocket goes to sleep after a while. I listen to the transfer events of a contract and send a message to telegram. but after a while it starts not being able to catch the events.

const Web3 = require("Web3")
var web3;
const abi = require('./abi.json') 
const express = require('express');

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

const app = express();
const port = 3002;
var bodyParser = require('body-parser');
var cors = require('cors')
app.use(bodyParser.urlencoded({ extended: false }))
const provider = new Web3.providers.WebsocketProvider("WEB_SOCKET_URL_FROM_SPEEDY_NODES")
web3 = new Web3(provider);
contract = new web3.eth.Contract(abi, "CONTRACT_ADDRESS");
    contract.events.Transfer({}).on("data", (data) => {
          try {
            //const bot = new TelegramBot(token, { polling: true });
                try {
                    // bot send message
                } catch (error) {

           } catch (err) {


module.exports = app

we recommend to use event sync on a server:

with web sockets, they may disconnect from time to time
you can also try another node provider if you want to use websockets