@liveblocks/emails
provides a set of functions that simplifies sending styled
emails with Notifications and
webhooks. This library is only intended for use in
your Node.js back end.
This package exposes functions that enable easy creation of styled emails with React and HTML. Each method is designed to be used with our webhooks which means you must set them up first. Webhooks require an API endpoint in your application, and this is typically what they will look like.
We’ll only show the highlighted part below, as it’s assumed you’ve set this
already, and your file contains liveblocks
and event
.
These functions help you create emails to notify users of unread comments in threads. They fetch each relevant comment, filtering out any that have already been read, and help you style each comment’s body with either React or HTML.
The function also helps you distinguish between unread mentions and unread replies.
A thread has unread replies if a comment was created after the readAt
date
on the notification, and created before or at the same time as the notifiedAt
date. All unread replies are returned in an array.
A thread has an unread mention if it has unread replies, and one of the replies mentions the user. A single comment with the latest mention is returned.
Takes a
thread notification webhook event
and returns unread comment body(s) related to the notification, as React nodes.
It can return one of three formats, an unreadMention
type containing one
comment, an unreadReplies
type returning multiple comments, or null
if there
are no unread mentions/replies. You can also
resolve user & room data
and
customize the components.
It’s designed to be used in a webhook event, which requires a
Liveblocks
Node.js
client and a
WebhookHandler
. Check
for the correct webhook event using
isThreadNotificationEvent
before running the function, such as in this Next.js route handler.
Returns comment information, and a formatted React body, ready for use in emails. Returns null
if there are no unread mentions or replies. The result has two formats depending on whether this notification is for a single unread mention, or for multiple unread replies:
A Liveblocks
Node.js client.
An object passed from a webhook event, specifically the
ThreadNotificationEvent
.
Learn more about setting this up.
A number of options to customize the format of the comments, adding user info, room info, and styles.
A function that resolves user information in
Comments. Return an array of UserMeta["info"]
objects in the same order they arrived. Works similarly to the resolver on
the
client.
Learn more.
A function that resolves room information. Return a RoomInfo
object, as
matching your types. Works similarly to the resolver on the
client
but for one room. Learn
more.
Pass different React components to customize the elements in the comment
bodies. Five components can be passed to the object: Container
,
Paragraph
, Text
, Link
, Mention
. Learn
more.
The comment body container.
The paragraph block.
The text element.
The link element.
The mention element.
Similarly to on the client, you can resolve users and room info, making it easier to render your emails. For example, you can resolve a user’s ID into their name, and show their name in the email.
Each React component in the comment body can be replaced with a custom React
component, if you wish to apply different styles. Five components are available:
Container
, Paragraph
, Text
, Link
, Mention
.
Takes a
thread notification webhook event
and returns unread comment body(s) related to the notification, as an HTML-safe
string. It can return one of three formats, an unreadMention
type containing
one comment, an unreadReplies
type returning multiple comments, or null
if
there are no unread mentions/replies. You can also
resolve user & room data
and
customize the styles.
It’s designed to be used in a webhook event, which requires a
Liveblocks
Node.js
client, a
WebhookHandler
. Check
for the correct webhook event using
isThreadNotificationEvent
before running the function, such as in this Next.js route handler.
Returns comment information, and a formatted HTML body, ready for use in emails. Returns null
if there are no unread mentions or comments. The result has two formats depending on whether this notification is for a single unread mention, or for multiple unread replies:
A Liveblocks
Node.js client.
An object passed from a webhook event, specifically the
ThreadNotificationEvent
.
Learn more about setting this up.
A number of options to customize the format of the comments, adding user info, room info, and styles.
A function that resolves user information in
Comments. Return an array of UserMeta["info"]
objects in the same order they arrived. Works similarly to the resolver on
the
client.
Learn more.
A function that resolves room information. Return a RoomInfo
object, as
matching your types. Works similarly to the resolver on the
client
but for one room. Learn
more.
Pass CSS properties to style the different HTML elements in the comment
bodies. Five elements can be styled: container
, paragraph
, text
,
link
, mention
. Learn
more.
Inline styles to apply to the comment body container.
Inline styles to apply to the paragraph block.
Inline styles to apply to the text element.
Inline styles to apply to the link element.
Inline styles to apply to the mention element.
Similarly to on the client, you can resolve users and room info, making it easier to render your emails. For example, you can resolve a user’s ID into their name, and show their name in the email.
Each element in the comment body can be styled with custom CSS properties, if
you would like to change the appearance. Five elements are available:
container
, paragraph
, text
, link
, mention
.
We use cookies to collect data to improve your experience on our site. Read our Privacy Policy to learn more.