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

Telegram-node-bot 1 worker with firebase child_added

Open livioalves opened this issue 8 years ago • 1 comments

Telegram-node-bot V4 is causing Firebase child_added to fire twice for the same child, while on V3 its working fine. I had to downgrade to V3 to solve the problem.

Sample code:

const Telegram = require('telegram-node-bot'); const TelegramBaseController = Telegram.TelegramBaseController; const tg = new Telegram.Telegram('');

var Firebase = require('firebase');

var config = { apiKey: '', databaseURL: " serviceAccount: '' };

Firebase.initializeApp(config);

var Items = Firebase.database().ref('path');

Items.on('child_added', function (snapshot) { var item = snapshot.val(); SendToTopic(item.topic, item.data);

})

function SendToTopic (topic, message) {

var subscribers = Firebase.database().ref('sub' );
subscribers.once('value', function (snapshot) {
	snapshot.forEach(
		item => { 
			tg.api.sendMessage(item.key, message); 
		}
	);
});

}

livioalves avatar Jan 24 '17 02:01 livioalves

Are you can use this solution: 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
})

AndryFM avatar Feb 06 '17 18:02 AndryFM