Click on your Mac.
Choose Messages > Settings, then click General.
Do any of the following:
Notify me about messages from unknown contacts: Select if you want to be notified when you receive a message from someone who doesn’t have a contact card in the Contacts app at the bottom of the window.
Turn off all notifications from Messages: Turn off “Allow notifications.”