appleboy / gorush

A push notification server written in Go (Golang).
MIT License
7.84k stars 829 forks source link

Link token to user ids #760

Open Chralu opened 6 months ago

Chralu commented 6 months ago

Hi @appleboy ,

here is a thought I would like to discuss...

In my experience, a recurring concern about push notifications is sending notifications to a particular user of your service. To achieve that, you have to maintain the matching between user id and its push notification tokens.

So, to achieve that, I would need :

It would be really convenient to add that responsability to GoRush.

New API proposal

POST /api/session

creates a mapping between user id, and its tokens

{
   "user_id": "xxxxxx",
   "token": {
       "platform": 1,
       "token": "sdfsfdsf",
   } 
}

POST /api/push/session

sends notification to users

{
  "notifications": [
    {
      "user_ids": ["user_id_1", "user_id_2"],
      "message": "Hello World Users !",
      "title": "Gorush with HMS"
    },
  ]
}

Cleaning the mapping

In case of invalid tokens (expired, invalid...) we want to remove it from the session mapping.

Fortunately, when sending notifications with services like Firebase Cloud Messaging, it returns the list of invalid tokens used.

What do you think ?

Chralu commented 6 months ago

might be related to #756