I've a node.js application that get some bot telegram token and run them as a bot.
I use telegraf module.
But when a bot receive too many request or throw an error and then crashed, this happen for the others bot.
What can i do to solve this problem.
I want the bots to be separate from each other.
A way is Copying my code and run the bots as multi script separately.
But i have many bot so it's impossible.
Here is my code to run the bots:
const Telegraf = require('telegraf');
var {Robots} = require('./model/models/robots');
var botsList = [];
setInterval(() => {
Robots.find({bot_type: 'group manager'}).then((res) => {
if(res.length > 0){
var tokens = [];
for(var i = 0 ; i < res.length ; i++){
var newToken = res[i].token;
tokens.push(newToken);
}
var bot = [];
tokens.map(token => {
if(!botsList.includes(token)){
botsList.push(token);
var botUserId = token.split(':')[0];
bot[botUserId] = new Telegraf(token);
module.exports = {
bot
};
const Commands = require('./controller/commands/commands.js');
bot[botUserId].on('text', (ctx) => {
Commands.executeCommand(bot[botUserId], ctx);
});
bot[botUserId].startPolling();
}
});
}
}).catch(console.log);
}, 5000);