Instead of asking my clients to manually export the history to a text file for me. I am wondering if there is a legal, more convenient way, with my clients' consent, to get their WhatsApp messages history from their phones to me for analytics services.
As far as I understand, any whatsapp automation other than using the official API is forbidden. Of course, the official API will not give you such an opportunity, as all history is cleared when you switch to the Business API. However, I should note that the official BSP partner of Meta, Wati, has a tool that allows you to make backups of all correspondence. Perhaps this is what you need, as it is free and easy to install: https://www.wati.io/whatsapp-chat-backup/. I don't know if this is a legal way, I think users should accept the agreement that they do it at their own risk.
Of course, there are always unofficial API solutions, that will allow you to automate any WhatsApp functionality, but I think it won't suit you.