Citing the article(s) these phrases appear and are applicable.
Block a phone number, contact, or email.
There are a few ways that you can block phone numbers, contacts, and emails.
And I've used these to help resolve and block several anonymous
iMessages from (& unknown callers) without having to save into
my Contacts first. The entire reason why, is that for me, this works.
• Block phone numbers, contacts, and emails on your iPhone, iPad, or iPod touch - Apple Support
https://support.apple.com/en-us/HT201229
In part these also helped remove 'unwanted unknown' messages.
Manage your blocked phone numbers, contacts, and emails:
Filter messages from unknown senders
"You can filter messages from people who aren't saved in your Contacts."
Sometimes I haven't time from my real world to answer again.
As a volunteer from 2003 in these discussions; little time away
from life and actual mostly unpaid work in either case, helps me.
[The proof to me, is these worked. One of the only paths with
an older macOS and newest iOS in iPhone; to make this work.]
Previously I was able to use an antique iPad Mini w/ iOS9.3.5
(wi-fi only) and the Messages app there, to block unknowns.
The Mac hasn't been fully satisfactory for me, with any these.
Perhaps due to using an older macOS; marginal but adequate.
The iPad still does this task; & takes me more steps to accomplish.
Instructions for macOS, on the other hand, tell me that I could be
be able to do these. Maybe articles apply to newer than Catalina.
My newest installed and running macOS in my daily use Mac, is
an older High Sierra. This machine has dual-drives and three OS.
(2 newer macOS installers are on second internal drive, 10.15/10.14.)
Purposefully and quite useful, was the ability to direct unwanted
and totally unknown to me (some suspected as spam) Messages
from Unknown Senders; to block & not enter those first in Contacts.
Often enough are times like these ~ are reason to need to block ASC
threads, where my experience wasn't good enough to match inquiry.
In this case, I've eaten my own stew. And so on.. I should feel insulted.
Not sure what level of success you've attained or tried first.
Sorry to find my efforts, are unsatisfactory; in your situation.