Using Liveblocks webhooks, it’s possible to trigger your API endpoints when certain events occur, such as users joining or leaving rooms. One of these events was created specifically for sending notifications from your back end, for example via email or Slack.
Email notifications are built around the concept of inbox notifications, which are different from “normal” notifications in the sense that they can group multiple activities together and evolve over time. This makes more sense when sending email notifications because it helps to avoid flooding your users with too many emails.
Using Liveblocks webhooks you can listen to a range of events such as user joining rooms, or threads being created. On your dashboard you can create a webhook for a project, and select which events you’d like to listen to.
The endpoint URL you pass will receive request with relevant data when the event
occurs. The webhook event built for creating these unread notification emails is
called "notification"
, and by default is sent up to every 30 minutes to each
user, though this can be customized in the webhooks dashboard. Here’s an example
of an event object that’s sent when a user receives a new (or updated) inbox
notification.
In your endpoint, you can use this event
object with
liveblocks.getInboxNotification
,
which will return the inbox notification for the event.
Once you have the inbox notification you can then send an email to the userId
containing information from the notification.
Here’s an example with every step linked together, along with the code necessary to verify a webhook request is valid.
When you receive a notification
webhook event, it's essential to verify if the
user has access to the room before sending an email. Liveblocks lacks the
necessary information to determine if a user has access to a room. For instance,
we create an inbox notification when a user is mentioned in a comment. In this
user's client context, we can determine if they have access to the notification
thanks to the token generated for that user. However, when we send a
notification
webhook event, we lack this information.
If you are using access tokens, this will always be true, Liveblocks will never have the information.
If you are using ID tokens, Liveblocks already possesses certain information about the permissions you have configured for each room, specifying which users and groups have access. However, what we currently lack is the relationship between a user and a group. At present, you need to verify user access before sending an email. We do, however, plan to include full permissions info in Liveblocks in our future updates. If you're interested in learning more about this feature, please feel free to reach out to us.
Here’s every Notifications-related
@liveblocks/node
function. Each also
has a corresponding REST API, you can find more info by following the links.
We use cookies to collect data to improve your experience on our site. Read our Privacy Policy to learn more.