Invite users to channels
Requires App Context
Enable App Context for your keyset in the Admin Portal.
Invite users to private or group conversations, creating their channel membership. Invitations trigger an Invite event that you can listen to and notify invited users.
To send notifications on invitations, implement custom logic to:
- Create and send custom events when invitations are sent
- Let invited users receive these events
Invite one user
Request a user to join a channel with invite().
Method signature
This method takes the following parameters:
1channel.invite(
2 user: UserImpl
3) async throws -> MembershipImpl
Input
| Parameter | Description |
|---|---|
user *Type: UserImplDefault: n/a | User that you want to invite. |
Output
| Parameter | Description |
|---|---|
MembershipImpl | Returned (modified) object containing the membership data. |
Sample code
Sample code
The code samples in Swift Chat SDK focus on asynchronous code execution.
You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.
Invite support-agent-15 to join the high-prio-incidents channel.
1
Invite multiple users
Request multiple users to join a channel with inviteMultiple(). Maximum 100 users per call.
Method signature
This method takes the following parameters:
1channel.inviteMultiple(
2 users: [UserImpl]
3) async throws -> [MembershipImpl]
Input
| Parameter | Description |
|---|---|
users *Type: [UserImpl]Default: n/a | List of users you want to invite to the group channel. You can invite up to 100 users in one call. |
Output
| Parameter | Description |
|---|---|
[MembershipImpl] | Returned (modified) list of objects containing the membership data. |
Sample code
Sample code
The code samples in Swift Chat SDK focus on asynchronous code execution.
You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.
Invite support-agent-15 and support-agent-16 to join the high-prio-incidents channel.
1
Get invitees
Get all invited members of a channel with getInvitees().
Method signature
This method takes the following parameters:
1channel.getInvitees(
2 limit: Int? = nil,
3 page: PubNubHashedPage? = nil,
4 filter: String? = nil,
5 sort: [PubNub.MembershipSortField] = []
6) async throws -> (memberships: [MembershipImpl], page: PubNubHashedPage?)
Input
| Parameter | Description |
|---|---|
limitType: IntDefault: 100 | Number of objects to return in response. The default (and maximum) value is 100 (set through the underlying Swift SDK). |
pageType: PubNubHashedPage?Default: nil | Object used for pagination to define which previous or next result page you want to fetch. |
filterType: StringDefault: nil | Expression used to filter the results. Returns only these members whose properties satisfy the given expression. The filter language is defined here. |
sortType: [PubNub.MembershipSortField]Default: [] | A collection to specify the sort order. Available options are id, name, and updated. Use asc or desc to specify the sorting direction, or specify null to take the default sorting direction (ascending). For example: {name: "asc"}. Unless specified otherwise, the items are sorted by the last updated date. Defaults to an empty list. |
Output
| Parameter | Description |
|---|---|
(memberships: [MembershipImpl], page: PubNubHashedPage?) | A tuple containing a set of invited channel members with membership and pagination information indicating the start, end, and total count of the invitees. |
Sample code
Sample code
The code samples in Swift Chat SDK focus on asynchronous code execution.
You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.
Get all invited members of the high-prio-incidents channel.
1
Listen to Invite events
Monitor invitation events with user.onInvited() and send notifications to invited users. You can also use user.stream.invites() for an AsyncStream-based approach.
Events documentation
To read more about the events of type Invite, refer to the Chat events documentation.
Method signature
1user.onInvited(
2 callback: @escaping (Invite) -> Void
3) -> AutoCloseable
The Invite struct carries the invitation payload:
1public struct Invite {
2 public let channelId: String
3 public let channelType: ChannelType
4 public let invitedByUserId: String
5 public let invitationTimetoken: Timetoken
6}
Input
| Parameter | Description |
|---|---|
callback *Type: (Invite) -> VoidDefault: n/a | Closure called with an Invite whenever the user receives a channel invitation. |
Output
| Parameter | Description |
|---|---|
AutoCloseable | An object you must retain. When released or closed, the listener stops. |
Sample code
Sample code
The code samples in Swift Chat SDK focus on asynchronous code execution.
You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.
1