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.
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
1Channel->Invite(UPubnubUser* User);
Input
| Parameter | Description |
|---|---|
User *Type: UPubnubUser*Default: n/a | User that you want to invite to a 1:1 channel. |
Output
| Type | Description |
|---|---|
UPubnubMembership* | Returned (modified) object containing the membership data. |
Sample code
Invite support-agent-15 to join the high-prio-incidents channel.
1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9UPubnubChannel* Channel = Chat->GetChannel("high-prio-incidents");
10
11// Define user ID
12FString UserID = "support_agent_15";
13
14// Get the user and save the reference
15UPubnubUser* 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
1Channel->InviteMultiple(TArray<UPubnubUser*> Users);
Input
| Parameter | Description |
|---|---|
Users *Type: TArray<UPubnubUser*>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
| Type | Description |
|---|---|
TArray<UPubnubMembership*> | Returned (modified) array of objects containing the membership data. |
Sample code
Invite support-agent-15 and support-agent-16 to join the high-prio-incidents channel.
1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9UPubnubChannel* Channel = Chat->GetChannel("high-prio-incidents");
10
11// Define user IDs
12FString UserID1 = "support_agent_15";
13FString UserID2 = "support_agent_16";
14
15// 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
1Chat->ListenForEvents(
2 FString ChannelID,
3 EPubnubChatEventType ChatEventType,
4 FOnPubnubEventReceived EventCallback
5);
| Parameter | Description |
|---|---|
ChannelID *Type: FStringDefault: n/a | Channel to listen for new invite events. |
ChatEventTypeType: EPubnubChatEventTypeDefault: n/a | Type of events. PCET_INVITE is the type defined for all events emitted when an offensive message is flagged/reported. |
EventCallback *Type: FOnPubnubEventReceivedDefault: 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.
Sample code
Listen for invitations received on the support channel.
1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9FString ChannelID = "support";
10
11// Create a pubnub response delegate
12// you MUST implement your own callback function to handle the response
13FOnPubnubEventReceived ListenResponse;
14ListenResponse.BindDynamic(this, &AMyActor::OnListenResponseReceived);
15
show all 20 lines