Work with all messages sent in chat

Hello guys, in my resource, I will need to collect each one of the messages that are sent in the chat and work with them before they are displayed in the chat

Does anyone know how I can do to collect messages from people, even if they are not commands, and work with these messages before they are actually sent in the chat for everyone to see?

I’m noob to FiveM scripting too, but I think you can add an event handler to the addChat event, preprocess it, and eventually call CancelEvent if you want to block the message.

I don’t know Lua, but I did this in C# in my script:

EventHandlers["chatMessage"] += new Action<int, string, string>(OnChatMessage);

Then

private void OnChatMessage(int playerid, string color, string text)
{
    if (something)
    {
        CancelEvent(); // blocks the message
    }
}