NOTWENNODE
NW RP Chat 1.0.1

API & Exports

Eventos, exports e integración con otros recursos.

FiveM / CFXESX · QBCore · QboxStandalone bridge
NW RP Chat — presentación del productoVer demo interactiva ↗

Public interface documented from the shipping resource. Only supported exports and documented standard chat events are listed; Lua client and server contexts must not be mixed. Callers should validate their own inputs and gameplay rules.

Use the exports below from your own resources. Client exports run in client scripts; server exports run in server scripts. Start nw_rpchat before resources that call its exports. Keep the resource folder name nw_rpchat.

The examples define helpers for an existing workflow. They do not send messages or register channels at startup.

Existing chat integrations

NW RP Chat provides chat, qb-chat, esx_rpchat and qbx_chat in its manifest. It supports the standard chat:addMessage, chat:addTemplate, chat:addSuggestion, chat:addSuggestions, chat:removeSuggestion and chat:clear events. Existing exports['chat']:addMessage(...) integrations are also supported; the client additionally supports exports['chat']:addSuggestion(...).

Do not run a second chat UI alongside this resource. Compatibility covers the public interfaces listed here, rather than every private API from another chat product.

Client exports

Export Arguments Result
addMessage(message) Standard chat message table, or a string. No return value; displays the message on this client.
addSuggestion(name, help, params) Command name including /, description, optional array of { name, help }. No return value.
RefreshChannelPermissions() None. No return value; schedules a permission refresh when dynamic permissions are enabled.
-- Client script: call when your workflow completes.
local function showDeliveryComplete()
    exports['nw_rpchat']:addMessage({
        color = { 36, 236, 112 },
        args = { 'DELIVERY', 'Delivery completed.' }
    })
end

Server message exports

Use a player's server ID for a single recipient, or -1 to broadcast where a target argument is accepted.

Export Arguments Result
addMessage(target, message) Standard chat message table. With only one argument, that argument is the message and the target is -1. No return value.
SendMessage(target, message, options) String or standard message table. For strings, options may contain author, args, color, templateId, multiline and not metadata. true after dispatch.
SendSystemMessage(target, text) Recipient and text. No return value.
SendStaffMessage(text) Text. No return value; sends to players with staff permission.
SendPrivateMessage(sourceId, targetId, text) Sender and recipient server IDs; sender 0 means SYSTEM. Boolean; respects private-message settings, recipient availability and player permissions/anti-spam.
SendJobMessage(jobs, text, options) Job name or array of names. Options: label, author, hex color, channelId, requireDuty. Number of recipients, or false for an empty/invalid job list. Duty is required only when requireDuty = true.
SendLocalMessage(sourceId, kind, text, range) Player sender, message kind such as me, do or ooc, text, optional distance. Boolean; uses local proximity and the configured anti-spam rules.
ClearChat(target) Recipient. No return value.
SendStructuredMessage(target, payload) message or text, optional title/author, kind, channel/category, hex color, fields, actions, actionTtl/ttl. false if disabled or text is empty; otherwise true, or an action token when actions are registered.
SendInteractiveMessage(target, payload) Same display fields as a structured message; requires a nonempty actions array. Optional sourceId and actionPlayerId identify a related player. Action token, or false if disabled/invalid.
InvalidateInteractiveMessage(token) Token created by this resource's caller. Boolean; a different owner receives false, 'owner_mismatch'.

SendMessage and the standard chat interfaces dispatch script-created content directly. They do not enforce player chat permission or anti-spam checks. Validate your own workflow before sending content. A successful dispatch is not a delivery acknowledgement.

Structured fields are an array of { label = '...', value = '...' }. Defaults allow six fields, with labels up to 32 bytes and values up to 96. Structured/interactive text is limited by Config.AntiSpam.maxLength (240 by default), and titles are limited to 48 bytes. These server-side limits use Lua string lengths, so non-ASCII characters can occupy more than one byte.

-- Server script: call after your server has completed the purchase.
local function sendPurchaseReceipt(playerId, itemLabel)
    return exports['nw_rpchat']:SendStructuredMessage(playerId, {
        title = 'PURCHASE',
        message = 'Your purchase is complete.',
        color = '#24EC70',
        fields = { { label = 'Item', value = itemLabel } }
    })
end

Channels

Export Arguments Result
RegisterChannel(id, definition) Unique ID and definition; alternatively one definition table containing id or command. true, channelId, or false, reason.
CreateChannelFromTemplate(id, templateName, overrides) Template from Config.ChannelTemplates.templates; optional overrides. true, channelId, or false, reason. Default templates: job, gang, event, local_job.
SendChannelMessage(channelId, sourceId, text, options) Registered channel, sender server ID (0 for SYSTEM), text; optional author. Boolean; checks player access, anti-spam and recipient access.
GetRegisteredChannels() None. Table keyed by channel ID with public configuration summaries.
CreateTemporaryChannel(id, definition) Definition with optional initial members. true, channelId, or false, reason. Forces member-only access and authorized recipients.
AddPlayerToChannel(channelId, playerId) Channel and player server ID. Boolean.
RemovePlayerFromChannel(channelId, playerId) Channel and player server ID. Boolean.
DeleteChannel(channelId) Channel owned by the calling resource. Boolean; a different owner receives false, 'owner_mismatch'.
RefreshPlayerChannels(playerId) Connected player server ID. Boolean; synchronizes channel suggestions and removes inaccessible channel views.

A channel definition may contain command, aliases, label, hex color, access, recipients, scope, range, jobs, gangs, ace/aces, members and requireDuty. Access modes are public, job, gang, ace, staff, members, job_or_ace, job_or_gang and job_gang_ace. recipients = 'authorized' restricts who can read; 'all' permits all recipients to read while keeping the sender's access check. scope is 'global' or 'local'.

Choose command names that do not conflict with other resources. Runtime channels and their membership are held in memory. Re-create them after a chat restart. Channels owned by a resource are removed when that resource stops. Default framework job/gang/duty events refresh player access automatically; use RefreshPlayerChannels after custom server-side permission changes.

-- Server script: call when your event starts, using its actual participants.
local function createEventChat(eventId, playerIds)
    local channelId = 'event_' .. tostring(eventId)
    local ok, result = exports['nw_rpchat']:CreateTemporaryChannel(channelId, {
        command = channelId,
        label = 'EVENT',
        color = '#24EC70',
        members = playerIds
    })
    if not ok then return false, result end
    exports['nw_rpchat']:SendChannelMessage(result, 0, 'Event chat is open.')
    return true, result
end
-- On completion: exports['nw_rpchat']:DeleteChannel(channelId)

Interactive actions

Each action accepts id, label, style (primary, danger or muted), serverEvent, clientEvent, data and once. event is an alias for serverEvent; once defaults to true for each recipient. A server event receives (playerId, data, context); a client event receives (data, context). Context contains token, actionId, playerId, ownerResource and createdAt.

The default limits are four actions per message, 90 seconds until expiry and a maximum requested lifetime of 180 seconds. Tokens are scoped to the recipient or broadcast audience, checked on the server, and removed when the owning resource stops. Validate the current workflow state in your action handler before changing inventory, money or other gameplay state.

-- Server script: call when a player receives an invitation.
local function sendEventInvitation(playerId, eventId)
    return exports['nw_rpchat']:SendInteractiveMessage(playerId, {
        title = 'EVENT',
        message = 'You have an event invitation.',
        ttl = 60,
        actions = {
            {
                id = 'accept', label = 'Accept',
                serverEvent = 'my_events:acceptChatInvitation',
                data = { eventId = eventId }
            }
        }
    })
end

-- Local server event: called by the validated chat action.
AddEventHandler('my_events:acceptChatInvitation', function(playerId, data, context)
    -- Check the invitation is still valid, then accept it in your event system.
end)

Editable hooks

Modify the following files to connect custom systems. Keep their existing function names and return contracts. Hooks are loaded when the chat resource starts; restart it after changes.

File / function Arguments Return
custom/client.lua: NotRPChatCustom.Notify (message, kind, duration, title) true when handled; otherwise false so auto mode can try the next adapter.
custom/server.lua: NotRPChatCustom.OnLog (kind, sourceId, text, extra) Return value is ignored. Built-in webhook logging remains independent.
custom/hooks/names.lua Returned function (sourceId, defaultName) Nonempty string to replace the display name; otherwise the default is retained.
custom/hooks/messages.lua Returned function (kind, payload) Table to replace the routed roleplay/channel payload; other returns keep the original. This hook does not cancel messages and does not cover every standard chat/API message.
custom/hooks/permissions.lua Returned function (sourceId, defaultAllowed) Boolean to override staff authorization; other returns retain the default.
custom/hooks/private.lua Returned function (sourceId, targetId, text, defaultAllowed) Boolean to allow/deny a player-originated private message; other returns retain the default. SYSTEM messages do not use this hook.
custom/hooks/police.lua Returned function (sourceId, defaultAllowed) Boolean to override permission to send /rpol; other returns retain the default.

Notification mode/order is configured in Config.Integrations.notify. Supported adapters are custom, framework, nw_notify, native and chat; mode none disables integration output. Default auto order is custom, framework, NW Notify, then native GTA notifications. nw_notify is optional. The adapter calls ShowNotification(message, kind, duration) and falls back to Notify(message, kind, duration, title).

bridge/server.lua adapts player identity, jobs, gangs, duty and staff permission for Qbox/QBX, QBCore, ESX and standalone. config/framework.lua allows resource aliases and Qbox fallback configuration. ESX and standalone do not supply a gang through the built-in bridge.

Product and framework information

These exports are server-only:

Export Result
GetFramework() Active framework name.
GetDetectionReport() Selected/active framework and detected Qbox, QBCore and ESX resource names or 'off'.
GetVersion() Version string from Config.Product.
GetProductInfo() name, version, edition, framework and enabled voice flag.
GetPlayerCommunicationContext(playerId) Connected player's id, name, job, gang, duty, staff and accessible channel IDs; nil for an invalid player.

Use configuration, hooks and public exports for integrations. Internal NUI callbacks and network events are implementation details.