Skip to main content

Export Chat Dump of a Session

You can programmatically retrieve all chat messages of a Dyte session using Chat Replay API.

Note

Chat Replay API is not enabled by default for your organization. Contact Us to enable the Chat Replay API for your organziation.

Once Chat Replay API is enabled, do the following:

  1. Get the chat_download_url using Chat Replay API.
  2. Download the chat dump CSV file.

Get chat_download_url

To get the chat_download_url, make a HTTP GET request to Chat Replay API. The API returns the following:

{
"success": true,
"data": {
"chat_download_url": "string",
"chat_download_url_expiry": "string"
}
}
  • chat_download_url is the AWS S3 signed URL to download the whole chat dump of a session in a CSV format.
  • chat_download_url_expiry timestamp indicates when the chat_download_url will expire. If a chat_download_url is expired, just call this endpoint again to generate a new download URL.

Download the chat dump file

You can download the chat dump file in CSV format by making HTTP GET request to chat_download_url that you obtained in the previous step.

The process of downloading any file from a HTTP URL in JavaScript differs slightly based on whether you are doing it on client side or server side.

Download on the client

To download at client side, do the following:

  1. Make a GET request to the chat_download_url.
  2. Convert response to blob.
  3. Create an invisible <a> HTML element with download attribute and add the above blob to it's href.
  4. Programatically click on the <a> element so that the browser automatically starts downloading and then remove the <a> element.

Download on the server

We use Node.js streams to download files on the server, so the steps are as follows:

  1. Create a writable stream for a local file.
  2. Make a GET request to chat_download_url.
  3. Get a readable stream using res.body and pipe to the writable stream created in the first step.

Example: CSV chat dump File

This CSV file contains all the chat messages along with the participant's name and some other metadata. It contains the following column headers:

  • id: This is the chat message ID unique to each chat message.
  • participantId: This is the ID of the participant that sent this message.
  • sessionId: The ID of the session in which this chat message was sent. This will be the same as what you sent as URL param in the above endpoint.
  • meetingId: The id of the meeting to which this session belongs to.
  • displayName: Display name of the participant who sent this message.
  • pinned: A boolean that indicates if the current message was pinned or not.
  • isEdited: A boolean that indicates if the current message was edited or not.
  • payloadType: An ENUM that indicates the type of payload sent in the chat message. It can be one of TEXT_MESSAGE, IMAGE_MESSAGE, FILE_MESSAGE.
  • payload: The actual payload sent in this chat message.
  • createdAt: Timestamp when this chat message was sent

Sample Chat Dump File

For more information on downloading the file, refer to How to Fetch Chat History of a Dyte Session blog.