Naltox / telegram-node-bot

Node module for creating Telegram bots.
MIT License
723 stars 143 forks source link

Clustering #158

Open Phoscur opened 7 years ago

Phoscur commented 7 years ago

Looks like a cool feature, but really, generating duplicate messages by default sounds rather like a bug :P Please explain how to use it correctly and use zero as default worker count!

vsviridov commented 7 years ago

You can check something like

const client = new Telegram(...);
if(!client._workers)
{
  /* In worker instance */
}
else
{
  /* in master instance */ 
}

but having official client.isMaster or client.isWorker would be nice.

AndryFM commented 7 years ago

Is not that what you are looking for? https://github.com/Naltox/telegram-node-bot#clustering

const tg = new Telegram.Telegram('YOUR_TOKEN', {
    workers: 1
})

tg.sendMessage(123, 'test message') //will be sent 2 times (one time on master and one time on worker)

tg.onMaster(() => {
    tg.sendMessage(123, 'test message') //will be sent one time
})
Phoscur commented 7 years ago

Yes @AndryFM, that's what I'm refering to, and it should answer @vsviridov comment.

What I mean is, that this part is this very much undocumented besides that short paragraph. It does not explain

Currently, not reading the refered paragraph will produce weird duplicate messages. The default worker count should be zero, eliminating the need to know about clustering at all.