Export Chat of a Session
You can programmatically retrieve all chat messages of a Dyte session in the following ways:
- Using Chat Replay API
- Setting up webhook for the meeting.chatSynced event
This guide walks you through the steps involved in exporting chat dump of a session using Chat Replay API.
If you wish to use webhooks, see Set Up Webhooks and meeting.chatSynced.
Once Chat Replay API is enabled, do the following:
- Get the
chat_download_url
using Chat Replay API. - 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"
}
}
- The
chat_download_url
is a URL that allows you to download the entire chat dump of a session in CSV format from AWS S3. chat_download_url_expiry
indicates the expiry timestamp of thechat_download_url
. If thechat_download_url
gets expired, simply call this endpoint again to obtain 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:
- Make a GET request to the
chat_download_url
. - Convert response to blob.
- Create an invisible
<a>
HTML element with download attribute and add the above blob to it'shref
. - Programmatically 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:
- Create a writable stream for a local file.
- Make a GET request to
chat_download_url
. - 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 includes the following column headings:
id
: Unique chat message IDparticipantId
: ID of the participant who sent the messagesessionId
: The session ID from which the chat message was sentmeetingId
: The ID of the meeting to which this session belongsdisplayName
: Display name of the participant who sent this messagepinned
: A boolean that indicates if the current message was pinned or notisEdited
: A boolean that indicates if the current message was edited or notpayloadType
: An ENUM that indicates the type of payload sent in the chat message. It can be one of TEXT_MESSAGE, IMAGE_MESSAGE, FILE_MESSAGEpayload
: The actual payload sent in the chat messagecreatedAt
: Timestamp when this chat message was sent
For more information on downloading the file, refer to How to Fetch Chat History of a Dyte Session blog.