Google attempts (or attempted at one point) to make this easy with Google Takeout: https://takeout.google.com/
Unfortunately it doesn't seem entirely reliable. Last time I tried it, some of my chat messages were missing.