node-telegram-bot-api
node-telegram-bot-api copied to clipboard
problem with start and stop polling
hi when I do startPolling after the time I did stopPolling, the message events will be executed twice in each request. how can I solve it.
function(detail){
this.username = detail.username
this.token = detail.token;
this.bot = null;
this.botindex = detail.botindex;
this.adminWaitingList = [];
this.confige = detail.confige;
this.category = [];
this.menuItems = [];
this.start = function(){
this.load();
if(!this.bot) this.bot = new global.fn.telegramBot(this.token, {polling: true});
else if(!this.bot.isPolling()) this.bot.startPolling({'restart': false});
this.bot.index = this.botindex;
//Message
this.bot.on('message', (msg) => {
//console.log(msg.text);
msg.botindex = this.botindex;
global.fn.messageRouting.analyze(msg);
});
//callback
this.bot.on('callback_query', (query) => {
//console.log(query);
query.botindex = this.botindex;
global.fn.queryRouting.analyze(query);
});
}
this.stop = function(){
this.bot.stopPolling();
}
Sorry but, why not use
var bot = new TelegramBot(token, {polling: true});
and bot.Text functions?
Hi, @navidshad! Happy 2022! Mate, I am currently going thru the same issue and seems the project was abandoned. Would you mind to share any workarounds you did for this issue? I just want the polling to stop but stopPolling method does not work at all. As a matter of fact, after the stopPolling method is called, the bot still responds commands what makes clear the method shamely does not work. I appreciate any help or tips you may give.
Regards.
Hi @ebezerra-it Happy 2022 Actually, I had a look at my legacy codes, there was nothing for this solution, but you can start a child process for each token and then stop/start them again whenever you want. this is a better approach for having a bot manager.
https://www.section.io/engineering-education/nodejs-child-processes/
Hi @ebezerra-it Happy 2022 Actually, I had a look at my legacy codes, there was nothing for this solution, but you can start a child process for each token and then stop/start them again whenever you want. this is a better approach for having a bot manager.
https://www.section.io/engineering-education/nodejs-child-processes/
Thank for your solution, if you resolved it, can you explain more step by step ?