Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to grab group name or group Id #25

Open
Hendroarifin opened this issue May 19, 2024 · 1 comment
Open

How to grab group name or group Id #25

Hendroarifin opened this issue May 19, 2024 · 1 comment

Comments

@Hendroarifin
Copy link

Hendroarifin commented May 19, 2024

i use client.get_joined_groups but not all group can grab

@lfaltoni
Copy link

lfaltoni commented Oct 6, 2024

i use client.get_joined_groups but not all group can grab

Check this script to find group structure, it will return protobuf structure for the first group.

# Run and press CTRL + C to see output.

from neonize.client import NewClient
from neonize.exc import GetJoinedGroupsError  # Updated import statement

def main():
    # Create a new client instance
    client = NewClient(name="MyClient")

    # Connect to WhatsApp
    client.connect()

    # Get joined groups
    try:
        # Assuming you have a method to get groups
        groups = client.get_joined_groups()
        
        print(f"Number of groups retrieved: {len(groups)}")
        
        # Print details of the first group
        if groups:
            first_group = groups[0]
            print("First group details:")
            
            # Access the group ID and name
            group_id = first_group.JID.User if hasattr(first_group, 'JID') else 'ID not available'
            group_name = first_group.GroupName.Name if hasattr(first_group, 'GroupName') else 'Subject not available'
            
            # Access participants
            if hasattr(first_group, 'Participants'):
                participants = first_group.Participants
                group_admins = [p.JID.User for p in participants if p.IsAdmin]  # List of admin JIDs
                group_admins_display = ', '.join(group_admins) if group_admins else 'No admins'
            else:
                group_admins_display = 'No participants'
            
            print(f"ID: {group_id}")
            print(f"Subject: {group_name}")
            print(f"Admins: {group_admins_display}")
        else:
            print("No groups found.")

    except GetJoinedGroupsError as e:
        print(f"Error retrieving groups: {e}")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

if __name__ == "__main__":
    main()

Look for this output:

Number of groups retrieved: number-of-groups-here
First group details:
ID: group-id-here
Subject: group-name-here
Admins: admin-phone-number(s)-here

ID must be turned into JID format which is defined in neonize/utils/jid.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants