The Content Moderation feature enables you to moderate user-generated content to prevent vulgarity and inappropriate content from being shared on the application. The feature provides the following abilities:
- Filter objectionable material from being posted to the app
- Report offensive content and timely responses to concerns
- Block abusive users from the service
Filter Profanity from Messages
PubNub Profanity Filter enables you to moderate chat messages in real time as they go over the network using Functions. The function detects objectionable words in any given text, and lets you censor the content in a variety of ways. When you publish a message, it triggers the function to check the content of the message against a dictionary of objectionable words. You can either replace a portion of the text or completely block the message.
We've removed the list of objectionable words for the inline sample below. You can get the actual code from the gist.
Setting up the PubNub Function
Create a new function. Go to your PubNub Dashboard and create a new module, and then create a new Before Publish function. Set up the function to trigger on a specific set of channels (such as
chat.*), or on all channels using wildcards (
Copy the function code from the gist. Make changes as necessary to the dictionary, and configure the function to either replace the swear words, or block the entire message from being published on the channel.
Click Start module on the right to start the function, and test it using the Test Payload field and Publish button on the left.
Testing the Function
Input: Publish a message on any channel with a text field included.
Output: If profanity is present in the original message text, the output message will have the profanity filtered.
You can also select from a list of prebuilt Blocks or build your own logic to restrict adult content on your application. Refer to the Integrations section for more details.
PubNub provides a mechanism for users to report offensive content in messages directly from their applications. A moderator can then fetch these flagged messages from storage and either delete them or take appropriate action against the users who sent the messages.
addMessageAction method to add a flag as an action to a published message. When an action is added, it also publishes an event on the channel so users can hide the message on the app. The flag is stored and linked to the original message, so you can see if messages are flagged or not when you fetch them from storage.
Ban & Mute Users
Ban user in channels
To ban a user in channels, call the grant method and set the read and write permissions on the channels to false.
Mute user in channels
To mute a user in channels, call the grant method and set the write permissions on the channels to false.