Liveblocks 1.9: Comments improvements that enable AI agents, chat moderation, thread filtering, and more
Today we’re introducing a way to programmatically create and modify comments, enabling AI agents, chat moderation, and more. We’re also adding a new option to filter threads by metadata.
With Liveblocks 1.9, we’re updating Comments, introducing a way to programmatically create and modify threads, comments, and reactions. This enables a number of different use cases such as AI agents, moderation, and two-way synchronization with messaging apps. We’re also adding a way to filter threads by metadata.
Upgrade now
Start using the new features now by updating each Liveblocks package in your
project to the @latest
version.
Note that there’s a small breaking change—all dates returned from Comments
are now Date
objects instead of strings
.
Learn more in our upgrade guide.
Modifying comments programmatically
It’s now possible to create and modify comments, threads, and reactions,
programmatically using the typed REST API functions in @liveblocks/node
. There
are seven new functions—here’s a few examples.
If you’re not using JavaScript, you can also call our REST API directly to modify comments.
You can find more information in the API reference for each new function.
createThread
editThreadMetadata
createComment
editComment
deleteComment
addCommentReaction
removeCommentReaction
AI agents, moderation, and more
The ability to programmatically modify comments enables a host of new possibilities, such as AI agents, comment moderation, and two-way chat synchronization.
AI agents
Using webhooks, you can now create an AI agent that responds to comments, such as in our example using GPT4.
This example uses the
CommentCreated
webhook event in
combination with
liveblocks.createComment
.
Comment moderation
If we take programmatically modifying comments to the next level, we can implement various types of comment moderation, such as banned word filtering, or creating moderator users.
When using Comments React hooks, such as
useDeleteComment
, you
can only delete your own comments. However, because the new APIs runs server
side, requiring your secret key, you can use them to delete any user’s
comments. Here’s an example of a server action that does exactly this.
This code snippet is using
liveblocks.deleteComment
.
Two-way messaging synchronization
Another use for our new APIs is bi-directional synchronization, the ability to send and receive updates between Comments and another service. This means it’s now possible to mirror a chat application, and have messages automatically synchronize.
Here’s an example of an endpoint that receives a new thread from a messaging application, then copies it to Comments—the first direction necessary in two-way synchronization.
Then in the other direction, you can listen for threads posted to Comments with webhook events, and copy the thread into your messaging app.
This uses the CommentCreated
webhook event in combination with
liveblocks.createComment
.
Thread filtering
In Liveblocks 1.9
useThreads
now has a query
option, allowing you to filter threads by metadata.
When multiple metadata fields are passed, the logical AND
operator is used,
returning a list of threads with every property.
Upgrade guide
Remember there’s a change to the way dates are handled in this update, so make sure to check the upgrade guide to learn more.
Get started with Comments
If you’d like to add Comments to your application, make sure to check out our guides and examples.
Contributors
Huge thanks to everyone who contributed and specifically to Florent Lefebvre, Nimesh Nayaju, Olivier Foucherot, Guillaume Salles, for all their work on this update. Keep checking out the changelog for the full release notes–see you next time!