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:
- Create and send custom events when invitations are sent.
- Let invited users receive these custom events upon sending invitations.
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
| Parameter | Description |
|---|---|
user *Type: UserDefault: n/a | 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.
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
| 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.
1
Listen to Invite events
As an admin of your chat app, you can use the SetListeningForInviteEvents(true) method to monitor all events emitted when someone invites a person to a direct or group channel. You can use this method 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 signature
This method has the following parameters:
1// start listening
2user.SetListeningForInviteEvents(bool listen)
3
4// triggered invite event
5public event Action<ChatEvent> OnInviteEvent;
6// needs a corresponding event handler
7void EventHandler(InviteEvent event)
Input
| Parameter | Description |
|---|---|
listen *Type: boolDefault: n/a | Whether to enable listening for invite events. |
Output
This method doesn't return anything.
Sample code
Print a notification when the user support-agent-2 is invited to the support channel.
1