Bizarrely, the only method of automatically retrieving content from messages in the history of iMessage (as far as I know) is through Siri Shortcuts automations.
Using the Received Message From:
trigger, you have a few different types of content that are passed in the form of Shortcut Input
(note the third screenshot above.)
I just tested it and it still works! Though there’s no way for me to share the configuration directly, unfortunately.