Similar to the call exceptions, we can specify whether SMS/MMS messages or messages via messaging apps, such as WhatsApp, should be allowed in Do Not Disturb mode.

We can also choose to allow all contacts or contact favourites.

The messages from allowed contacts will then be put through with sound and vibration.

Android 10 | OxygenOS 10.0
Step 1:  Open the  Settings
Step 2:  Tap on  Sounds & vibration
Step 3:  Tap on  Do Not Disturb
Step 4:  Tap on  SMS, MMS, and messaging apps
Step 5:  Tap on  Allow messages
Step 6:  Choose  From anyone ,  From contacts only ,  From starred contacts only  or  Don´t allow any messages
  1. Open the Settings
  2. Tap on Sounds & vibration
  3. Tap on Do Not Disturb
  4. Tap on SMS, MMS, and messaging apps
  5. Tap on Allow messages
  6. Choose From anyoneFrom contacts only, From starred contacts only or Don´t allow any messages

OnePlus Instructions