You can block text messages via Messages app. This works really well for blocking text messages on iPhone, like some unknown spammers, advertising companies and internet marketers bothering you with promotions and offers for products that are not at all related to your interest. These steps will block only those unknown callers that you choose to block.
1. Go to the Messages app.
2. Tap on the target message from the spammer.
3. Choose "Details" on the top right hand corner and tap on it.
4. There will be phone icon and a letter "i" icon across from the number. Tap on the "i" icon.
5. Scroll down to the bottom of the page and then tap on "Block Contact".
Note: Once you press on Block Contact, the phone number that you just blocked won't be able to make phone calls, send text messages, or Facetime you. How to Block Text Messages on iPhone