Files are stored in ContentDocument entity.
Use this soql to find the ContentDocumentId.
SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = ‘<MessagingSessionId>’
Example:
1. Run the below SOQL.
SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = ‘0Mw3h00000146TkCAI’
0Mw3h00000146TkCAI is the Messaging Session Id.
2. Use the ContentDocumentId and open the file.