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.

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

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