1

I'm using FCM for my push messages. Its great, however I've a client that needs to be able to remove a push message once its sent - (in case of mistakes / typos etc).

I know you can get the message id from when the Topic is queued to send messages, just wondering if there is a way to then use that ID to expire those messages remotely. i.e. to delete the message.

AL.
  • 36,815
  • 10
  • 142
  • 281
kierandes
  • 161
  • 3
  • 16

2 Answers2

2

There is currently no way to delete/remove a message from the server side/console. The message_id is just an identifier that the message was sent successfully to the FCM server.

What is usually used for this scenario is the tag parameter (see my answer here) where an existing notification with the same tag gets replaced with the newer one.

AL.
  • 36,815
  • 10
  • 142
  • 281
  • 1
    You're welcome. If you think this pretty much answer your question, feel free to tick it as correct so that your post would be properly tagged. Cheers! – AL. Feb 22 '18 at 08:03
  • I'll try it out this afternoon :). I think that what you suggest works. What I'll do with that then is that if an item is deleted. I can replace the notification with a new one that expires after a second .e.g (Deleted) . Then in other cases would just update the notification. Oh and of course I'll mark it solved! – kierandes Feb 22 '18 at 10:27
2

There are scenarios where you might want a replacing notification to notify the user rather than silently update. Chat applications are a good example. In this case you should set tag and renotify to true.

write this code on your sw.js

    const title = 'Notification 2 of 2';
    const options = {
      tag: 'renotify',
      renotify: true
    };
    registration.showNotification(title, options);

You can test demo on here by clicking in renotify button

Tushar Acharekar
  • 880
  • 7
  • 21
  • Cool thank you. Thats good to know. Might be times when theres an important update or "Breaking News! Update" style scenario. – kierandes Feb 22 '18 at 10:29