You could try using imessage-exporter. I haven't used it myself but have seen it being recommended before in this sub.
post
replies:
As I recall, if you have a MacBook, iMessage syncs your messages and stores them in a file named ~/Library/Application Support/MobileSync/Backup
That file or files (my notes don't say number or the names of files) is just a SQL database which can be queried with the sqlite client, or exported into a more friendly format.
This solution worked for me about 5 years ago; I don't know if Apple still allows this.
IIRC there's some EU regulation that is going to mandate iMessage to be compatible with Android, which means Apple may soon make iMessage more open, and more options should appear in a few years.
all 7 comments