AI Moderation in the CometChat SDK helps ensure that your chat application remains safe and compliant by automatically reviewing messages for inappropriate content. This feature leverages AI to moderate messages in real-time, reducing manual intervention and improving user experience.For a broader understanding of moderation features, see the Moderation Overview.
When sending text, image, or video messages, the moderation process introduces the following changes to the message flow:
Initial Status:
On successfully sending a text, image, or video message, the response will include the moderation status as pending.
You can fetch this status using the getModerationStatus() method, which returns an Enum: ModerationStatus.PENDING.
Moderation Result Event:
Once the moderation service processes the message, a real-time event is triggered in your MessageListener as onMessageModerated.
This event provides the message object with the updated moderation status, which will be either ModerationStatus.APPROVED or ModerationStatus.DISAPPROVED.
Example:
Copy
Ask AI
// Check moderation status after sending a message. This check is only applicable for TextMessage & MediaMessage class.if(message.getModerationStatus().equals(ModerationStatus.PENDING)) { // Message is under moderation}// Listen for moderation resultCometChat.addMessageListener("UNIQUE_LISTENER_ID", new CometChat.MessageListener() { @Override public void onMessageModerated(BaseMessage message) { if(message instanceof TextMessage){ if(((TextMessage) message).getModerationStatus().equals(ModerationStatus.APPROVED)) { // Message approved } else if(((TextMessage) message).getModerationStatus().equals(ModerationStatus.DISAPPROVED)) { // Message disapproved } } else if(message instanceof MediaMessage){ if(((MediaMessage) message).getModerationStatus().equals(ModerationStatus.APPROVED)) { // Message approved } else if(((MediaMessage) message).getModerationStatus().equals(ModerationStatus.DISAPPROVED)) { // Message disapproved } } }});