how to save chat correspondence in a separate file? for example the variable message_key = "" is where the message text is entered. who knows how best to do it or may have already done it.
I'm not sure what you are doing with "online" chat...but if you have a variable with a string already, you can literally save that string to a file using the file functions in the manual. Yes, you should read the manual.
If you want better help than that, you are going to need to supply more information about what you are actually doing and what you have tried already(if anything).
If you have already implemented an online chat, that usually means you have an array or list that new messages get pushed into. JSON makes quick work of saving that.