Profanity filtering users can't bypass.
Chat, player names and group names, checked before other players see them, with before hooks you paste into your Nakama server.

lobby3 players
river_ottergg wp everyone
river_otterthis lag is ******* unbearable
Message not sent.Only you see this
gg wp everyonethis lag is fucking unbearablei hate you and everyone in this lobby hates you tooMessage #lobby
Build with a test key, 100 checks a month; switch to a live key when you ship.
Nakama 3, with its TypeScript, Go or Lua runtime.
The module was run on Nakama 3.41.0.
An Unprofane key from the keys page of the dashboard: a test key (up_test_…) to build with, a live key (up_live_…) in production.
Add the key under runtime.env in your Nakama config.
The module reads it from there, and your game client never holds it.
config.yml
runtime:
env:
- "UNPROFANE_API_KEY=up_live_YOUR_KEY"One file, in the language your server code is written in. Every hook it adds is listed at the end of it.
// Unprofane for Nakama: chat, player names and group names, checked before other players see them.
// Set UNPROFANE_API_KEY under runtime.env in your Nakama config. Build to ES5, as Nakama's runtime needs.
const UNPROFANE = 'https://api.unprofane.com/v1/check';
// Who the game is for: kids, teen, standard or strict (https://unprofane.com/docs/policies/).
const POLICY = 'teen';
// The field of a chat message's JSON content that holds what the player typed.
const MESSAGE_FIELD = 'message';
interface Check {
allowed: boolean;
censored: string;
matches: Array<{ category: string }>;
decided_by: Array<{ from: 'words' | 'context' }>;
}
/** One check, or null when Unprofane did not answer: each caller decides what that means. */
function check(
ctx: nkruntime.Context,
logger: nkruntime.Logger,
nk: nkruntime.Nakama,
text: string,
context: string,
): Check | null {
try {
const res = nk.httpRequest(
UNPROFANE,
'post',
{ Authorization: 'Bearer ' + ctx.env.UNPROFANE_API_KEY, 'Content-Type': 'application/json' },
JSON.stringify({ text: text, context: context, policy: POLICY }),
2000,
);
if (res.code === 200) return JSON.parse(res.body);
logger.warn('Unprofane answered %v: %v', res.code, res.body);
} catch (e) {
logger.warn('Unprofane did not answer: %v', String(e));
}
return null;
}
/** An error the player's client receives with this message. */
function refusal(message: string, code = nkruntime.Codes.INVALID_ARGUMENT): nkruntime.Error {
return { message: message, code: code };
}
/**
* A chat line as the channel will read it: unchanged when it is allowed, masked when
* the words that decided it can be hidden, and refused when there is no word to hide.
*/
function chatLine(
ctx: nkruntime.Context,
logger: nkruntime.Logger,
nk: nkruntime.Nakama,
content: string,
): string {
let body: { [field: string]: unknown };
try {
body = JSON.parse(content);
} catch {
return content;
}
const text = body && typeof body === 'object' ? body[MESSAGE_FIELD] : undefined;
if (typeof text !== 'string' || !text.trim()) return content;
const r = check(ctx, logger, nk, text, 'gaming');
// No answer: chat keeps flowing, unchecked. To hold every line instead, throw here.
if (!r || r.allowed) return content;
if (r.decided_by.every((d) => d.from === 'words')) {
body[MESSAGE_FIELD] = r.censored;
return JSON.stringify(body);
}
throw refusal('Message not sent.');
}
function beforeChannelMessageSend(
ctx: nkruntime.Context,
logger: nkruntime.Logger,
nk: nkruntime.Nakama,
envelope: nkruntime.EnvelopeChannelMessageSend,
): nkruntime.EnvelopeChannelMessageSend {
const message = envelope.channelMessageSend;
message.content = chatLine(ctx, logger, nk, message.content);
return envelope;
}
function beforeChannelMessageUpdate(
ctx: nkruntime.Context,
logger: nkruntime.Logger,
nk: nkruntime.Nakama,
envelope: nkruntime.EnvelopeChannelMessageUpdate,
): nkruntime.EnvelopeChannelMessageUpdate {
const message = envelope.channelMessageUpdate;
message.content = chatLine(ctx, logger, nk, message.content);
return envelope;
}
/** Throws the words the player reads when a name or a description cannot be used. */
function guard(
ctx: nkruntime.Context,
logger: nkruntime.Logger,
nk: nkruntime.Nakama,
text: string | undefined,
context: string,
what: string,
): void {
if (!text) return;
const r = check(ctx, logger, nk, text, context);
// No answer is not a yes: refused for now, and the player tries again.
if (!r)
throw refusal('The ' + what + ' could not be checked. Try again.', nkruntime.Codes.UNAVAILABLE);
if (r.allowed) return;
throw refusal(
r.matches[0]?.category === 'reserved'
? 'That name is reserved.'
: 'Pick a different ' + what + '.',
);
}
/** A sign-up by any method. A returning player sends a name that exists, so only a new one is checked. */
function signUpName<T extends { username?: string }>(
ctx: nkruntime.Context,
logger: nkruntime.Logger,
nk: nkruntime.Nakama,
data: T,
): T {
if (data.username && nk.usersGetUsername([data.username]).length === 0)
guard(ctx, logger, nk, data.username, 'username', 'username');
return data;
}
/** A change to the profile. Only what changes is checked, however much of it the client sends. */
function beforeUpdateAccount(
ctx: nkruntime.Context,
logger: nkruntime.Logger,
nk: nkruntime.Nakama,
data: nkruntime.UserUpdateAccount,
): nkruntime.UserUpdateAccount {
const user = nk.accountGetId(ctx.userId!).user;
if (data.username !== user.username)
guard(ctx, logger, nk, data.username, 'username', 'username');
if (data.displayName !== user.displayName)
guard(ctx, logger, nk, data.displayName, 'display_name', 'display name');
return data;
}
/** A group or clan, made or changed: its name, and its description. */
function groupText<T extends { name?: string; description?: string }>(
ctx: nkruntime.Context,
logger: nkruntime.Logger,
nk: nkruntime.Nakama,
data: T,
): T {
guard(ctx, logger, nk, data.name, 'username', 'group name');
guard(ctx, logger, nk, data.description, 'gaming', 'group description');
return data;
}
function InitModule(
ctx: nkruntime.Context,
logger: nkruntime.Logger,
nk: nkruntime.Nakama,
initializer: nkruntime.Initializer,
) {
if (!ctx.env.UNPROFANE_API_KEY)
throw new Error('Set UNPROFANE_API_KEY under runtime.env in your Nakama config.');
// Chat: a line, and an edit to one.
initializer.registerRtBefore('ChannelMessageSend', beforeChannelMessageSend);
initializer.registerRtBefore('ChannelMessageUpdate', beforeChannelMessageUpdate);
// Names: a sign-up by any method, and a change later.
initializer.registerBeforeAuthenticateDevice(signUpName);
initializer.registerBeforeAuthenticateEmail(signUpName);
initializer.registerBeforeAuthenticateCustom(signUpName);
initializer.registerBeforeAuthenticateApple(signUpName);
initializer.registerBeforeAuthenticateGoogle(signUpName);
initializer.registerBeforeAuthenticateFacebook(signUpName);
initializer.registerBeforeAuthenticateFacebookInstantGame(signUpName);
initializer.registerBeforeAuthenticateGameCenter(signUpName);
initializer.registerBeforeAuthenticateSteam(signUpName);
initializer.registerBeforeUpdateAccount(beforeUpdateAccount);
// Groups and clans.
initializer.registerBeforeCreateGroup(groupText);
initializer.registerBeforeUpdateGroup(groupText);
logger.info('Unprofane checks chat, names and groups under the %v policy.', POLICY);
}teen lets a taunt about play through and masks swearing; standard also lets swearing at the game through, and kids acts on both.gg ez is a taunt, not an insult, and a threat outside the game still counts.censored hides them: the channel reads the masked line.Message not sent. and nobody else sees the line.// Unprofane for Nakama: chat, player names and group names, checked before other players see them.
// Set UNPROFANE_API_KEY under runtime.env in your Nakama config, and build with the
// nakama-pluginbuilder image of your Nakama's version.
package main
import (
"bytes"
"context"
"database/sql"
"encoding/json"
"errors"
"io"
"net/http"
"strings"
"time"
"github.com/heroiclabs/nakama-common/api"
"github.com/heroiclabs/nakama-common/rtapi"
"github.com/heroiclabs/nakama-common/runtime"
)
const (
unprofaneURL = "https://api.unprofane.com/v1/check"
// Who the game is for: kids, teen, standard or strict (https://unprofane.com/docs/policies/).
policy = "teen"
// The field of a chat message's JSON content that holds what the player typed.
messageField = "message"
// The codes Nakama sends the client with an error.
codeInvalidArgument = 3
codeUnavailable = 14
)
type checkResult struct {
Allowed bool `json:"allowed"`
Censored string `json:"censored"`
Matches []struct {
Category string `json:"category"`
} `json:"matches"`
DecidedBy []struct {
From string `json:"from"`
} `json:"decided_by"`
}
type unprofane struct {
key string
client *http.Client
}
// check returns nil when Unprofane did not answer: each caller decides what that means.
func (u *unprofane) check(ctx context.Context, logger runtime.Logger, text, kind string) *checkResult {
body, _ := json.Marshal(map[string]string{"text": text, "context": kind, "policy": policy})
req, err := http.NewRequestWithContext(ctx, http.MethodPost, unprofaneURL, bytes.NewReader(body))
if err != nil {
logger.Warn("Unprofane request: %v", err)
return nil
}
req.Header.Set("Authorization", "Bearer "+u.key)
req.Header.Set("Content-Type", "application/json")
res, err := u.client.Do(req)
if err != nil {
logger.Warn("Unprofane did not answer: %v", err)
return nil
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
msg, _ := io.ReadAll(io.LimitReader(res.Body, 512))
logger.Warn("Unprofane answered %v: %s", res.StatusCode, msg)
return nil
}
var r checkResult
if err := json.NewDecoder(res.Body).Decode(&r); err != nil {
logger.Warn("Unprofane's answer could not be read: %v", err)
return nil
}
return &r
}
// chatLine is a chat line as the channel will read it: unchanged when it is allowed, masked
// when the words that decided it can be hidden, and refused when there is no word to hide.
func (u *unprofane) chatLine(ctx context.Context, logger runtime.Logger, content string) (string, error) {
var body map[string]any
if json.Unmarshal([]byte(content), &body) != nil {
return content, nil
}
text, _ := body[messageField].(string)
if strings.TrimSpace(text) == "" {
return content, nil
}
r := u.check(ctx, logger, text, "gaming")
// No answer: chat keeps flowing, unchecked. To hold every line instead, return an error here.
if r == nil || r.Allowed {
return content, nil
}
for _, d := range r.DecidedBy {
if d.From != "words" {
return "", runtime.NewError("Message not sent.", codeInvalidArgument)
}
}
body[messageField] = r.Censored
masked, err := json.Marshal(body)
if err != nil {
return "", err
}
return string(masked), nil
}
func (u *unprofane) beforeChannelMessageSend(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *rtapi.Envelope) (*rtapi.Envelope, error) {
if message := in.GetChannelMessageSend(); message != nil {
line, err := u.chatLine(ctx, logger, message.Content)
if err != nil {
return nil, err
}
message.Content = line
}
return in, nil
}
func (u *unprofane) beforeChannelMessageUpdate(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *rtapi.Envelope) (*rtapi.Envelope, error) {
if message := in.GetChannelMessageUpdate(); message != nil {
line, err := u.chatLine(ctx, logger, message.Content)
if err != nil {
return nil, err
}
message.Content = line
}
return in, nil
}
// guard returns the words the player reads when a name or a description cannot be used.
func (u *unprofane) guard(ctx context.Context, logger runtime.Logger, text, kind, what string) error {
if text == "" {
return nil
}
r := u.check(ctx, logger, text, kind)
// No answer is not a yes: refused for now, and the player tries again.
if r == nil {
return runtime.NewError("The "+what+" could not be checked. Try again.", codeUnavailable)
}
if r.Allowed {
return nil
}
if len(r.Matches) > 0 && r.Matches[0].Category == "reserved" {
return runtime.NewError("That name is reserved.", codeInvalidArgument)
}
return runtime.NewError("Pick a different "+what+".", codeInvalidArgument)
}
// signUpName checks a sign-up by any method. A returning player sends a name that exists,
// so only a new one is checked.
func signUpName[T interface{ GetUsername() string }](u *unprofane) func(context.Context, runtime.Logger, *sql.DB, runtime.NakamaModule, T) (T, error) {
return func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in T) (T, error) {
var none T
name := in.GetUsername()
if name == "" {
return in, nil
}
users, err := nk.UsersGetUsername(ctx, []string{name})
if err != nil {
return none, err
}
if len(users) == 0 {
if err := u.guard(ctx, logger, name, "username", "username"); err != nil {
return none, err
}
}
return in, nil
}
}
// beforeUpdateAccount checks a change to the profile. Only what changes is checked,
// however much of it the client sends.
func (u *unprofane) beforeUpdateAccount(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.UpdateAccountRequest) (*api.UpdateAccountRequest, error) {
userID, _ := ctx.Value(runtime.RUNTIME_CTX_USER_ID).(string)
account, err := nk.AccountGetId(ctx, userID)
if err != nil {
return nil, err
}
if name := in.GetUsername(); name != nil && name.Value != account.User.Username {
if err := u.guard(ctx, logger, name.Value, "username", "username"); err != nil {
return nil, err
}
}
if name := in.GetDisplayName(); name != nil && name.Value != account.User.DisplayName {
if err := u.guard(ctx, logger, name.Value, "display_name", "display name"); err != nil {
return nil, err
}
}
return in, nil
}
// groupText checks a group or clan's name and description, when it is made or changed.
func (u *unprofane) groupText(ctx context.Context, logger runtime.Logger, name, description string) error {
if err := u.guard(ctx, logger, name, "username", "group name"); err != nil {
return err
}
return u.guard(ctx, logger, description, "gaming", "group description")
}
func (u *unprofane) beforeCreateGroup(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.CreateGroupRequest) (*api.CreateGroupRequest, error) {
if err := u.groupText(ctx, logger, in.GetName(), in.GetDescription()); err != nil {
return nil, err
}
return in, nil
}
func (u *unprofane) beforeUpdateGroup(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.UpdateGroupRequest) (*api.UpdateGroupRequest, error) {
if err := u.groupText(ctx, logger, in.GetName().GetValue(), in.GetDescription().GetValue()); err != nil {
return nil, err
}
return in, nil
}
func InitModule(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, initializer runtime.Initializer) error {
env, _ := ctx.Value(runtime.RUNTIME_CTX_ENV).(map[string]string)
if env["UNPROFANE_API_KEY"] == "" {
return errors.New("set UNPROFANE_API_KEY under runtime.env in your Nakama config")
}
u := &unprofane{key: env["UNPROFANE_API_KEY"], client: &http.Client{Timeout: 2 * time.Second}}
for _, err := range []error{
// Chat: a line, and an edit to one.
initializer.RegisterBeforeRt("ChannelMessageSend", u.beforeChannelMessageSend),
initializer.RegisterBeforeRt("ChannelMessageUpdate", u.beforeChannelMessageUpdate),
// Names: a sign-up by any method, and a change later.
initializer.RegisterBeforeAuthenticateDevice(signUpName[*api.AuthenticateDeviceRequest](u)),
initializer.RegisterBeforeAuthenticateEmail(signUpName[*api.AuthenticateEmailRequest](u)),
initializer.RegisterBeforeAuthenticateCustom(signUpName[*api.AuthenticateCustomRequest](u)),
initializer.RegisterBeforeAuthenticateApple(signUpName[*api.AuthenticateAppleRequest](u)),
initializer.RegisterBeforeAuthenticateGoogle(signUpName[*api.AuthenticateGoogleRequest](u)),
initializer.RegisterBeforeAuthenticateFacebook(signUpName[*api.AuthenticateFacebookRequest](u)),
initializer.RegisterBeforeAuthenticateFacebookInstantGame(signUpName[*api.AuthenticateFacebookInstantGameRequest](u)),
initializer.RegisterBeforeAuthenticateGameCenter(signUpName[*api.AuthenticateGameCenterRequest](u)),
initializer.RegisterBeforeAuthenticateSteam(signUpName[*api.AuthenticateSteamRequest](u)),
initializer.RegisterBeforeUpdateAccount(u.beforeUpdateAccount),
// Groups and clans.
initializer.RegisterBeforeCreateGroup(u.beforeCreateGroup),
initializer.RegisterBeforeUpdateGroup(u.beforeUpdateGroup),
} {
if err != nil {
return err
}
}
logger.Info("Unprofane checks chat, names and groups under the %v policy.", policy)
return nil
}teen lets a taunt about play through and masks swearing; standard also lets swearing at the game through, and kids acts on both.gg ez is a taunt, not an insult, and a threat outside the game still counts.Message not sent. and nobody else sees the line.censored hides them: the channel reads the masked line.-- Unprofane for Nakama: chat, player names and group names, checked before other players see them.
-- Set UNPROFANE_API_KEY under runtime.env in your Nakama config.
local nk = require("nakama")
local UNPROFANE = "https://api.unprofane.com/v1/check"
-- Who the game is for: kids, teen, standard or strict (https://unprofane.com/docs/policies/).
local POLICY = "teen"
-- The field of a chat message's JSON content that holds what the player typed.
local MESSAGE_FIELD = "message"
-- The codes Nakama sends the client with an error.
local INVALID_ARGUMENT = 3
local UNAVAILABLE = 14
-- One check, or nil when Unprofane did not answer: each caller decides what that means.
local function check(context, text, kind)
local headers = {
["Authorization"] = "Bearer " .. (context.env["UNPROFANE_API_KEY"] or ""),
["Content-Type"] = "application/json",
}
local body = nk.json_encode({ text = text, context = kind, policy = POLICY })
local ok, code, _, answer = pcall(nk.http_request, UNPROFANE, "post", headers, body, 2000)
if not ok then
nk.logger_warn("Unprofane did not answer: " .. tostring(code))
return nil
end
if code ~= 200 then
nk.logger_warn("Unprofane answered " .. code .. ": " .. answer)
return nil
end
return nk.json_decode(answer)
end
-- A chat line as the channel will read it: unchanged when it is allowed, masked when
-- the words that decided it can be hidden, and refused when there is no word to hide.
local function chat_line(context, content)
local ok, body = pcall(nk.json_decode, content)
if not ok or type(body) ~= "table" then
return content
end
local text = body[MESSAGE_FIELD]
if type(text) ~= "string" or text:match("^%s*$") then
return content
end
local r = check(context, text, "gaming")
-- No answer: chat keeps flowing, unchecked. To hold every line instead, raise an error here.
if r == nil or r.allowed then
return content
end
for _, d in ipairs(r.decided_by) do
if d.from ~= "words" then
error({ "Message not sent.", INVALID_ARGUMENT })
end
end
body[MESSAGE_FIELD] = r.censored
return nk.json_encode(body)
end
local function before_channel_message_send(context, envelope)
local message = envelope.channel_message_send
message.content = chat_line(context, message.content)
return envelope
end
local function before_channel_message_update(context, envelope)
local message = envelope.channel_message_update
message.content = chat_line(context, message.content)
return envelope
end
-- Raises the words the player reads when a name or a description cannot be used.
local function guard(context, text, kind, what)
if text == nil or text == "" then
return
end
local r = check(context, text, kind)
-- No answer is not a yes: refused for now, and the player tries again.
if r == nil then
error({ "The " .. what .. " could not be checked. Try again.", UNAVAILABLE })
end
if r.allowed then
return
end
if r.matches[1] and r.matches[1].category == "reserved" then
error({ "That name is reserved.", INVALID_ARGUMENT })
end
error({ "Pick a different " .. what .. ".", INVALID_ARGUMENT })
end
-- A sign-up by any method. A returning player sends a name that exists, so only a new one is checked.
local function sign_up_name(context, payload)
local name = payload.username
if name ~= nil and name ~= "" and #nk.users_get_username({ name }) == 0 then
guard(context, name, "username", "username")
end
return payload
end
-- A change to the profile. Only what changes is checked, however much of it the client sends.
local function before_update_account(context, payload)
local user = nk.account_get_id(context.user_id).user
if payload.username ~= nil and payload.username ~= user.username then
guard(context, payload.username, "username", "username")
end
if payload.display_name ~= nil and payload.display_name ~= user.display_name then
guard(context, payload.display_name, "display_name", "display name")
end
return payload
end
-- A group or clan, made or changed: its name, and its description.
local function group_text(context, payload)
guard(context, payload.name, "username", "group name")
guard(context, payload.description, "gaming", "group description")
return payload
end
-- Chat: a line, and an edit to one.
nk.register_rt_before(before_channel_message_send, "ChannelMessageSend")
nk.register_rt_before(before_channel_message_update, "ChannelMessageUpdate")
-- Names: a sign-up by any method, and a change later.
for _, method in ipairs({
"AuthenticateDevice", "AuthenticateEmail", "AuthenticateCustom", "AuthenticateApple",
"AuthenticateGoogle", "AuthenticateFacebook", "AuthenticateFacebookInstantGame",
"AuthenticateGameCenter", "AuthenticateSteam",
}) do
nk.register_req_before(sign_up_name, method)
end
nk.register_req_before(before_update_account, "UpdateAccount")
-- Groups and clans.
nk.register_req_before(group_text, "CreateGroup")
nk.register_req_before(group_text, "UpdateGroup")
nk.logger_info("Unprofane checks chat, names and groups under the " .. POLICY .. " policy.")teen lets a taunt about play through and masks swearing; standard also lets swearing at the game through, and kids acts on both.gg ez is a taunt, not an insult, and a threat outside the game still counts.Message not sent. and nobody else sees the line.censored hides them: the channel reads the masked line.Complete as printed: it reads the key from the config. Chat goes as context: "gaming", names as "username", both under the teen policy.
Put the file at src/main.ts in your Nakama TypeScript project. It builds with Heroic Labs’ usual tsconfig.json: ES5, into one build/index.js.
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"lib": ["es2015"],
"outFile": "./build/index.js",
"typeRoots": ["./node_modules"],
"strict": true,
"removeComments": false,
"skipLibCheck": true
},
"files": ["./node_modules/nakama-runtime/index.d.ts"],
"include": ["src/**/*"]
}Install Nakama’s runtime types beside TypeScript 5.9: Nakama needs ES5, which TypeScript 6 marks deprecated.
npm install --save-dev typescript@5.9.3 github:heroiclabs/nakama-common#v1.48.0Build it, and point runtime.js_entrypoint at build/index.js.
npx tscNakama runs one InitModule. If you have one, rename this one initUnprofane and call it from yours.
Put main.go in a folder of its own, beside this go.mod. Its nakama-common must be the version your Nakama uses.
go.mod
module unprofane-nakama
go 1.27.1
require github.com/heroiclabs/nakama-common v1.48.0
require google.golang.org/protobuf v1.36.12 // indirectFetch what it needs with the plugin builder image tagged with your Nakama’s exact version.
docker run --rm -w /builder -v "$PWD:/builder" heroiclabs/nakama-pluginbuilder:3.41.0 mod tidyBuild it with the same image.
docker run --rm -w /builder -v "$PWD:/builder" heroiclabs/nakama-pluginbuilder:3.41.0 build -buildmode=plugin -trimpath -o ./unprofane.so .Put unprofane.so in data/modules beside your own plugin: Nakama runs the InitModule of each.
Put unprofane.lua in data/modules. Nakama loads every Lua file there when it starts; there is nothing to build.
Say this lag is fucking unbearable in any channel: the other players read this lag is ******* unbearable.
Sign up as admin: the client gets That name is reserved. Sign up as river_otter: it goes through.
What the run sent, as two players, and what came backNakama 3.41.0nakama-js 2.8.0TypeScript 5.9.3Postgres 16
What the other players read depends on what decided the answer.
allowSent as typed
Typedgg wp everyone
Others readgg wp everyone
Nothing to hide.
blockSent masked
Typedthis lag is fucking unbearable
Others readthis lag is ******* unbearable
Listed words decided it, so the module sends censored.
blockNot sent
Typedi hate you and everyone in this lobby hates you too
Others readNothing. The sender's client gets Message not sent.
The model decided it, with no word to mask. Only the sender is told.
The same module checks every name a player types and every group a player makes.
| Where | Nakama hooks | Read as | The player reads |
|---|---|---|---|
| Sign-up | Device, email, custom ID, Apple, Google, Facebook, Facebook Instant Games, Game Center, Steam | username | Pick a different username. |
| Username change | Update account | username | Pick a different username. |
| Display name | Update account | display_name | Pick a different display name. |
| Group name | Create group, update group | username | Pick a different group name. |
| Group description | Create group, update group | gaming | Pick a different group description. |
A name that claims to be the game or its staff, such as admin or moderators, gets That name is reserved. instead.
When it runs, what it costs, and what usually goes wrong.
Before anyone reads it. Nakama runs a before hook ahead of its own work, so a chat line is checked before it is stored in the channel’s history or sent to anyone, and a name before it is saved. A line the module refuses never reaches the channel.
A chat line has no moderator queue, so the module treats review like block. A line whose listed words decided it is sent with those words masked; a line the model decided, with no word to mask, is not sent. A name or a description is refused outright, with words the player can act on: Pick a different username., or That name is reserved. for a name that claims to be the game or its staff.
Every field of the answer is in the API reference.
Each check waits two seconds at most. When Unprofane does not answer in time, or answers with an error, chat goes out unchecked, so a slow check never stops a match; a comment in the code marks the line to change to hold chat instead. A new name or description is refused, with words such as The username could not be checked. Try again., so nothing unchecked is saved. A returning player still signs in: their name is not checked again.
Every chat line with text is one check, and so is every new name or description. A returning player’s sign-in, an unchanged name and a message with no text field cost none. The plans are on the pricing page.
The hooks run on what players send. A message your own server code sends with channelMessageSend passes no hook: check it in that code before you send it.
Each module was built as this page says, loaded into Nakama 3.41.0 in Docker with a fresh Postgres 16, and played by two players on Heroic Labs’ JavaScript client 2.8.0: every step of the log, then the same with Unprofane held past the two-second timeout. Unprofane was its API run locally with the model stood in for, so a line the model decides was decided by the stand-in. The modules ran exactly as printed here, with only the API’s address changed.
Set UNPROFANE_API_KEY under runtime.envThe key is not in the config Nakama read. Add it under runtime.env, or pass --runtime.env UNPROFANE_API_KEY=…, and start Nakama again.
Your client puts the text in a field other than message: set MESSAGE_FIELD to it. Otherwise Nakama’s log says why, in a line that starts Unprofane answered or Unprofane did not answer.
TypeError: Object has no member when Nakama startsYour Nakama is older than the hook named. Remove that one registration, or upgrade Nakama.
plugin was built with a different version of packageBuild it with the nakama-pluginbuilder image tagged with your Nakama’s exact version, and keep nakama-common in go.mod at the version that Nakama uses.
target: ES5 is deprecatedThat is TypeScript 6. Install typescript@5.9.3, as the install line above does.
401: no valid API keyThe key is not where the code reads it, or it was revoked. Set it again and deploy again.
402: a plan is requiredA live or publishable key needs a plan. Build with a test key (up_test_…), which needs none.
429: too many requestsA test key’s free checks are capped across the account, a month’s with no plan and a day’s on one, and every plan has a per-minute limit. The answer’s type says which.
Every error, and what to send instead, is on the errors page.
A name screen can hint while the player types; the module above still decides.
Add the file, set the key, and say this lag is fucking unbearable in your lobby.