---
source_url: https://www.pubnub.com/docs/chat/kotlin-chat-sdk/build/features/channels/invite
title: Invite users to channels
updated_at: 2026-06-15T12:11:30.681Z
---

> 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/kotlin-chat-sdk/build/features/channels/membership). Invitations trigger an [invite event](https://www.pubnub.com/docs/chat/kotlin-chat-sdk/build/features/custom-events#events-for-channel-initations) that you can [listen to](https://www.pubnub.com/docs/chat/kotlin-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/kotlin-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/kotlin-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:

```kotlin
channel.invite(user: User): PNFuture<Membership>
```

#### Input

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

#### Output

| Type | Description |
| --- | --- |
| `PNFuture<Membership>` | Returned (modified) object containing the membership data. |

### Sample code

Invite `support-agent-15` to join the `high-prio-incidents` channel.

```kotlin
// assuming you have a chat service or a chat client object called "chat"
val userId = "support-agent-15"
val channelId = "high-prio-incidents"
// reference "support-agent-15"
chat.getUser(userId).async { userResult ->
    userResult.onSuccess { user ->
        if (user != null) {
            // User found, proceed to get the "high-prio-incidents" channel
            chat.getChannel(channelId).async { channelResult ->
                channelResult.onSuccess { channel ->
                    if (channel != null) {
                        // Channel found, proceed to invite the agent to join the channel
                        channel.invite(user).async { inviteResult ->
                            inviteResult.onSuccess { membership ->
                                // User successfully invited
                                println("User ${user.id} has been invited to channel ${channel.id}")
                            }.onFailure {
                                // handle failure
                            }
                        }
                    }
                }.onFailure {
                    // handle failure
                }
            }
        }
    }.onFailure {
        // handle failure
    }
}
```

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

```kotlin
channel.inviteMultiple(users: Collection<User>): PNFuture<List<Membership>>
```

#### Input

| Parameter | Description |
| --- | --- |
| `users` *Type: `Collection<User>`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

| Type | Description |
| --- | --- |
| `PNFuture<List<Membership>>` | Returned (modified) list of objects containing the membership data. |

### Sample code

Invite `support-agent-15` and `support-agent-16` to join the `high-prio-incidents` channel.

```kotlin
// assuming you have a chat service or a chat client object called "chat", reference both agents and the "high-prio-incidents" channel
val userId1 = "support-agent-15"
val userId2 = "support-agent-16"
val channelId = "high-prio-incidents"

chat.getUser(userId1).async { userResult1 ->
    userResult1.onSuccess { user1 ->
        if (user1 != null) {
            // First user found, now get the second user
            chat.getUser(userId2).async { userResult2 ->
                userResult2.onSuccess { user2 ->
                    if (user2 != null) {
                        // Second user found, now get the channel
                        chat.getChannel(channelId).async { channelResult ->
                            channelResult.onSuccess { channel ->
                                if (channel != null) {
                                    // Channel found, proceed to invite both users
                                    channel.inviteMultiple(listOf(user1, user2)).async { inviteResult ->
                                        inviteResult.onSuccess { memberships ->
                                            // Users successfully invited
                                            println("Users ${user1.id} and ${user2.id} have been invited to channel ${channel.id}")
                                        }.onFailure {
                                            // handle failure
                                        }
                                    }
                                }
                            }.onFailure {
                                // handle failure
                            }
                        }
                    }
                }.onFailure {
                    // handle failure
                }
            }
        }
    }.onFailure {
        // handle failure
    }
}
```

## Get invitees

`getInvitees()` returns the list of channel members whose membership status is "pending" (invited but not yet joined).

### Method signature

This method takes the following parameters:

```kotlin
channel.getInvitees(
    limit: Int? = 100,
    page: PNPage? = null,
    filter: String? = null,
    sort: Collection<PNSortKey<PNMemberKey>> = listOf(),
): PNFuture<MembersResponse>
```

#### Input

| Parameter | Description |
| --- | --- |
| `limit`Type: `Int?`Default: `100` | Number of objects to return in response. The default (and maximum) value is `100`. |
| `page`Type: `PNPage?`Default: `null` | Object used for pagination to define which previous or next result page you want to fetch. |
| `filter`Type: `String?`Default: `null` | Expression used to filter the results. This filter is combined with the pending status filter. |
| `sort`Type: `Collection<PNSortKey<PNMemberKey>>`Default: `listOf()` | A collection to specify the sort order. |

#### Output

| Type | Description |
| --- | --- |
| `PNFuture<MembersResponse>` | Object containing only pending (invited) members. Has the same structure as the response from [getMembers()](https://www.pubnub.com/docs/chat/kotlin-chat-sdk/build/features/channels/membership#get-channel-members). |

### Sample code

Get all pending invitees for the `high-prio-incidents` channel.

```kotlin
val channelId = "high-prio-incidents"

chat.getChannel(channelId).async { channelResult ->
    channelResult.onSuccess { channel ->
        if (channel != null) {
            channel.getInvitees().async { result ->
                result.onSuccess { membersResponse ->
                    membersResponse.members.forEach { membership ->
                        println("Pending invitee: ${membership.user.id}")
                    }
                }.onFailure {
                    // handle failure
                }
            }
        }
    }.onFailure {
        // handle failure
    }
}
```

## Listen to invite events

Monitor invitation events with `onInvited()` on the `User` object. This replaces the deprecated `listenForEvents()` approach with a typed callback.

:::warning Deprecated method
`listenForEvents<EventContent.Invite>()` is deprecated. Use `user.onInvited()` instead, which provides a typed `Invite` object with richer data.
:::

### Method signature

This method has the following parameters:

```kotlin
user.onInvited(callback: (invite: Invite) -> Unit): AutoCloseable
```

#### Input

| Parameter | Description |
| --- | --- |
| `callback` *Type: `(invite: Invite) -> Unit`Default: n/a | Function invoked with an `Invite` event whenever the user receives a channel invitation. |

The `Invite` object contains:

| Property | Description |
| --- | --- |
| `channelId`Type: `String` | The channel the user is invited to. |
| `channelType`Type: `ChannelType` | Type of the channel (direct, group, etc.). |
| `invitedByUserId`Type: `String` | User ID of who sent the invitation. |
| `invitationTimetoken`Type: `Long` | Timetoken of the invitation. |

#### Output

| Type | Description |
| --- | --- |
| `AutoCloseable` | Interface that lets you stop receiving invitation events by invoking the `close()` method. |

### Sample code

Listen for invite events on the current user.

```kotlin
val user = chat.currentUser

val subscription = user.onInvited { invite ->
    println("Invited to channel ${invite.channelId} (${invite.channelType}) by ${invite.invitedByUserId}")
}

// stop listening:
// subscription.close()
```