Is it possible to get the notification id after notificationSend in server side by JS runtime?

nk.notificationSend(receiverId, subject, content, code, senderId, persistent);

current the function return void. but i can see the source code of this function:

so is there any way to get this id after send from the server side with js runtime? If not what the best way to get this id in server side?

Hello @mengxin,

Can you elaborate on what’s the use case that requires you to fetch the notification id?

I’m currently working on building a mailbox system based on notifications. Our aim is to include company data along with notifications on the server side.
For instance:

  1. We will introduce a new Mailbox type for notifications.
  2. When the server sends a mailbox-type notification to a player, the server will also create accompanying data such as:
    {
    notificationId: xxx,
    sendTime: xxx,
    isRead: false,
    isClaimed: false
    }
    This data will be sent to the player.
  3. The client will also synchronize this data to keep track of the mailbox.

Additionally, if we can’t retrieve the ID on the server side, we will need to delay the next RPC (Remote Procedure Call) from the server for updating the status. Currently, this isn’t an issue since all the fields have default values of empty or false. We can use these default values to generate the data on the client side and build it on the server during the next update RPC, such as when a player reads a notification. However, if there’s data that needs to be built based on server configuration, we may encounter difficulties, especially if there’s no way to link the notification ID with the data.

I’m currently working on building a mailbox system based on notifications. Our aim is to include company data along with notifications on the server side.
For instance:

  1. We will introduce a new Mailbox type for notifications.
  2. When the server sends a mailbox-type notification to a player, the server will also create accompanying data such as:
    {
    notificationId: xxx,
    sendTime: xxx,
    isRead: false,
    isClaimed: false
    }
    This data will be sent to the player.
  3. The client will also synchronize this data to keep track of the mailbox.

Additionally, if we can’t retrieve the ID on the server side, we will need to delay the next RPC (Remote Procedure Call) from the server for updating the status. Currently, this isn’t an issue since all the fields have default values of empty or false. We can use these default values to generate the data on the client side and build it on the server during the next update RPC, such as when a player reads a notification. However, if there’s data that needs to be built based on server configuration, we may encounter difficulties, especially if there’s no way to link the notification ID with the data.

The update should be driven by the client, which has the data and the notification ID, you can then use an RPC to do the lookup (as mentioned in Seem like there is no way to get the notification on server side - #2 by sesposito) and decorate as needed.

yeah, we are implementing like this way. but if the send API can return the notification object sent will be more helpful to work with server logic

@mengxin wouldn’t implementing mailbox be more vesable to be done as S2S.
Basically you could have mailbox services done outside of the nakama, and to the nakama it could communicate with S2S.
Nakama it self could post notification if player is online or if not. On this way i belive you can get best of both worlds.

yeah, this is what we did to achieve this feature, the only minor issue we have extra data to track the mail read/claim expiration status. after the server sends notification, as we cannot get the notification itself, so cannot create a corresponding entry for the notification when send, need client drive to maintain this data structure

Maybe implementation is off: but here is how we are doing:

  • We have specific service for sending emails to the players

  • This service communicates with DB and writes in db emails

  • Users fetches emails from storage, as it should

  • Notification is only sent that you got new mail, and when you tap on the button it will request new data from the server

  • Now marking that email has been read/claimed that is all done with rpc, and that can be possible because we are using storage system.

1 Like