On this page

Invite users to channels

Requires App Context

To manage channel membership, you must enable App Context for your app's keyset in the Admin Portal.

Let users invite one or more people to a private or group conversation and sets their channel membership.

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

As a result or inviting one or more users to a direct or group channel, an event of the invite type gets created. You can listen to these events in your chat app and notify the invited users.

Unity Chat SDK doesn't provide any default logic that is triggered when one user invites another user to join a channel. However, if you want the invited user to receive a notification about the new invitation, you can implement custom logic in your chat app that will:

Invite one user

Invite() requests another user to join a channel and become its member.

Method signature

This method takes the following parameters:

1channel.Invite(User user)

Input

* required
ParameterDescription
user *
Type: User
Default:
n/a
User that you want to invite to a 1:1 channel.

Output

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

1

Invite multiple users

InviteMultiple() requests other users to join a channel and become its members. You can invite up to 100 users at once.

Method signature

This method takes the following parameters:

1channel.InviteMultiple(List<User> users)

Input

* required
ParameterDescription
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

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

1

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

Method signature

This method takes the following parameters:

1channel.GetInvitees(
2 string filter = "",
3 string sort = "",
4 int limit = 0,
5 PNPageObject page = null
6)

Input

* required
ParameterDescription
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.
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

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

1

Listen to Invite events

As an admin of your chat app, you can monitor all events emitted when someone invites a person to a direct or group channel.

Use the StreamInviteEvents() method to enable or disable invite event streaming on a user, and the OnInviteEvent event to handle invite updates. You can use this to send notifications to the invited users.

Events documentation

To read more about the events of type Invite, refer to the Chat events documentation.

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)
  • OnInviteEvent - Event signature

    1// event on the User entity
    2public event Action<ChatEvent> OnInviteEvent;
    3// needs a corresponding event handler
    4void EventHandler(ChatEvent inviteEvent)

Input

ParameterRequired in StreamInviteEvents()Required in OnInviteEventDescription
stream
Type: bool
Default:
n/a
Yes
n/a
Whether to start (true) or stop (false) listening to invite events for the user.
inviteEvent
Type: ChatEvent
Default:
n/a
No
Yes
The invite event containing information about the invitation.

Output

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

Sample code

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

1

Last updated on