Bob wants to automate!
How do I set up an app to open files with a custom extension from anywhere, process them, and then discard them?
I have a feeling this is a question that hackers ask. Consequently, Apple has gone to great lengths to make sure you can't do this!
But you have a legitimate business process, so what options are available to you? Break your big business problem into several smaller business problems. Try to automate each step. Then think of a strategy to weave those processes together.
Shortcuts
Have you explored iOS Shortcuts?
See-> Communication Shortcuts
Shortcuts provides a mechanism for running code when you receive a message from a particular person and the message contains particular phrases. Start here!
Using your example, a friend sends you a text file. Use Shortcuts to look for messages sent by your friend, and maybe the phrase "Daily Sales Receipts". You might be able to take action on that message and save any attachments to a "Receipts" folder. If necessary, rename the file with a sequence number, and timestamp.
Now the problem is out of the Messages application. Another Shortcut might execute anytime there's a file in the Receipts folder. This might kick off your custom Swift app to open and parse the file, storing data in a CoreData database, or following other business processes.
When that finishes, you might have another Shortcuts, or possibly Swift application to delete the file in the Receipts folder.
Once all these pieces work, you can consider how to merge them.