How to Export iMessage Chat History

How to export your iMessage chat history to a text file which can be uploaded and analyzed with Ai.