---
source_url: https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/channels/invite
title: Invite users to channels
updated_at: 2026-06-05T11:10:02.098Z
---

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

When a user is invited to a channel, their membership status is set to `"pending"` until they join the channel.

To send notifications on invitations, implement custom logic to:

* [Create and send custom events](https://www.pubnub.com/docs/chat/unity-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/unity-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:

```csharp
channel.Invite(User user)
```

#### Input

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

#### Output

| Type | Description |
| --- | --- |
| `Task<ChatOperationResult<Membership>>` | Awaitable `Task` with the returned (modified) object containing the membership data. |

### Sample code

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

```csharp
using System.Collections.Generic;
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;

// Configuration
PubnubChatConfig chatConfig = new PubnubChatConfig();
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
// reference "support-agent-15"
var userResult = await chat.GetUser("support-agent-15");
if (userResult.Error)
{
    Debug.Log("Couldn't find user to invite!");
    return;
}
var user = userResult.Result;

// get the channel
var channelResult = await chat.GetChannel("high-prio-incidents");
if (channelResult.Error)
{
    Debug.Log("Couldn't find channel to invite!");
    return;
}
var channel = channelResult.Result;

// invite the agent to join the channel
await channel.Invite(user);
```

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

```csharp
channel.InviteMultiple(List<User> users)
```

#### Input

| Parameter | Description |
| --- | --- |
| `users` *Type: `List<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 |
| --- | --- |
| `Task<ChatOperationResult<List<Membership>>>` | Awaitable `Task` with the 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.

```csharp
using System.Collections.Generic;
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;

// Configuration
PubnubChatConfig chatConfig = new PubnubChatConfig();
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
// reference "support-agent-15"
var user1Result = await chat.GetUser("support-agent-15");
if (user1Result.Error)
{
    Debug.Log("Couldn't find first user!");
    return;
}
var user1 = user1Result.Result;

// reference "support-agent-16"
var user2Result = await chat.GetUser("support-agent-16");
if (user2Result.Error)
{
    Debug.Log("Couldn't find second user!");
    return;
}
var user2 = user2Result.Result;

// reference the "high-prio-incidents" channel
var channelResult = await chat.GetChannel("high-prio-incidents");
if (channelResult.Error)
{
    Debug.Log("Couldn't find channel!");
    return;
}
var channel = channelResult.Result;

// invite both agents to join the channel
var newMemberships = await channel.InviteMultiple(new List<User> { user1, user2 });
```

## Get invited users

`GetInvitees()` retrieves a list of users who have been invited to a channel but haven't joined yet. This method returns all memberships with a status of `"pending"`.

When a user accepts an invitation and joins the channel the pending status is cleared, and they no longer appear in the invitees list. For more information about membership status transitions, refer to the [Membership](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/channels/membership) documentation.

### Method signature

This method takes the following parameters:

```csharp
channel.GetInvitees(
    string filter = "",
    string sort = "",
    int limit = 0,
    PNPageObject page = null
)
```

#### Input

| Parameter | Description |
| --- | --- |
| `filter`Type: `string`Default: empty string | Expression used to filter the results. The filter is automatically combined with `status == "pending"` to return only invited users. The filter language is [defined here](https://www.pubnub.com/docs/general/metadata/filtering). |
| `sort`Type: `string`Default: empty string | Key-value pair of a property to sort by, and a sort direction. 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"}`. By default, the items are sorted by the last updated date. |
| `limit`Type: `int`Default: `0` | Number of objects to return in response. |
| `page`Type: `PNPageObject`Default: `null` | Object used for pagination to define which previous or next result page you want to fetch. |

#### Output

| Type | Description |
| --- | --- |
| `Task<ChatOperationResult<MembersResponseWrapper>>` | Awaitable `Task` with the returned wrapper object containing the list of pending memberships. |

### Sample code

Retrieve all users who have been invited to the `my_channel` channel but haven't joined yet.

```csharp
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;

// Configuration
PubnubChatConfig chatConfig = new PubnubChatConfig();
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
// Get or create a channel
var channelResult = await chat.GetChannel("my_channel");
if (channelResult.Error)
{
    Debug.LogError($"Could not fetch channel! Error: {channelResult.Exception.Message}");
}
var channel = channelResult.Result;
var getInvitees = await channel.GetInvitees();
if (getInvitees.Error)
{
    Debug.LogError($"Could not fetch invitees! Error: {getInvitees.Exception.Message}");
}
foreach (var membership in getInvitees.Result.Memberships)
{
    Debug.Log($"User {membership.UserId} has is invited to channel {membership.ChannelId}");
}
```

## Listen to invite events

Use the `OnInvited` event on the [User](https://www.pubnub.com/docs/chat/unity-chat-sdk/learn/chat-entities/user) object to receive real-time invitation events. Call `StreamInviteEvents(true)` to enable the callback.

The event delivers a typed [Invite](https://www.pubnub.com/docs/chat/unity-chat-sdk/learn/chat-entities/event#typed-event-data) struct containing the channel ID, channel type, inviter user ID, and timetoken.

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

:::tip Method naming
Earlier versions used `SetListeningForInviteEvents()` to enable streaming. This method has been superseded by `StreamInviteEvents()`, though it remains available for backward compatibility.
:::

### Method signature

These methods take the following parameters:

* StreamInviteEvents() 1user.StreamInviteEvents(bool stream)
* OnInvited - Event signature 1// event on the User entity2public event Action<Invite> OnInvited;3// needs a corresponding event handler4void EventHandler(Invite invite)

#### Input

| Parameter | Required in `StreamInviteEvents()` | Required in `OnInvited` | Description |
| --- | --- | --- | --- |
| `stream`Type: `bool`Default: n/a | Yes | n/a | Whether to start (`true`) or stop (`false`) listening to invite events for the user. |
| `invite`Type: [Invite](https://www.pubnub.com/docs/chat/unity-chat-sdk/learn/chat-entities/event#typed-event-data)Default: n/a | No | Yes | The invite event containing the channel ID, channel type, inviter user ID, and timetoken. |

#### Output

These methods don't return a value. Invite event updates are delivered through the `OnInvited` event handler.

### Sample code

Print a notification when the user `support-agent-2` is invited to the `support` channel.

```csharp
using System.Collections.Generic;
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;

// Configuration
PubnubChatConfig chatConfig = new PubnubChatConfig();
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
var userResult = await chat.GetUser("support-agent-2");
if(userResult.Error){
    Debug.Log("Couldn't find user!");
    return;
}
var user = userResult.Result;

//start listening
user.StreamInviteEvents(true);
//lambda event handler
user.OnInvited += (inviteEvent) => 
    {
        if(inviteEvent.ChannelId == "support")
        {
            Debug.Log("User support-agent-2 has been invited to the support channel!");
        }    
    };
```