Semi-related: Does anybody know of a way to export iMessages from your iPhone?
From there, you just need to export the data you want from the messages db. The schema is kind of amazing, but not in a good way.
You don't need to buy a tool - you can write a python/ruby/whatever script.