The problem is this also blocks SMS from those outside your contacts. It will be an issue with 2FA.
I created a "Do not disturb" profile that only blocks voice calls for non-contacts. SMS still comes through. My ringtone is a silent file, but that's just my preference.
In the DND profile, I only allowed messaging apps to show notifications. I don't care about the rest.