Notifications

This guide will help you retrieve Account related notifications.

When an Account interacts with you or your content, the activity is recorded and a notification detailing the interaction is stored in the Lens API.

Notification types

There are various types of notifications, each with a slightly different structure, requiring individual handling. The available notification types include:

  • AccountActionExecutedNotification - when an account action is executed on your account

  • PostActionExecutedNotification - when a post action is executed on your post

  • GroupMembershipRequestApprovedNotification - when your group membership request is approved

  • GroupMembershipRequestRejectedNotification - when your group membership request is rejected

  • ReactionNotification - when someone adds a reaction to your post

  • CommentNotification - when someone comments on your post

  • RepostNotification - when someone reposts your post

  • QuoteNotification - when someone quotes your post

  • FollowNotification - when someone follows you

  • MentionNotification - when someone mentions you in a post

  • TokenDistributedNotification - when tokens are distributed to your account

At any given time new notification types may be added to the Lens API. Make sure you handle gracefully unknown notification types to avoid breaking your app.

Notifications Query

You MUST be authenticated as Account Owner or Account Manager to make this request.

Use the useNotifications hook to fetch notifications.

const { data, loading, error } = useNotifications(request);

Example of how to use the useNotifications hook:

Example
import { useNotifications, evmAddress } from "@lens-protocol/react";
// …
const { data, loading, error } = useNotifications({  filter: {    timeBasedAggregation: true,    notificationTypes: [NotificationType.Commented, NotificationType.Followed],    apps: [evmAddress("0x1234…"), evmAddress("0x5678…")]  }});
if (loading) {  return <p>Loading…</p>;}
if (error) {  return <p>{error.message}</p>;}
// data: {items: Array<Notification>, pageInfo: PageInfo}

Continue with the Pagination guide for more information on how to handle paginated results.