createGroup
Description
info
(1) The creator creates a group as the group owner and specifies the group administrator and ordinary group members. After success, all members enter the group immediately;
(2) It is recommended that the maximum number of group members at a time is 1000, because too many members may cause the data packet to be too large and rejected by the backend.
Note
(1) If groupID is specified, then groupID cannot be repeated;
(2) If groupID is not specified, the server will generate a unique groupID.
Related Callbacks:
onJoinedGroupAdded
onGroupMemberAdded
- iOS
- Android
- Flutter
- uni-app
- Browser/Electron/MiniProgram
- React-Native
- Unity
Function Prototype
Future<GroupInfo> createGroup({
required GroupInfo groupInfo,
List<String> memberUserIDs = const [],
List<String> adminUserIDs = const [],
String? ownerUserID,
String? operationID,
})
Input Parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| groupInfo | GroupInfo | Yes | Group info |
| memberUserIDs | List<String> | Yes | List of invited group members |
| adminUserIDs | List<String> | No | List to invite and set as administrators |
| ownerUserID | String | No | Group owner |
Return Result
| Parameter Name | Parameter Type | Description |
|---|---|---|
| ~ | GroupInfo | Success |
Code Example
final groupInfo = await OpenIM.iMManager.groupManager.createGroup(
groupInfo: GroupInfo(
groupID: '',
groupName: groupName,
faceURL: faceURL,
groupType: GroupType.work,
),
memberUserIDs: allList.where((e) => e.userID != OpenIM.iMManager.userID)
.map((e) => e.userID!)
.toList(),
);
// todo
Function Prototype
- (void)createGroup:(OIMGroupCreateInfo *)groupCreateInfo
onSuccess:(nullable OIMGroupInfoCallback)onSuccess
onFailure:(nullable OIMFailureCallback)onFailure;
Input Parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| groupCreateInfo | OIMGroupCreateInfo | Yes | Initialization info during creation |
Return Result
| Parameter Name | Parameter Type | Description |
|---|---|---|
| onSuccess | OIMGroupInfo | Success |
| onFailure | OIMFailureCallback | Failure |
Code Example
OIMGroupCreateInfo *group = [OIMGroupCreateInfo new];
group.groupName = @"";
group.introduction = @"";
[OIMManager.manager createGroup:group
onSuccess:^(OIMGroupInfo * _Nullable groupInfo) {
} onFailure:^(NSInteger code, NSString * _Nullable msg) {
}];
Function Prototype
public void createGroup(List<String> memberUserIDs, List<String> adminUserIDs,
GroupInfo groupInfo, String ownerUserID, OnBase<GroupInfo> callBack)
Input Parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| groupInfo | GroupInitInfo | Yes | Group basic info |
| memberUserIDs | string[] | Yes | List of invited group members |
| adminUserIDs | string[] | No | List to invite and set as administrators |
| ownerUserID | string | No | Group owner ID |
| callBack | OnBase<GroupInfo> | Yes | Callback interface |
Return Result
Code Example
OpenIMClient.getInstance().groupManager.createGroup(memberUserIDs, adminUserIDs,
groupInfo, ownerUserID, new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
});
Function Prototype
IMSDK.createGroup({
groupInfo:Partial<GroupItem>,
memberUserIDs: string[],
adminUserIDs?: string[],
ownerUserID?: string
}, operationID?: string): Promise<WsResponse<GroupItem>>
Input Parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| groupInfo | Partial<GroupItem> | Yes | Group basic info |
| memberUserIDs | string[] | Yes | List of invited group members |
| adminUserIDs | string[] | No | List to invite and set as administrators, mutually exclusive with member list |
| ownerUserID | string | No | Group owner ID, defaults to current user ID |
Return Result
| Parameter Name | Parameter Type | Description |
|---|---|---|
| Promise.then() | Promise<WsResponse<GroupItem>> | Success callback |
| Promise.catch() | Promise<WsResponse> | Failure callback |
Code Example
import { getSDK } from '@openim/wasm-client-sdk';
const IMSDK = getSDK();
// use in electron with ffi
// import { getWithRenderProcess } from '@openim/electron-client-sdk/lib/render';
// const { instance: IMSDK } = getWithRenderProcess();
// use in mini program
// import { getSDK } from '@openim/client-sdk';
// const IMSDK = getSDK();
IMSDK.createGroup({
groupInfo: {
groupName: '',
groupType: 2,
},
memberUserIDs: [''],
})
.then(() => {
// Success
})
.catch(({ errCode, errMsg }) => {
// Failure
});
Function Prototype
IMSDK.asyncApi('createGroup', operationID: string, {
groupInfo: Partial<GroupItem>,
memberUserIDs: string[],
adminUserIDs?: string[],
ownerUserID?: string
}): Promise<GroupItem>
Input Parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| operationID | string | Yes | Operation ID, used to pinpoint issues, keep unique, prefer time+random |
| groupInfo | Partial<GroupItem> | Yes | Group basic info |
| memberUserIDs | string[] | Yes | List of invited group members |
| adminUserIDs | string[] | No | List to invite and set as administrators |
| ownerUserID | string | No | Group owner ID |
Return Result
Use the
openim-uniapp-polyfillpackage to make the function Promise. When calling, you need to usethenandcatchto determine and handle success and failure callbacks.
| Parameter Name | Parameter Type | Description |
|---|---|---|
| Promise.then() | Promise<GroupItem> | Success callback |
| Promise.catch() | Promise<CatchResponse> | Failure callback |
Code Example
import IMSDK from 'openim-uniapp-polyfill';
IMSDK.asyncApi('createGroup', IMSDK.uuid(), {
groupInfo: {
groupName: '',
groupType: 2,
},
memberUserIDs: [''],
})
.then((data) => {
// Success
})
.catch(({ errCode, errMsg }) => {
// Failure
});
Function Prototype
OpenIMSDK.createGroup({
groupInfo: Partial<GroupItem>,
memberUserIDs: string[],
adminUserIDs?: string[],
ownerUserID?: string
}, operationID?: string): Promise<GroupItem>
Input Parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| groupInfo | Partial<GroupItem> | Yes | Group basic info |
| memberUserIDs | string[] | Yes | List of invited group members |
| adminUserIDs | string[] | No | List to invite and set as administrators |
| ownerUserID | string | No | Group owner ID |
| operationID | string | No | Operation ID, used to pinpoint issues, keep unique, prefer time+random |
Return Result
| Parameter Name | Parameter Type | Description |
|---|---|---|
| Promise.then() | Promise<GroupItem> | Success callback |
| Promise.catch() | Promise<OpenIMApiError> | Failure callback |
Code Example
import OpenIMSDK from "@openim/rn-client-sdk";
OpenIMSDK.createGroup({
groupInfo: {
groupName: '',
groupType: 2,
},
memberUserIDs: [''],
})
.then((data) => {
// Success
})
.catch((error) => {
// Failure
});
Function Prototype
public static void CreateGroup(OnBase<GroupInfo> cb, CreateGroupReq groupReqInfo)
Input Parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| cb | OnBase<GroupInfo> | Yes | Callback |
| groupReqInfo | CreateGroupReq | Yes | Group creation params |
Return Result
Code Example
IMSDK.CreateGroup((groupInfo,errCode,errMsg)=>{
},new CreateGroupReq(){
MemberUserIDs={""},
GroupInfo = groupInfo,
AdminUserIDs = {},
OwnerUserID = "",
});