Quick Reference for AI Agents & DevelopersNote: Only admins and moderators can add members. The result HashMap contains UID as key and “success” or error message as value.
Add Members to Group
You can add members to the group using theaddMembersToGroup() method. This method takes the below parameters:
GUID- GUID of the group users are to be added to.List<GroupMember> members- This is a list ofGroupMemberobjects. In order to add members, you need to create an object of theGroupMemberclass. TheUIDand the scope of theGroupMemberare mandatory.List<String> bannedMembers- This is the list ofUIDsthat need to be banned from the group. This can be set tonullif there are no members to be banned.- Callback
- Java
- Kotlin
onSuccess() method of the CallbackListener, you will receive a HashMap which will contain the UID of the users and the value will either be success or an error message describing why the operation to add the user to the group or ban the user failed.
Real-Time Group Member Added Events
How do I know when someone is added to the group while my app is running?When a group member is added by another member, this event is triggered. When a user joins a group on their own, the joined event is triggered.
onMemberAddedToGroup() method of the GroupListener class.
onMemberAddedToGroup()- This method is triggered when any user is added to the group, informing the logged-in user of the other members added to the group.
- Java
- Kotlin
Member Added to Group event in Message History
How do I know when someone is added to the group while my app is not running? When you retrieve the list of previous messages, if a member has been added to any group that the logged-in user is a member of, the list of messages will contain anAction message. An Action message is a sub-class of the BaseMessage class.
For the group member added event, in the Action object received, the following fields can help you get the relevant information-
action-addedactionOn- User object containing the details of the user who was added to the groupactionBy- User object containing the details of the user who added the member to the groupactionFor- Group object containing the details of the group to which the member was added
Best Practices
Assign Appropriate Scopes
Assign Appropriate Scopes
Choose member scopes carefully: ADMIN for full control, MODERATOR for moderation tasks, PARTICIPANT for regular members. Limit admin count to maintain control.
Batch Add Members
Batch Add Members
Add multiple members in a single call instead of multiple individual calls to improve performance and reduce API overhead.
Handle Partial Success
Handle Partial Success
Check the result HashMap for each UID - some additions may succeed while others fail. Handle each case appropriately in your UI.
Validate UIDs Before Adding
Validate UIDs Before Adding
Verify user UIDs exist before attempting to add them to avoid unnecessary API errors.
Troubleshooting
Add Failed - Insufficient Permissions
Add Failed - Insufficient Permissions
Symptom:
addMembersToGroup() fails with “Insufficient permissions” error.Cause: User is not an admin or moderator of the group.Solution: Only admins and moderators can add members. Check the user’s scope before showing add member options.Some Members Not Added
Some Members Not Added
Symptom: Result HashMap shows errors for some UIDs.Cause: UIDs may not exist, users may already be members, or users may be banned.Solution: Check the error message for each UID in the result HashMap. Verify UIDs exist and users aren’t already members or banned.
Cannot Add to Private Group
Cannot Add to Private Group
Symptom: Adding members to private group fails.Cause: Private groups have restricted membership.Solution: Ensure you have admin or moderator permissions. Private groups require explicit member additions by authorized users.