---
source_url: https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/channels/invite
title: Invite users to channels
updated_at: 2026-06-16T12:48:52.384Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Invite users to channels

:::note Requires App Context
Enable [App Context](https://youtu.be/9UEoSlngpYI) for your keyset in the [Admin Portal](https://admin.pubnub.com/).
:::

Invite users to private or group conversations, creating their channel [membership](https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/channels/membership). Invitations trigger an [Invite event](https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/custom-events#events-for-channel-initations) that you can [listen to](https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/channels/invite#listen-to-invite-events) and notify invited users.

To send notifications on invitations, implement custom logic to:

* [Create and send custom events](https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/custom-events#create-and-send-events) when invitations are sent
* Let invited users [receive these events](https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/custom-events#receive-current-events)

## Invite one user

Request a user to join a channel with `invite()`.

### Method signature

This method takes the following parameters:

```swift
channel.invite(
    user: UserImpl
) async throws -> MembershipImpl
```

#### Input

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| user | UserImpl | Yes |  | User that you want to invite. |

#### Output

| Parameter | Description |
| --- | --- |
| `MembershipImpl` | Returned (modified) object containing the membership data. |

### Sample code

:::tip 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.

```swift
// Assumes a "ChatImpl" reference named "chat"
Task {
  let supportAgent = try await chat.getUser(userId: "support-agent-15")
  let channel = try await chat.getChannel(channelId: "high-prio-incidents")
    
  if let supportAgent, let channel {
    let channelMembership = try await channel.invite(user: supportAgent)
    debugPrint("Updated membership: \(channelMembership)")
    debugPrint("Membership channel id: \(channelMembership.channel.id)")
  } else {
    debugPrint("User or channel not found")
  }
}
```

## 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:

```swift
channel.inviteMultiple(
    users: [UserImpl]
) 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

:::tip 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.

```swift
// Assumes a "ChatImpl" reference named "chat"
Task {
  let supportAgent15 = try await chat.getUser(userId: "support-agent-15")
  let supportAgent16 = try await chat.getUser(userId: "support-agent-16")
  let channel = try await chat.getChannel(channelId: "high-prio-incidents")
    
  if let supportAgent15, let supportAgent16, let channel {
    let channelMembership = try await channel.inviteMultiple(users: [supportAgent15, supportAgent16])
    debugPrint("Updated memberships: \(channelMembership)")
  } else {
    debugPrint("Channel or users not found")
  }
}
```

## Get invitees

Get all invited members of a channel with `getInvitees()`.

### Method signature

This method takes the following parameters:

```swift
channel.getInvitees(
    limit: Int? = nil,
    page: PubNubHashedPage? = nil,
    filter: String? = nil,
    sort: [PubNub.MembershipSortField] = []
) async throws -> (memberships: [MembershipImpl], page: PubNubHashedPage?)
```

#### Input

| Parameter | Description |
| --- | --- |
| `limit`Type: `Int`Default: `100` | Number of objects to return in response. The default (and maximum) value is `100` (set through the underlying Swift SDK). |
| `page`Type: `PubNubHashedPage?`Default: `nil` | Object used for pagination to define which previous or next result page you want to fetch. |
| `filter`Type: `String`Default: `nil` | Expression used to filter the results. Returns only these members whose properties satisfy the given expression. The filter language is [defined here](https://www.pubnub.com/docs/general/metadata/filtering). |
| `sort`Type: `[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

:::tip 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.

```swift
//
//  InviteSnippets.swift
//
//  Copyright (c) PubNub Inc.
//  All rights reserved.
//
//  This source code is licensed under the license found in the
//  LICENSE file in the root directory of this source tree.
//

import PubNubSwiftChatSDK

var chat: ChatImpl!

// MARK: - Invite One User

func inviteOneUser() {
  // snippet.invite.inviteOne
  // Assumes a "ChatImpl" reference named "chat"
  Task {
    let supportAgent = try await chat.getUser(userId: "support-agent-15")
    let channel = try await chat.getChannel(channelId: "high-prio-incidents")
    
    if let supportAgent, let channel {
      let channelMembership = try await channel.invite(user: supportAgent)
      debugPrint("Updated membership: \(channelMembership)")
      debugPrint("Membership channel id: \(channelMembership.channel.id)")
    } else {
      debugPrint("User or channel not found")
    }
  }
  // snippet.end
}

// MARK: - Invite Multiple Users

func inviteMultipleUsers() {
  // snippet.invite.inviteMultiple
  // Assumes a "ChatImpl" reference named "chat"
  Task {
    let supportAgent15 = try await chat.getUser(userId: "support-agent-15")
    let supportAgent16 = try await chat.getUser(userId: "support-agent-16")
    let channel = try await chat.getChannel(channelId: "high-prio-incidents")
    
    if let supportAgent15, let supportAgent16, let channel {
      let channelMembership = try await channel.inviteMultiple(users: [supportAgent15, supportAgent16])
      debugPrint("Updated memberships: \(channelMembership)")
    } else {
      debugPrint("Channel or users not found")
    }
  }
  // snippet.end
}

// MARK: - Listen to Invite Events

func listenForInviteEvents() {
  // snippet.invite.listenForEvents
  // Assumes a "ChatImpl" reference named "chat"
  Task {
    for await event in chat.listenForEvents(type: EventContent.Invite.self, channelId: "userId") {
      debugPrint("Received an invitation on channel ID: \(event.event.payload.channelId)")
      debugPrint("Channel type: \(event.event.payload.channelType)")
    }
  }
  // snippet.end
}
```

## 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.

:::tip Events documentation
To read more about the events of type `Invite`, refer to the [Chat events](https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/custom-events#invite-events) documentation.
:::

### Method signature

```swift
user.onInvited(
    callback: @escaping (Invite) -> Void
) -> AutoCloseable
```

The `Invite` struct carries the invitation payload:

```swift
public struct Invite {
    public let channelId: String
    public let channelType: ChannelType
    public let invitedByUserId: String
    public let invitationTimetoken: Timetoken
}
```

##### Input

| Parameter | Description |
| --- | --- |
| `callback` *Type: `(Invite) -> Void`Default: 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

:::tip 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.
:::

```swift
// Assumes a "ChatImpl" reference named "chat"
Task {
  for await event in chat.listenForEvents(type: EventContent.Invite.self, channelId: "userId") {
    debugPrint("Received an invitation on channel ID: \(event.event.payload.channelId)")
    debugPrint("Channel type: \(event.event.payload.channelType)")
  }
}
```