Invite users to channels
Requires App Context
Enable App Context for your keyset in the Admin Portal.
Invite users to private or group conversations, creating their channel membership. Invitations trigger an invite event that you can listen to 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 when invitations are sent
- Let invited users receive these events
Invite one user
Request a user to join a channel with Invite().
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
Request multiple users to join a channel with InviteMultiple(). Maximum 100 users per call.
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
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
| Parameter | Description |
|---|---|
filterType: stringDefault: 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. |
sortType: stringDefault: 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. |
limitType: intDefault: 0 | Number of objects to return in response. |
pageType: PNPageObjectDefault: 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.
1
Listen to invite events
Use the OnInvited event on the User object to receive real-time invitation events. Call StreamInviteEvents(true) to enable the callback.
The event delivers a typed Invite struct containing the channel ID, channel type, inviter user ID, and timetoken.
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) -
OnInvited- Event signature1// event on the User entity
2public event Action<Invite> OnInvited;
3// needs a corresponding event handler
4void EventHandler(Invite invite)
Input
| Parameter | Required in StreamInviteEvents() | Required in OnInvited | Description |
|---|---|---|---|
streamType: boolDefault: n/a | Yes | n/a | Whether to start (true) or stop (false) listening to invite events for the user. |
inviteType: InviteDefault: 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.
1