V
V
Vlad2016-09-11 23:01:55
Clustering
Vlad, 2016-09-11 23:01:55

How to cluster a bot on Node.js for Telegram?

Hello everyone) I recently started writing a bot for Telegram in JavaScript (Node.js). I already taught him how to work with both MySQL and Redis, but at one fine moment I decided to check how much faster it would work if the bot was clustered. I installed the “PM2” module and launched the bot with the following command: “pm2 start app.js –i 2”. The result surprised me a little, although it should not have surprised me. The whole joke is that I use Long Polling requests to get updates from Telegram servers. And if you run an echo-bot (a bot that repeats a sent message) using the “pm2” module, which also receives updates via Long Polling requests, it will repeat the message sent to it twice. That is, I write to him, for example, “Hello!”, And he sends me two such messages “Hello!” "Hello!", not just one. In other words, bot
Hence the question: How can you cluster a bot that uses Long Polling requests to receive updates?
The only option, as I understand it, is to use the built-in "cluster" module, but maybe someone else will offer something) I would be grateful for any help :)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question