Invite users to channels
Let users invite one or more people to a private or group conversation and sets their channel membership.
Requires App Context
To manage channel membership, you must enable App Context for your app's keyset in the Admin Portal.
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.
Not available for public chats
Invitations are disabled in public chats. If you try implementing this feature in a public channel type, you'll get the Channel invites are not supported in Public chats
error.
Unreal 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
- Blueprint
- C++ / Input parameters
Channel->Invite(UPubnubUser* User);
Input
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
User | UPubnubUser* | Yes | n/a | User that you want to invite to a 1:1 channel. |
Output
Type | Description |
---|---|
UPubnubMembership* | Returned (modified) object containing the membership data. |
Basic usage
Invite support-agent-15
to join the high-prio-incidents
channel.
#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"
UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
UPubnubChannel* Channel = Chat->GetChannel("high-prio-incidents");
// Define user ID
FString UserID = "support_agent_15";
// Get the user and save the reference
UPubnubUser* User = Chat->GetUser(UserID);
show all 17 linesInvite 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
- Blueprint
- C++ / Input parameters
Channel->InviteMultiple(TArray<UPubnubUser*> Users);
Input
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
Users | TArray<UPubnubUser*> | Yes | n/a | Array of users you want to invite to the group channel. You can invite up to 100 users in one call. |
Output
Type | Description |
---|---|
TArray<UPubnubMembership*> | Returned (modified) array of objects containing the membership data. |
Basic usage
Invite support-agent-15
and support-agent-16
to join the high-prio-incidents
channel.
#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"
UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
UPubnubChannel* Channel = Chat->GetChannel("high-prio-incidents");
// Define user IDs
FString UserID1 = "support_agent_15";
FString UserID2 = "support_agent_16";
// Get the user and save the reference
show all 23 linesListen to invite
events
As an admin of your chat app, you can use the ListenForEvents()
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
- Blueprint
- C++ / Input parameters
Chat->ListenForEvents(
FString ChannelID,
EPubnubChatEventType ChatEventType,
FOnPubnubEventReceived EventCallback
);
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
ChannelID | FString | Yes | n/a | Channel to listen for new invite events. |
ChatEventType | EPubnubChatEventType | No | n/a | Type of events. PCET_INVITE is the type defined for all events emitted when an offensive message is flagged/reported. |
EventCallback | FOnPubnubEventReceived | Yes | n/a | Callback function passed as a parameter. It defines the custom behavior to be executed whenever an invite event type is detected on the specified channel. |
EPubnubChatEventType
Value | Description |
---|---|
PCET_TYPING | Indicates a user is typing a message. Displayed as Typing. |
PCET_REPORT | Represents an event where a message has been flagged or reported for offensive content. Displayed as Report. |
PCET_RECEIPT | Confirms receipt of a message or event. Displayed as Receipt. |
PCET_MENTION | Indicates that a user has been mentioned in a message. Displayed as Mention. |
PCET_INVITE | Represents an invitation event typically sent to a specific user. Displayed as Invite. |
PCET_CUSTOM | Custom event type for specialized behavior or use cases. Displayed as Custom. |
PCET_MODERATION | Represents an event related to content moderation actions. Displayed as Moderation. |
Output
This method doesn't return any value.
Basic usage
Listen for invitations received on the support
channel.
#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"
UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
FString ChannelID = "support";
// Create a pubnub response delegate
// you MUST implement your own callback function to handle the response
FOnPubnubEventReceived ListenResponse;
ListenResponse.BindDynamic(this, &AMyActor::OnListenResponseReceived);
show all 20 lines