save messages to database