[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"academy-blogs-en-1-1-all-message-filtering-websocket-chat-all--*":3,"academy-blog-translations-d6zazypgm15q020":79},{"data":4,"page":67,"perPage":67,"totalItems":67,"totalPages":67},[5],{"alt":6,"collectionId":7,"collectionName":8,"content":9,"cover_image":10,"cover_image_path":11,"created":12,"created_by":13,"expand":14,"id":73,"keywords":74,"locale":49,"published_at":75,"scheduled_at":13,"school_blog":71,"short_description":76,"slug":77,"status":69,"title":6,"updated":78,"updated_by":13,"views":72},"EP.65 Message Filtering in WebSocket Chat","sclblg987654321","school_blog_translations","\u003Cp>In EP.65, we will explore how to add Message Filtering in WebSocket Chat. This system will help chat room administrators filter inappropriate messages such as offensive words, inappropriate links, or other unwanted content in real-time. It will ensure that the chat remains a safe and secure environment.\u003C\u002Fp>\u003Cp>Message filtering is essential in maintaining security and order in real-time chat applications. By implementing this system, we can ensure that the content shared within the chat is appropriate for all users.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>Why is Message Filtering Important in WebSocket Chat?\u003C\u002Fh2>\u003Ch3>Message filtering helps by allowing the chat room admin to:\u003C\u002Fh3>\u003Cul>\u003Cli>Prevent inappropriate behavior: Filter out offensive language, inappropriate links, or illegal content from the chat.\u003C\u002Fli>\u003Cli>Maintain security: Prevent harmful or inappropriate messages from being sent in the chat.\u003C\u002Fli>\u003Cli>Enhance user experience: Allow users to chat without worrying about encountering inappropriate content.\u003C\u002Fli>\u003C\u002Ful>\u003Ch3>Benefits of Message Filtering:\u003C\u002Fh3>\u003Cul>\u003Cli>Creates a safe chat environment: Filters out unwanted or inappropriate content from the chat.\u003C\u002Fli>\u003Cli>Improves user experience: Ensures that users can chat safely without being exposed to offensive messages.\u003C\u002Fli>\u003Cli>Gives the admin more control: Admins can easily moderate and manage the content within the chat.\u003C\u002Fli>\u003C\u002Ful>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>Structure of Message Filtering in WebSocket Chat\u003C\u002Fh2>\u003Cp>Message filtering in WebSocket Chat works by checking incoming messages before they are sent to the chat room. If the message violates the defined rules, the system will reject or block it from being sent.\u003C\u002Fp>\u003Ch3>Key components of the message filtering system:\u003C\u002Fh3>\u003Col>\u003Cli>Filtering messages before sending:\u003Cbr>The system checks messages before sending them to the chat room.\u003C\u002Fli>\u003Cli>Checking for forbidden words:\u003Cbr>The system checks for inappropriate words or content using predefined rules or a database of banned words.\u003C\u002Fli>\u003Cli>Sending a notification to the user:\u003Cbr>When a message is filtered, the system will notify the user that the message could not be sent due to its inappropriate content.\u003C\u002Fli>\u003C\u002Fol>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>Implementing Message Filtering Features in WebSocket Server\u003C\u002Fh2>\u003Cp>To add the message filtering feature in the WebSocket Server, we need to implement a function that checks incoming messages and either accepts or rejects them based on predefined conditions.\u003C\u002Fp>\u003Ch3>Steps to implement:\u003C\u002Fh3>\u003Col>\u003Cli>Update WebSocket Server:\u003Cul>\u003Cli>Add a function to check each message before it is sent to the chat room.\u003C\u002Fli>\u003C\u002Ful>\u003C\u002Fli>\u003Cli>Add filtering for forbidden words or inappropriate content:\u003Cul>\u003Cli>Use regex or a list of banned words to check each message.\u003C\u002Fli>\u003C\u002Ful>\u003C\u002Fli>\u003Cli>Send a notification if the message is filtered:\u003Cul>\u003Cli>If the message is blocked, send a notification to the user that the message cannot be sent.\u003C\u002Fli>\u003C\u002Ful>\u003C\u002Fli>\u003C\u002Fol>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>Example Code for Message Filtering in WebSocket Server\u003C\u002Fh2>\u003Col>\u003Cli>\u003Ch3>Message Filtering in WebSocket Server\u003C\u002Fh3>\u003C\u002Fli>\u003C\u002Fol>\u003Cpre>\u003Ccode class=\"language-plaintext language-go\">package main\n\nimport (\n    \"fmt\"\n    \"net\u002Fhttp\"\n    \"strings\"\n    \"github.com\u002Fgorilla\u002Fwebsocket\"\n)\n\nvar upgrader = websocket.Upgrader{\n    CheckOrigin: func(r *http.Request) bool {\n        return true\n    },\n}\n\nfunc handleConnection(w http.ResponseWriter, r *http.Request) {\n    conn, err := upgrader.Upgrade(w, r, nil)\n    if err != nil {\n        fmt.Println(\"Error upgrading connection:\", err)\n        return\n    }\n    defer conn.Close()\n\n    for {\n        messageType, msg, err := conn.ReadMessage()\n        if err != nil {\n            fmt.Println(\"Error reading message:\", err)\n            break\n        }\n\n        \u002F\u002F Filter the message\n        if isInappropriate(msg) {\n            err = conn.WriteMessage(messageType, []byte(\"Message contains inappropriate content and was blocked\"))\n            if err != nil {\n                fmt.Println(\"Error sending message:\", err)\n                break\n            }\n            continue\n        }\n\n        \u002F\u002F Send the valid message to the chat room\n        err = conn.WriteMessage(messageType, msg)\n        if err != nil {\n            fmt.Println(\"Error sending message:\", err)\n            break\n        }\n    }\n}\n\nfunc isInappropriate(msg []byte) bool {\n    forbiddenWords := []string{\"badword\", \"offensive\"} \u002F\u002F List of forbidden words\n    for _, word := range forbiddenWords {\n        if strings.Contains(string(msg), word) {\n            return true\n        }\n    }\n    return false\n}\n\nfunc main() {\n    http.HandleFunc(\"\u002Fws\", handleConnection)\n    fmt.Println(\"WebSocket server running on port 8080\")\n    http.ListenAndServe(\":8080\", nil)\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>In this example, the WebSocket server filters messages that contain forbidden words like \u003Ccode inline=\"\">\"badword\"\u003C\u002Fcode> or \u003Ccode inline=\"\">\"offensive\"\u003C\u002Fcode>, and notifies the user if the message is blocked.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>Testing the Message Filtering System\u003C\u002Fh2>\u003Cp>After implementing the message filtering feature, it’s important to test the system to ensure it works as expected.\u003C\u002Fp>\u003Ch3>Tests to conduct:\u003C\u002Fh3>\u003Cul>\u003Cli>Test for forbidden words:\u003Cbr>Test the system by sending messages with banned words and verify that they are blocked.\u003C\u002Fli>\u003Cli>Test the message sending:\u003Cbr>Ensure that only valid messages pass through the filter and are sent to the chat room.\u003C\u002Fli>\u003Cli>Test the user notification:\u003Cbr>Verify that users are notified when their message is blocked due to inappropriate content.\u003C\u002Fli>\u003C\u002Ful>\u003Cp>&nbsp;\u003C\u002Fp>\u003Chr>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch3>Challenge!\u003C\u002Fh3>\u003Cp>Try adding \u003Cstrong>custom filtering rules\u003C\u002Fstrong> based on user roles. For example, allow admins to bypass the message filter, or allow certain users to use specific keywords that others cannot.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>\u003Cstrong>Next EP:\u003C\u002Fstrong>\u003Cbr>In \u003Cstrong>EP.66\u003C\u002Fstrong>, we will explore \u003Cstrong>Using Golang with JSON Web Tokens (JWT)\u003C\u002Fstrong> to manage \u003Cstrong>authentication\u003C\u002Fstrong> and \u003Cstrong>user login\u003C\u002Fstrong> systems, making user authentication more secure and efficient!\u003C\u002Fp>","102_11zon_yvqyw802x2.webp","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclblg987654321\u002Fuymtos7qordq74d\u002F102_11zon_yvqyw802x2.webp","2026-03-04 08:48:18.569Z","",{"keywords":15,"locale":43,"school_blog":53},[16,23,28,33,38],{"collectionId":17,"collectionName":18,"created":19,"created_by":13,"id":20,"name":21,"updated":22,"updated_by":13},"sclkey987654321","school_keywords","2026-03-04 08:48:16.045Z","oquh1nk04vozvr7","WebSocket message filtering","2026-04-10 16:13:43.668Z",{"collectionId":17,"collectionName":18,"created":24,"created_by":13,"id":25,"name":26,"updated":27,"updated_by":13},"2026-03-04 08:48:16.346Z","u0jh247dpv2rlv3","Message filtering WebSocket","2026-04-10 16:13:43.796Z",{"collectionId":17,"collectionName":18,"created":29,"created_by":13,"id":30,"name":31,"updated":32,"updated_by":13},"2026-03-04 08:45:10.623Z","2zhfdpu8sy1xeju","Golang WebSocket","2026-04-10 16:12:55.126Z",{"collectionId":17,"collectionName":18,"created":34,"created_by":13,"id":35,"name":36,"updated":37,"updated_by":13},"2026-03-04 08:48:16.807Z","a5bvi0h0c8nu1ep","Chat moderation WebSocket","2026-04-10 16:13:44.074Z",{"collectionId":17,"collectionName":18,"created":39,"created_by":13,"id":40,"name":41,"updated":42,"updated_by":13},"2026-03-04 08:48:17.444Z","fz8kzj8k6swcpww","WebSocket chat security","2026-04-10 16:13:44.270Z",{"code":44,"collectionId":45,"collectionName":46,"created":47,"flag":48,"id":49,"is_default":50,"label":51,"updated":52},"en","pbc_1989393366","locales","2026-01-22 11:00:02.726Z","twemoji:flag-united-states","qv9c1llfov2d88z",false,"English","2026-04-10 15:42:46.825Z",{"category":54,"collectionId":55,"collectionName":56,"expand":57,"id":71,"views":72},"wqxt7ag2gn7xcmk","pbc_2105096300","school_blogs",{"category":58},{"blogIds":59,"collectionId":60,"collectionName":61,"created":62,"created_by":13,"id":54,"image":63,"image_alt":13,"image_path":64,"label":65,"name":66,"priority":67,"publish_at":68,"scheduled_at":13,"status":69,"updated":70,"updated_by":13},[],"sclcatblg987654321","school_category_blogs","2026-03-04 08:33:53.210Z","59ty92ns80w_15oc1implw.png","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclcatblg987654321\u002Fwqxt7ag2gn7xcmk\u002F59ty92ns80w_15oc1implw.png",{"en":66,"th":66},"Golang The Series",1,"2026-03-16 04:39:38.440Z","published","2026-04-25 02:32:15.470Z","d6zazypgm15q020",209,"uymtos7qordq74d",[20,25,30,35,40],"2025-07-09 03:16:46.930Z","Learn how to implement Message Filtering in WebSocket Chat to filter inappropriate messages and control chat content in real-time!","message-filtering-websocket-chat","2026-04-22 07:10:09.825Z",{"en":77}]