Using Liveblocks webhooks, it’s possible to trigger your API endpoints when certain events occur, such as a thread being created, or a comment being modified. One use for these events is sending new comment notifications, for example via email or Slack.
Using Liveblocks webhooks you can listen to a range of events such as comments being deleted, or reactions being added. On the dashboard you can create a webhook for a project, and select which events you’d like to listen to.
The endpoint URL will be sent a request with relevant data when the event occurs. Here’s an example of an event object that’s sent when a thread is created.
In your endpoint, you can use this event
object with functions such as
liveblocks.getThread
and
stringifyCommentBody
,
which will return the thread that’s just been created, and the text from the
first comment.
You could then call liveblocks.getParticipants
to find a list of user IDs
mentioned in the thread, and send an email to each user.
Here’s an example with every step linked together, along with the code necessary to verify a webhook request is valid.
Learn more about building this in our how to send email notifications guide.
There are more webhook events than just the ThreadCreatedEvent
event used
above—a number related to Comments are available to use.
CommentCreatedEvent
CommentEditedEvent
CommentDeletedEvent
CommentReactionAddedEvent
CommentReactionRemovedEvent
ThreadCreatedEvent
ThreadMetadataUpdatedEvent
There are also more events, for example you can trigger events when users enter or leave rooms. We recommend reading our guide on testing webhooks locally to get started.
Here’s every Comments-related
@liveblocks/node
function. Each also
has a corresponding REST API, you can find more info by following the links.