createGroup
Feature Introduction
Description
- The creator establishes a group as the group owner, specifying group administrators and ordinary group members. Once successful, all roles immediately join the group.
- It's recommended that the number of group members does not exceed 1000 at a time, as larger numbers may result in data packets being rejected by the backend due to their size.
Note
- If a groupID is specified, it cannot be duplicated.
- If no groupID is 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 | Data Type | Required | Description |
---|---|---|---|
groupInfo | GroupInfo | Yes | Group information |
memberUserIDs | List<String> | Yes | List of invited group members |
adminUserIDs | List<String> | No | List of invited admins |
ownerUserID | String | No | Group owner's ID |
Return Value
Parameter Name | Data Type | Description |
---|---|---|
~ | GroupInfo | Successful return |
Example Code
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 | Data Type | Required | Description |
---|---|---|---|
groupCreateInfo | OIMGroupCreateInfo | Yes | Initialization information for creating a group |
Return Value
Parameter Name | Data Type | Description |
---|---|---|
onSuccess | OIMGroupInfo | Successful return |
onFailure | OIMFailureCallback | Failure return |
Example Code
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 | Data Type | Required | Description |
---|---|---|---|
groupInfo | GroupInitInfo | Yes | Basic group chat information |
memberUserIDs | string[] | Yes | List of invited group members |
adminUserIDs | string[] | No | List of invited admins |
ownerUserID | string | No | Group owner's ID |
callBack | OnBase<GroupInfo> | Yes | Callback interface |
Return Value
Example Code
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 | Mandatory | Description |
---|---|---|---|
groupInfo | Partial<GroupItem> | Yes | Basic group chat information |
memberUserIDs | string[] | Yes | List of invited group members |
adminUserIDs | string[] | No | List of users invited as administrators |
ownerUserID | string | No | Group owner 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(() => {
// On successful call
})
.catch(({ errCode, errMsg }) => {
// On failed call
});
Function Prototype
IMSDK.asyncApi('createGroup', operationID: string, {
groupInfo: Partial<GroupItem>,
memberUserIDs: string[],
adminUserIDs?: string[],
ownerUserID?: string
}): Promise<GroupItem>
Input Parameters
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
operationID | string | Yes | Operation ID for troubleshooting. Keep unique. Recommended to use current time and random number. |
groupInfo | Partial<GroupItem> | Yes | Basic group chat information |
memberUserIDs | string[] | Yes | List of invited group members |
adminUserIDs | string[] | No | List of users invited as administrators |
ownerUserID | string | No | Group owner ID |
Return Result
The function is Promisified through the
openim-uniapp-polyfill
package. When calling, usethen
andcatch
to judge and handle success and failure callbacks respectively.
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) => {
// On successful call
})
.catch(({ errCode, errMsg }) => {
// On failed call
});
Function Prototype
OpenIMSDKRN.createGroup({
groupInfo: Partial<GroupItem>,
memberUserIDs: string[],
adminUserIDs?: string[],
ownerUserID?: string
}, operationID: string): Promise<GroupItem>
Input Parameters
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
groupInfo | Partial<GroupItem> | Yes | Basic group chat information |
memberUserIDs | string[] | Yes | List of invited group members |
adminUserIDs | string[] | No | List of users invited as administrators |
ownerUserID | string | No | Group owner ID |
operationID | string | Yes | Operation ID, used for problem location, keep unique, suggest using current time and random number |
Return Result
Parameter Name | Parameter Type | Description |
---|---|---|
Promise.then() | Promise<GroupItem> | Callback on successful call |
Promise.catch() | Promise<CatchResponse> | Callback on failed call |
Code Example
import OpenIMSDKRN from "open-im-sdk-rn";
OpenIMSDKRN.createGroup({
groupInfo: {
groupName: '',
groupType: 2,
},
memberUserIDs: [''],
}, 'operationID')
.then((data) => {
// On successful call
})
.catch(({ errCode, errMsg }) => {
// On failed call
});
Function Prototype
public static void CreateGroup(OnBase<GroupInfo> cb, CreateGroupReq groupReqInfo)
Input Parameter
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
cb | OnBase<GroupInfo> | Yes | Callback |
groupReqInfo | CreateGroupReq | Yes | Create Group Args |
Return Result
Code Example
IMSDK.CreateGroup((groupInfo,errCode,errMsg)=>{
},new CreateGroupReq(){
MemberUserIDs={""},
GroupInfo = groupInfo,
AdminUserIDs = {},
OwnerUserID = "",
});