Report misbehaving users
Requires App Context
Enable App Context in the Admin Portal to work with user metadata.
Administrators are chat users with SDK instances initialized with a Secret Key. Admin moderation capabilities:
- Mute users on channels
- Ban users from accessing channels
Use Access Manager to enforce restrictions.
Mute or ban users
Mute or ban users with SetRestrictions() on the Chat, User, or Channel object. All three produce the same output with different input parameters.
How it works:
- Muting/banning creates a
moderationevent (mutedorbanned) - A moderation membership is created with
PUBNUB_INTERNAL_MODERATION_prefix (secured via Access Manager, filtered fromGetMemberships()results) - Lifting restrictions removes the moderation membership and creates a
liftedevent
Listen to moderation events to trigger actions like removing memberships. Check restrictions to verify user status.
Secret Key required
Initialize with Secret Key (from Admin Portal) for admin operations. Never expose Secret Key to clients. If compromised, generate a new one in the Admin Portal.
Method signature
- Blueprint
- C++ / Input parameters
-
User->SetRestrictions()1User->SetRestrictions(
2 FString ChannelID,
3 FPubnubRestriction Restrictions
4); -
Channel->SetRestrictions()1Channel->SetRestrictions(
2 FString UserID,
3 FPubnubRestriction Restrictions
4); -
Chat->SetRestrictions()1Chat->SetRestrictions(
2 FString UserID,
3 FString ChannelID,
4 FPubnubRestriction Restrictions
5);
| Parameter | Required for Chat | Required for User | Required for Channel | Description |
|---|---|---|---|---|
userIdType: stringDefault: n/a | Yes | No | No | Unique User ID that becomes your app's current user. It's a string of up to 92 characters that identifies a single client (end user, device, or server) that connects to PubNub. Based on User ID, PubNub calculates pricing for your apps' usage. User ID should be persisted and remain unchanged. If you don't set userId, you won't be able to connect to PubNub. In this method, userId stands for the user that you want to mute or ban. |
ChannelIDType: stringDefault: n/a | Yes | No | No | ID of the channel on/from which the user should be muted or banned. |
RestrictionsType: FPubnubRestrictionDefault: n/a | Yes | Yes | Yes | The restrictions to apply. |
FPubnubRestriction
| Parameter | Type | Description |
| Ban | bool | Value that represents the user's moderation restrictions. Set to true to ban the user from the channel or to false to unban them. |
| Mute | bool | Value that represents the user's moderation restrictions. Set to true to mute the user on the channel or to false to unmute them. |
| Reason | FString | Reason why you want to ban or mute the user. |
Output
These methods don't return any value.
Sample code
Mute
Mute support_agent_15 on the support channel.
-
SetRestrictions()(on theChatobject)
show all 20 lines1#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
9// Define user ID
10FString UserID = "support_agent_15";
11
12FString ChannelID = "support";
13
14FPubnubRestriction Restrictions;
15Restrictions.Mute = true; -
SetRestrictions()(on theUserobject)
show all 22 lines1#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
9// Define user ID
10FString UserID = "support_agent_15";
11FString ChannelID = "support";
12
13// Get the user and save the reference
14UPubnubUser* User = Chat->GetUser(UserID);
15 -
SetRestrictions()(on theChannelobject)
show all 22 lines1#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
9// Define user ID
10FString UserID = "support_agent_15";
11FString ChannelID = "support";
12
13// Get the user and save the reference
14UPubnubChannel* Channel = Chat->GetChannel(ChannelID);
15
Ban
Ban support_agent_15 from the support channel.
-
SetRestrictions()(on theChatobject)
show all 20 lines1#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
9// Define user ID
10FString UserID = "support_agent_15";
11
12FString ChannelID = "support";
13
14FPubnubRestriction Restrictions;
15Restrictions.Mute = false; -
SetRestrictions()(on theUserobject)
show all 22 lines1#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
9// Define user ID
10FString UserID = "support_agent_15";
11FString ChannelID = "support";
12
13// Get the user and save the reference
14UPubnubUser* User = Chat->GetUser(UserID);
15 -
SetRestrictions()(on theChannelobject)
show all 22 lines1#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
9// Define user ID
10FString UserID = "support_agent_15";
11FString ChannelID = "support";
12
13// Get the user and save the reference
14UPubnubChannel* Channel = Chat->GetChannel(ChannelID);
15
Check restrictions
One user on one channel
Check mute or ban restrictions for a user on a specific channel with GetChannelRestrictions() or GetUserRestrictions().
Method signature
- Blueprint
- C++ / Input parameters
-
User->GetChannelRestrictions()1User->GetChannelRestrictions(UPubnubChannel* Channel) -
Channel->GetUserRestrictions());1Channel->GetUserRestrictions(UPubnubUser* User);
Output
| Parameter | Description |
|---|---|
FPubnubRestrictionType: struct | Returned object containing three fields: Ban, Mute, and Reason. |
→ BanType: bool | Info whether the user is banned from the channel. |
→ MuteType: bool | Info whether the user is muted on the channel. |
→ ReasonType: FString | Reason why the user was banned or muted. |
Sample code
Check if the user support_agent_15 has any restrictions set on the support channel.
-
GetChannelRestrictions()
show all 16 lines1#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
9// Define user ID
10FString UserID = "support_agent_15";
11
12// Get the user and save the reference
13UPubnubUser* User = Chat->GetUser(UserID);
14UPubnubChannel* Channel = Chat->GetChannel("support");
15 -
GetUserRestrictions()
show all 16 lines1#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
9// Define user ID
10FString UserID = "support_agent_15";
11
12// Get the user and save the reference
13UPubnubUser* User = Chat->GetUser(UserID);
14UPubnubChannel* Channel = Chat->GetChannel("support");
15
One user on all channels
Check mute or ban restrictions for a user across all their channels with GetChannelsRestrictions().
Method signature
- Blueprint
- C++ / Input parameters
1User->GetChannelsRestrictions(
2 FString Sort = "",
3 int Limit = 0,
4 FPubnubPage Page = FPubnubPage()
5);
| Parameter | Description |
|---|---|
LimitType: intDefault: 100 | Number of objects to return in response. The default (and maximum) value is 100. |
PageType: FPubnubPageDefault: n/a | Object used for pagination to define which previous or next result page you want to fetch. |
→ NextType: FStringDefault: n/a | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. |
→ PrevType: FStringDefault: n/a | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the next parameter is supplied. |
SortType: FStringDefault: n/a | 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. |
Output
| Parameter | Description |
|---|---|
FPubnubChannelsRestrictionsWrapperType: struct | Returned object containing these fields: Page, Total, Status, and Restrictions. |
→ pageType: object | Object used for pagination to define which previous or next result page you want to fetch. |
→ NextType: FString | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. |
→ PrevType: FString | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the next parameter is supplied. |
→ TotalType: int | Total number of restrictions. |
→ StatusType: int | Status code of a server response, like 200. |
→ RestrictionsType: TArray<FPubnubChannelRestriction> | Array containing restrictions. |
→ BanType: bool | Info whether the user is banned from the given channel. |
→ MuteType: bool | Info whether the user is muted on the given channel. |
→ ReasonType: FString | Reason why the user was banned or muted. |
→ Channel IDType: FString | ID of the channel containing user restrictions. |
Sample code
List all mute and ban restrictions set for the user support_agent_15.
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
9// Define user ID
10FString UserID = "support_agent_15";
11
12// Get the user and save the reference
13UPubnubUser* User = Chat->GetUser(UserID);
14
15FPubnubChannelsRestrictionsWrapper Restrictions = User->GetChannelsRestrictions();
All users on one channel
Check mute or ban restrictions for all members of a channel with GetUsersRestrictions().
Method signature
- Blueprint
- C++ / Input parameters
1Channel->GetUsersRestrictions(
2 FString Sort = "",
3 int Limit = 0,
4 FPubnubPage Page = FPubnubPage()
5);
| Parameter | Description |
|---|---|
LimitType: intDefault: 100 | Number of objects to return in response. The default (and maximum) value is 100. |
PageType: FPubnubPageDefault: n/a | Object used for pagination to define which previous or next result page you want to fetch. |
→ NextType: FStringDefault: n/a | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. |
→ PrevType: FStringDefault: n/a | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the next parameter is supplied. |
SortType: FStringDefault: n/a | 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. |
Output
| Parameter | Description |
|---|---|
FPubnubUsersRestrictionsWrapperType: struct | Returned object containing these fields: Page, Total, Status, and Restrictions. |
→ pageType: object | Object used for pagination to define which previous or next result page you want to fetch. |
→ NextType: FString | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. |
→ PrevType: FString | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the next parameter is supplied. |
→ TotalType: int | Total number of restrictions. |
→ StatusType: int | Status code of a server response, like 200. |
→ RestrictionsType: TArray<FPubnubUserRestriction> | Array containing restrictions. |
→ BanType: bool | Info whether the user is banned from the given channel. |
→ MuteType: bool | Info whether the user is muted on the given channel. |
→ ReasonType: FString | Reason why the user was banned or muted. |
→ User IDType: FString | ID of the restricted user. |
Sample code
List all mute and ban restrictions set for 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
9UPubnubChannel* Channel = Chat->GetChannel("support");
10
11FPubnubUsersRestrictionsWrapper Restrictions = Channel->GetUsersRestrictions();
Secure moderation
Client-side UI restrictions (hiding channels, disabling input) can be bypassed. Secure with server-side logic using Access Manager, plus optional client-side feedback.
Server-side restrictions
Use Access Manager with Chat SDK methods to grant/revoke permissions based on muting/banning restrictions.
Recommended workflow:
- Admin sets restrictions via dashboard (e.g., Channel Monitor)
- Get moderation restrictions for users
- Call Access Manager API to generate/revoke tokens
Implementation steps:
-
Enable Access Manager in the Admin Portal.
-
Initialize Chat SDK with
Auth Keyon the frontend to authenticate users and grant access to PubNub resources. -
Initialize backend with
Secret Keyusing the Unreal SDK to secure your PubNub instance.tip
Secret Keysigns and verifies messages for Access Manager. Never expose to clients. -
Get user permissions - Retrieve restrictions with Get user details and Check restrictions, then convert to permission format (read/write/access per channel).
-
Generate authorization token - Assign an access token with channel permissions and validity period.
tip
See Permissions for the complete operation-to-permission mapping.
Short TTLs recommended
Use short-lived tokens (TTLs) for up-to-date restrictions.
-
Listen for moderation events - Listen for the
moderationevent type (banned,muted, orlifted). -
Act on moderation events - Update permissions and generate new tokens as needed.
Client-side restrictions
With server-side permissions enforced, add optional client-side UI feedback. Read moderation restrictions to display popup messages or icons informing users about their mute/ban status before they attempt restricted actions.
Listen to moderation events
ListenForEvents() sends notifications when users are muted/banned or removes memberships on ban.
Events documentation
See Chat events for moderation event details.
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 moderation events. It is the user's channel (ID of the moderated user) which you want to get moderation events from. Should be prefixed with PUBNUB_INTERNAL_MODERATION.. |
ChatEventTypeType: EPubnubChatEventTypeDefault: n/a | Type of events. PCET_MODERATION is the type defined for all report events. |
EventCallback *Type: FOnPubnubEventReceivedDefault: n/a | Callback function passed as a parameter. It defines the custom behavior to be executed whenever a report 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 moderation events on the user123 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 UserID = "user123";
10FString ChannelID = "PUBNUB_INTERNAL_MODERATION." + UserID;
11
12// Create a pubnub response delegate
13// you MUST implement your own callback function to handle the response
14FOnPubnubEventReceived ListenResponse;
15ListenResponse.BindDynamic(this, &AMyActor::OnListenResponseReceived);
show all 21 lines