Skip to main content
Unlisted page
This page is unlisted. Search engines will not index it, and only users having a direct link can access it.

Introduction to the chat filter

Last updated on January 14, 57241

Overview

The chat filter in AccelByte Gaming Services (AGS) can be customized via Extend. In this guide, we will present the contract of the customization with example code for how to create a custom chat filter that takes chat messages and returns them with certain words filtered. We do this using the FilterBulk function in the contract as shown below.

service FilterService {
...
rpc FilterBulk(ChatMessageBulk) returns (MessageBatchResult);
}

FilterBulk

The FilterBulk function will be called when there are chats from players. A single invocation of this function may contain more than one chat message. In this example, we will loop through all chat messages received and, if IsProfane(...) detects certain words, we will Censor(...) it and return the results back.

Here is a code example:

func (s FilterServiceServer) FilterBulk(ctx context.Context, chatMessages *pb.ChatMessageBulk) (*pb.MessageBatchResult, error) {
result := &pb.MessageBatchResult{
Data: make([]*pb.MessageResult, len(chatMessages.GetMessages())),
}

for index, chatMessage := range chatMessages.GetMessages() {
action := pb.MessageResult_PASS
timestamp := chatMessage.GetTimestamp()
message := chatMessage.GetMessage()
if s.detector.IsProfane(chatMessage.GetMessage()) {
action = pb.MessageResult_CENSORED
timestamp = time.Now().Unix()
message = s.detector.Censor(message)
}
result.GetData()[index] = &pb.MessageResult{
Id: chatMessage.GetId(),
Timestamp: timestamp,
Action: action,
Classification: []pb.MessageResult_Classification{},
Message: message,
}
}

return result, nil
}
On this page