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.

icon

Usage in Blueprints and C++


Asynchronous and synchronous method execution

Most PubNub Unreal SDK methods are available in both asynchronous and synchronous variants.

  • Asynchronous methods (Async suffix) return void and take an optional delegate parameter that fires when the operation completes.

    1Channel->InviteAsync(User, OnInviteResponseDelegate);

    You can also use native callbacks that accept lambdas instead of dynamic delegates. Native callback types have the Native suffix (for example, FOnPubnubChatInviteResponseNative).

  • Synchronous methods (no suffix) block the main game thread until the operation completes and return a result struct directly.

    1FPubnubChatInviteResult Result = Channel->Invite(User);

To send notifications on invitations, implement custom logic to:

Invite one user​

Request a user to join a channel with Invite().

Method signature​

1Channel->Invite(UPubnubChatUser* User);

Input​

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

Output​

TypeDescription
FPubnubChatInviteResultReturned object containing Result (FPubnubChatOperationResult) and Membership (UPubnubChatMembership*).

Sample code​

Reference code

This example is a self-contained code snippet ready to be run. Set up your Unreal project and follow the instructions in the lines marked with ACTION REQUIRED before running the code. Use it as a reference when working with other examples in this document.

Invite a user to a channel asynchronously.

Actor.h​
1

Actor.cpp​
1

Invite multiple users​

Request multiple users to join a channel with InviteMultiple(). Maximum 100 users per call.

Method signature​

1Channel->InviteMultiple(TArray<UPubnubChatUser*> Users);

Input​

* required
ParameterDescription
Users *
Type: TArray<UPubnubChatUser*>
Default:
n/a
Array of users you want to invite to the group channel. You can invite up to 100 users in one call.

Output​

TypeDescription
FPubnubChatInviteMultipleResultReturned object containing Result (FPubnubChatOperationResult) and Memberships (TArray<UPubnubChatMembership*>).

Sample code​

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

1

Get invitees​

Get invitees (members with pending status) for this channel with GetInvitees().

Method signature​

1Channel->GetInvitees(int Limit = 0, FString Filter = "", FPubnubMemberSort Sort = ..., FPubnubPage Page = FPubnubPage());

Output​

TypeDescription
FPubnubChatMembershipsResultReturned object containing Result (FPubnubChatOperationResult), Memberships (TArray<UPubnubChatMembership*>), Page, and Total.

Sample code​

1

Listen to invite events​

Subscribe to real-time invitation events for a user with StreamInvitations(). Bind the user's OnInvited delegate before calling this method.

DelegateTypePayload
OnInvitedFOnPubnubChatUserInvitedFPubnubChatInviteEvent containing ChannelType, ChannelID, and Event details.

Method signature​

1User->StreamInvitations();

Output​

TypeDescription
FPubnubChatOperationResultContains Error and ErrorMessage. Check Error to determine if the subscription started successfully.

Sample code​

Actor.h​
1

Actor.cpp​
1

Stopping updates​

To stop receiving invitation events, call StopStreamingInvitations() on the user.

1User->StopStreamingInvitations();

Output​

TypeDescription
FPubnubChatOperationResultContains Error and ErrorMessage.

Was this page useful?

Last updated on