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.
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
- 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
Request multiple users to join a channel with InviteMultiple(). Maximum 100 users per call.
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
Monitor invitation events with ListenForEvents() and send notifications to invited users.
Events documentation
See Chat events for details on invite events.
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