node-telegram-bot-api icon indicating copy to clipboard operation
node-telegram-bot-api copied to clipboard

problem with start and stop polling

Open navidshad opened this issue 7 years ago • 3 comments

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();
    }

navidshad avatar Feb 06 '18 19:02 navidshad

Sorry but, why not use

var bot = new TelegramBot(token, {polling: true});

and bot.Text functions?

sidelux avatar Mar 02 '18 15:03 sidelux

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.

ebezerra-it avatar Jan 02 '22 18:01 ebezerra-it

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/

navidshad avatar Jan 02 '22 20:01 navidshad

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 ?

annguyen97dev avatar Dec 07 '22 14:12 annguyen97dev