Nhảy đến nội dung chính

Social Notifications

Applications such as NEAR Social and the NEAR Dev Portal allow components to send notifications to their users.

Notifications are great to inform users in real time that something has happened, and can be easily incorporated into any web app.


Sending Notifications

Notifications are implemented as a particular case of indexed actions.

This means that to send a notification we just need to index the notify action for the indexer, with a key and a value.

  • The key tells which account to notify.
  • The value includes the notification type and the item being notified of.
Loading...

In this example, the account executing the code is notifying mob.near that they liked their social post created at the block height 102169725.


Notification Types

Since notifications are indexed actions, anyone can create their own kind of notification.

While there is no standard for notifications, we recommend using the following types:

  Social.set({
index: JSON.stringify({
notify: {
key: "mob.near",
value: {
type: "custom",
message: "A message in the notification",
widget: "The widget to open when clicking on the notification",
params: { parameters: "to pass to the widget", ... },
},
}
})
});

Note: currently, only dev.near.org implements custom notifications

caution

There is no standard for notifications, but you can contribute to create one in this public discussion.


Parsing Notifications

In order to get all notifications for an user, we make a call to the Social indexer.

Loading...
caution

Please notice that anyone can create a notification for the user, and thus some form of filtering might be needed.

tip

You can also check how the Notifications Page is implemented.

Was this page helpful?