Browse SDKs · uni-app / uni-app x
Platform
SDKsuni-app / uni-app x

Create a group

Create a new group and configure initial administrators and regular members.

Copy

Invoke createGroup() to initialize a new group with specified profile data, regular members, and optional initial administrators. You cannot explicitly designate an arbitrary owner during creation; OpenIMServer automatically sets the creator as the group owner (ownerUserID).

Parameters

ParameterTypeRequiredDescription
groupInfoOpenIMCreateGroupInfoYesInitial group profile configuration object.
groupInfo.groupNamestringYesDisplay name of the new group.
groupInfo.groupTypeOpenIMGroupTypeYesGroup type constant; pass OpenIMGroupTypeWorkingGroup for standard working groups.
groupInfo.notificationstringNoInitial group announcement string.
groupInfo.introductionstringNoInitial group introduction or description.
groupInfo.faceURLstringNoAvatar image URL for the group.
groupInfo.exstringNoCustom group extension string.
memberUserIDsstring[]YesArray of user IDs to add as initial regular members.
adminUserIDsstring[]NoArray of user IDs to designate as initial administrators.

Deduplicate both user ID arrays and ensure there is no overlap between memberUserIDs and adminUserIDs.

Code example

import {
  OpenIMGroupTypeWorkingGroup,
  createGroup,
} from '@/uni_modules/unix-openim-sdk'

const group = await createGroup({
  groupInfo: {
    groupName: 'Project Discussion Group',
    groupType: OpenIMGroupTypeWorkingGroup,
    faceURL: 'https://example.com/group.png',
  },
  memberUserIDs: ['user-003', 'user-004'],
  adminUserIDs: ['user-002'],
})

if (group != null) {
  openGroupPage(group.groupID)
}

Return value

The Promise resolves with an OpenIMGroupItem | null object containing the newly created group record. A non-null return value provides the new groupID and initial metadata.

State changes after the call

A resolved Promise confirms that the group was created on OpenIMServer. The active user's joined group roster is updated via the onJoinedGroupAdded event using groupID. For complete group event listener registration, see Group overview.