Liveblocks 1.8: Typed REST APIs and easy Comments notifications
Today we’re introducing new typed REST API methods, making integrating Liveblocks into your back end easier than ever. We’re also adding functions to help you transform comments, and create email notifications more easily.
With Liveblocks 1.8, we’re introducing an improved way to consume our REST APIs with types, making it quicker to integrate Liveblocks into the back end of your application. We’re also adding a way to transform comments into HTML, Markdown, and more, meaning sending formatted email notifications is now simpler.
Upgrade now
Start using the new features now by updating each Liveblocks package in your
project to the @latest
version.
If you use any other Liveblocks packages, make sure to include those too.
Typed REST APIs
It’s now possible to access our REST APIs using the
@liveblocks/node
package. Previously,
the only way to access our REST APIs in Node.js was via a fetch
call.
From now, you can set up a Liveblocks
client, call a corresponding method, and
get type hints on the returned value.
Every existing REST API is supported, and we’ll continue to add them in the future. Here’s an example of some more methods.
Find all the methods in the API reference under
@liveblocks/node
.
Transforming comments
Using Liveblocks 1.8, you can transform a comment’s text into different formats, for example HTML, Markdown, or a plain string of text. Here’s an example of a comment converted into two different formats.
To enable this, we’ve added a new helper function called
stringifyCommentBody
.
Here’s one way it could be used, alongside
Liveblocks.getComment
.
You can also customize the output format, either completely, or on an
element-by-element basis. Make sure to read
stringifyCommentBody
to learn more.
Get mentioned IDs
As a bonus, we’ve also added a utility that makes it easy to find each user
mentioned in a comment’s body. It’s called
getMentionedIdsFromCommentBody
, and
here’s how it works.
Sending Comments email notifications
Using the new REST API and comment transformation functions, it’s easier than
ever to send formatted email notifications. You can trigger events when comments
are created using our webhooks, and in particular the
CommentCreatedEvent
.
Here’s an example of a Next.js route handler that listens for new comments, then sends a formatted HTML email with Resend.
To learn exactly how this works, we’ve written a full guide on sending email notifications when comments are created.
Contributors
Huge thanks to everyone who contributed and specifically to Nimesh Nayaju and Marc Bouchenoire for their work on the REST API methods and the Comments functions respectively. Keep checking out the changelog for the full release notes–see you next time!