When I receive a message on Facebook I get a push notification on a lock screen (iOS). Then I read this message on desktop. Right after that this push notification disappear
One simple way to achieve this effect is to send a normal push notification to your device with a payload that only contains a badge count of 0.
In Facebook's example, they clearly have enough server power to simply detect when you've read the message on your desktop and send a push to your devices to makes sure that notification is no longer there.
I'm not saying this is how FB does it but it's a simpler path that may or may not fit your needs. Keep in mind that background tasking consumes your user's battery significantly and should be avoided when possible.