Feature Announcement: Exporting Channels

Matheus C.
Matheus C.
Published November 23, 2020

A chat app generates a lot of data based on user interactions. In some cases, such as when you need to provide chat transcripts of a livestream event to the event organizer, it's essential to have easy access to that data in a flexible format. You can then transform the data into your preferred format for analysis by your organization or a third party.

While it's possible to use Stream Chat's standard client methods for exporting data from your chat channels, it may not always be the best option for large sets of data due to the constraints of pagination, data size, and possible rate limits.

To help you deal with this scenario, we implemented a convenient way for exporting channels that gives you all the data from one or multiple channels in the JSON format. Optionally, you can specify a timeframe for the data you want.

For now, exporting channels is only possible with the Stream Chat JS client.

Channel Export

To request the data from a channel, you should call the exportChannel method. The parameters messages_since and messages_until are optional. If those are not included, the export will contain all data since the creation of the channel.

const response = await serverClient.exportChannel({
    type: "livestream",
    id: "white-room", 
    messages_since: "2020-11-10T09:30:00.000Z",
    messages_until: "2020-11-10T11:30:00.000Z",
});

const taskID = response.task_id;                    

That method will not return the data itself, but an identifier (task_id), which you can use to check on the export's status.

Export Status

After you requested the channel export, you can periodically check the export status using the getExportChannelStatus method to verify that it's complete.

const response = await serverClient.getExportChannelStatus(taskId);

console.log(response.status);       // the status for this task
console.log(response.result);       // the result object, only present if the task is completed
console.log(response.result.url);   // the link to the JSON export
console.log(response.error);        // if not null the description of the task error

Once the task is complete and there's no error, you can find the entire exported data by accessing the URL in the returned object.

Multiple Channels

It's also possible to export the history from multiple channels at once. The method is the same, but instead of a single object, you provide an array of objects containing the channel type and id. You can specify up to 25 channels. You can also specify messages_since and messages_until for each of them.

await serverClient.exportChannel([
    {type: "livestream", id: "blue-room"},
    {type: "livestream", id: "red-room"},
    {type: "livestream", id: "purple-room"},
]);

We're happy to bring yet another feature to help you understand your chat users better. For more information about this new feature, see the documentation on exporting channels. If you need help or have specific feedback about this feature, please leave a comment on the documentation page.

decorative lines
Integrating Video with your App?
We've built a Video and Audio solution just for you. Check out our APIs and SDKs.
Learn more ->