How can I download my chat history from PlayStation messages to a text file?
As far as I know there is no export function for your chats, but you can access it via web browser just like any other text chat, including chat history, creating new chats and of course you can reply to existing conversations.
Just head over to playstation.com and log in with your PSN account. On the top right you'll find the chat menu.