Search code examples
node.jsfacebook-graph-apichatbotfacebook-chatbot

want to make 'X Post' request every N seconds with Nodejs ( i'm working on facebook chatbot so i wanna make 250 Post Request every second )


I would like to do the following

  1. I want to make 250 Post request Every 1 Second.
  2. When I use the benchmark to choose the best Module for Request, it shows that superAgent is the fastest one to solve slow time request but still have this problem.

Will the following code help me to do that?

1 - iterate though users

2- Push requests to myRequests Array

for (var i = 0; i < 1000000; i++) {
  //console.log(i);
  myRequests.push(function(callback) {
    request.get(
      "https://graph.facebook.com/v2.6/me/messages",
      {
        qs: {
          access_token: "55"
        },
        json: {
          recipient: {
            id: users[i]
          },
          message: "55"
        }
      },
      (err, res) => {
        callback(null);
      }
    );
  });
}

`

3- Set ParallelLimit to 250

async.parallelLimit(
    myRequests, 250, function(err, results) {
});

`


Solution

  • The slowest part is most likely the request to Facebook, no matter if you use superagent, axios or something else. If you want to broadcast messages, better use the Broadcast API: