That's what I'm wondering. I know for calls this kind of thing was implemented as part of CallKit, but I'm not quite sure if that includes anything for messaging, and in particular iMessage which is controlled by Apple directly essentially.
Right. Check out the app (RoboKiller). Perhaps you can determine how they do it. I’m afraid their explanation is vague.