9

Is there a way to programmatically determine the number of participants in a WhatsApp group ?
(like API's, web scraping or something ?)

I want to make few WhatsApp groups(eg: group 1, group 2), and store invite links to a backend. On visiting the server, it'll check if group1 count is less than 256, if no, checks group2 count and so on and returns the first link that isn't full. So it'll be possible to enroll to multiple groups with a single link.


This question might also be a solution for:
How to automatically redirect people to several WhatsApp groups when limit is full ?
How to add more than 256 people in a WhatsApp group(not possible) ?

Steev James
  • 2,396
  • 4
  • 18
  • 30

1 Answers1

0

It seems that the topic is still relevant, given the ongoing questions in the comments. First, let me clarify that you can't add more than 256 people to a WhatsApp group; that's a limitation set by WhatsApp itself. However, automating group management can be done fairly easily. I personally use Whapi.Cloud for my work. Here's what you can do:

That provider offers a method for gathering information about groups and their members. This way, you can check how many participants are already in each group. They also have an API method to create an invitation to a group. This means you can generate and save the invite links on your end, just as you wanted to. You can easily implement user redirection on your server by checking the number of participants in each group and then redirecting the user to the first group that's not yet full.

const request = require('request');
            
            // Your API token
            const apiToken = 'FMjkgWhiIIWBOaQEd44pJXpYiKrrQdNX';
            
            // Function to get information about all groups
            function getGroupInfo(callback) {
              const options = {
                method: 'GET',
                url: `https://gate.whapi.cloud/groups?count=100&token=${apiToken}`,
                headers: { accept: 'application/json' }
              };
              request(options, function (error, response, body) {
                if (error) throw new Error(error);
                callback(JSON.parse(body));
              });
            }
            
            // Function to generate an invite link for a group
            function generateInviteLink(groupId, callback) {
              const options = {
                method: 'GET',
                url: `https://gate.whapi.cloud/groups/${groupId}/invite?token=${apiToken}`,
                headers: { accept: 'application/json' }
              };
              request(options, function (error, response, body) {
                if (error) throw new Error(error);
                callback(JSON.parse(body).inviteLink);
              });
            }
            
            // Function to find a group with less than 256 members and return its invite link
            function getAvailableGroupLink(callback) {
              getGroupInfo(function(groups) {
                for (let group of groups) {
                  const memberCount = group.members.length;  // Assume 'members' is an array of group members
                  if (memberCount < 256) {
                    generateInviteLink(group.id, function(inviteLink) {
                      callback(inviteLink);
                      return;
                    });
                    return;
                  }
                }
                callback('All groups are full.');
              });
            }
            
            // Example usage
            getAvailableGroupLink(function(link) {
              if (link !== 'All groups are full.') {
                console.log(`Redirect the user using this link: ${link}`);
              } else {
                console.log('All groups are full.');
              }
            });

If anything a list of all methods is here: https://whapi.cloud/docs. Take the methods I've listed and there are many more additional useful ones out there. I hope this helps!

UPD Apparently there's been a slight change. I double-checked now, you need the /getgroup method. The response will be the participants parameter (array of objects). That's what you need to count.

Hafiz
  • 39
  • 3