please select
  • UIKit
  • SDK
  • Server APIs
Chat/
SDK/
Unity(Game Solution)/
Group/
SDK
  • Run Demo
  • SDK Integration
  • Initialization
  • Login and Logout
  • Message
    • Message Overview
    • Sending Message
    • Receiving Message
    • Historical Message
    • Forwarding Message
    • Modifying Message
    • Deleting Message
    • Clearing Messages
    • Recalling Message
    • Online Message
    • Read Receipt
    • Querying Message
    • Group @ Message
    • Targeted Group Message
    • Notification Muting
    • Message Extension
  • Conversation
    • Conversation Overview
    • Conversation List
    • Getting Conversation
    • Conversation Unread Count
    • Pinning Conversation to the Top
    • Deleting Conversation
    • Conversation Draft
    • Conversation Mark
    • Conversation Group
  • Group
    • Group Overview
    • Group Management
    • Group Profile
    • Group Member Management
    • Group Member Profile
    • Custom Group Attribute
    • Group Counter
  • User
    • User Profile
    • User Status
    • Friend Management
    • Friend List
    • Blocklist
  • Changelog
  • Guideline for Beginners
  • Console Guide
    • Creating and Upgrading an Application
    • Basic Configuration
    • Feature Configuration
    • Account Management
    • Group Management
    • Webhook Configuration
  • Product Introduction
    • Message Management
      • One-to-One Message
      • Message Storage
      • Offline Push
      • Group Message
      • Message Formats
    • Account System
      • Login Authentication
      • Online Status Management
    • Group Related
      • Group System
      • Group Management
    • User Profile and Relationship Chain
      • Profile Management
      • Relationship Chain Management
  • Purchase Guide
    • Billing Overview
    • Pricing
  • Error Codes

Group Management

Feature Description

The group management feature allows creating a group, joining a group, getting the joined groups, leaving a group, or disbanding a group.


Group Event Listener

In the group management feature as described below, the IM SDK will automatically trigger the group event notification callback, for example, when someone joins or leaves a group.
Call SetGroupTipsEventCallback (Details) to add a group event listener.
To stop receiving group events, call SetGroupTipsEventCallback again (Details) and pass in null to remove the group event listener.
Caution:
You need to set the group event listener in advance to receive group event notifications.
Sample code:
TencentIMSDK.SetGroupTipsEventCallback((GroupTipsElem message, string user_data)=>{
// Process the callback logic
});

Creating a Group

To initialize the group information such as group introduction, group profile photo, and existing group members when creating a group, call the GroupCreate advanced API (Details), and the create_group_result_groupid will be returned in the callback for successful creation.
Sample code:
// Create a public group and specify group attributes
CreateGroupParam param = new CreateGroupParam
{
create_group_param_group_id = "group_id",
create_group_param_group_name = "group_name",
create_group_param_group_type = TIMGroupType.kTIMGroup_Public,
create_group_param_add_option = TIMGroupAddOption.kTIMGroupAddOpt_Any,
};

TIMResult res = TencentIMSDK.GroupCreate(param, (int code, string desc, CreateGroupResult result, string user_data)=>{
// Process the async logic
});


Joining a Group

The method for joining a group may vary by group type as follows:
Type
Method for Joining a Group
Work group (Work)
By invitation
Public group (Public)
On request from the user and on approval from the group owner or admin
Meeting group (Meeting)
Free to join
Community (Community)
Free to join
Audio-video group (AVChatRoom)
Free to join
The following describes how to join the groups in an easy-to-hard sequence.
Caution:
You need to call SetGroupTipsEventCallback to add a group event listener in advance to receive the following group events.

Free to join a group

Meeting groups (Meeting), audio-video groups (AVChatRoom), and communities are mainly used for free interaction scenarios, such as online meeting and live show. The process of joining such groups is the simplest:
1. The user calls GroupJoin (Details) to join the group.
2. After the user has successfully joined the group, all the group members (including the user) will receive the GroupTipsEventCallback callback (Details).
Sample code:
// Listen for the group join event
TencentIMSDK.SetGroupTipsEventCallback((GroupTipsElem message, string user_data)=>{
// Process the callback logic
});


// Join a group
TIMResult res = TencentIMSDK.GroupJoin(group_id, "greeting message", (int code, string desc, string user_data)=>{
// Process the async logic
});

Joining a group by invitation

Resembling WeChat and WeCom groups, work groups (Work) are suitable for communication in work environments. The interaction pattern is designed to disable proactive group joining and only allow users to be invited to join the group by group members. The steps to join a group are as follows:
1. A group member calls GroupInviteMember (Details) to invite a user to the group.
2. All the group members (including the user) will receive the GroupTipsEventCallback callback (Details).
Sample code:
// Listen for the group invitation event
TencentIMSDK.SetGroupTipsEventCallback((GroupTipsElem message, string user_data)=>{
// Process the callback logic
});


// Invite the `userA` user to join the `groupA` group
GroupInviteMemberParam param = new GroupInviteMemberParam
{
group_invite_member_param_group_id = "group_id",
group_invite_member_param_identifier_array = new List<string> {
"1234"
} // Array of IDs of the users invited to the group
};
TIMResult res = TencentIMSDK.GroupInviteMember(param, (int code, string desc, List<GroupInviteMemberResult> result, string user_data)=>{
// Process the async logic
});

Joining a group on request and on approval

A public group (Public) is similar to the interest group and clan group of QQ. Anyone can join it on request and on approval from the group owner or admin.
Description of process:
1. Set the callback for a group system message SetGroupTipsEventCallback (Details).
2. The user calls GroupJoin (Details) to request to join the group.
3. The group owner or admin traverses the group join request list and calls GroupHandlePendency (Details) to approve/reject the request.
4. On approval, all the group members (including the user) will receive the SetGroupTipsEventCallback callback (Details), notifying the group members that someone joined the group.
The group owner or admin can also call the GroupModifyGroupInfo API (Details) to change the group join option (group_modify_info_param_add_option) to "no group join allowed" or "no approval required".
group_modify_info_param_add_option has the following options:
Group Join Option
Description
TIMGroupAddOption.kTIMGroupAddOpt_Forbid
No users can join the group.
TIMGroupAddOption.kTIMGroupAddOpt_Auth
Approval from the group owner or admin is required to join the group (default value).
TIMGroupAddOption.kTIMGroupAddOpt_Any
Any user can join the group without approval.

Getting the Joined Groups

Call GroupGetJoinedGroupList (Details) to get the list of joined work groups (Work), public groups (Public), meeting groups (Meeting), and communities (Community, which don't support the topic feature). Audio-video groups (AVChatRoom) and communities (Community, which support the topic feature) are not included in this list.
Sample code:
// Get the joined groups
TIMResult res = TencentIMSDK.GroupGetJoinedGroupList((int code, string desc, List<GroupBaseInfo> info_list, string user_data)=>{
// Process the async logic
});


Leaving a Group

Call GroupQuit (Details) to leave a group. Other group members will receive the SetGroupTipsEventCallback callback (Details).
Caution:
The group owner cannot leave a public group (Public), meeting group (Meeting), community, or audio-video group (AVChatRoom) and can only disband it.
Sample code:
// Leave a group
TIMResult res = TencentIMSDK.GroupQuit(group_id, (int code, string desc, string user_data)=>{
// Process the async logic
});


Disbanding a Group

Call GroupDelete (Details) to disband a group, and all the group members will receive the SetGroupTipsEventCallback callback (Details).
Sample code:
// Disband a group
TIMResult res = TencentIMSDK.GroupDelete(group_id, (int code, string desc, string user_data)=>{
// Process the async logic
});