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
Listen to Invite events
Monitor invitation events with listenForEvents() and send notifications to invited users.
Events documentation
To read more about the events of type Invite, refer to the Chat events documentation.
Method signature
This method has the following parameters:
1chat.listenForEvents<T: EventContent>(
2 type: T.Type,
3 channelId: String,
4 customMethod: EmitEventMethod = .publish,
5 ) -> AsyncStream<EventWrapper<T>>
Input
| Parameter | Description |
|---|---|
type *Type: T.TypeDefault: n/a | Type parameter allowing access to type information at runtime. |
channelId *Type: StringDefault: n/a | Channel to listen for new Invite events. |
customMethodType: EmitEventMethodDefault: n/a | An optional custom method for emitting events. If not provided, defaults to .publish. Available values: .publish and .signal. |
Output
| Parameter | Description |
|---|---|
AsyncStream<EventWrapper<T>> | An asynchronous stream that produces a value each time a new event of the specified type is detected. |
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.
Print a notification for an invitation received on the userId channel.
1