Skip to content
Advertisement

How create a spam filter in express.js or how to filter objects based on the word in the key values?

I want create simple spam filter. I dont have an inbox yet but I was thinking when the emails are recived I could make a GET request and filter the object based on the words mentioned in the message. If the posted object is

[{“id”:”1″ “email”:”xyz@gmail.com”, “cc”: “abc@gmail.com”,
“message”: “You have a chance to win a lottery and be a millionaire” },

{“id”:”1″ “email”:”qwet@gmail.com”, “cc”: “ghj@gmail.com”,
“message”: “hello how are you doing” } ]

I want to filter the object with id===1 that contains a combination of words “lottery”,”win”,”millionaire” in the message

I have come across Naive Bayes spam filtering algorithm but I don’t know how to integrate it with Express.

Any help is appreciated.

Advertisement

Answer

you can do this way by using filter()

posted_object.filter(
  (item) => item.id != 1 || !item.message.includes("lottery") || !item.message.includes("win") || !item.message.includes("millionaire")
);
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement