xtrinch / fcm-django

FCM Django: Send push notifications via django to websites, iOS & android mobile devices through FCM (Firebase Cloud Messaging)
http://fcm-django.readthedocs.io/
MIT License
774 stars 195 forks source link

`InvalidArgumentError` should not cause deactivation of token #223

Open daadu opened 1 year ago

daadu commented 1 year ago

Potential causes include invalid registration, invalid package name, message too big, invalid data key, invalid TTL, or other invalid parameters.

Invalid registration: Check the format of the registration token you pass to the server. Make sure it matches the registration token the client app receives from registering with Firebase Notifications. Do not truncate or add additional characters.

Invalid package name: Make sure the message was addressed to a registration token whose package name matches the value passed in the request.

Message too big: Check that the total size of the payload data included in a message does not exceed FCM limits: 4096 bytes for most messages, or 2048 bytes in the case of messages to topics. This includes both the keys and the values. Invalid data key: Check that the payload data does not contain a key (such as from, or gcm, or any value prefixed by google) that is used internally by FCM. Note that some words (such as collapse_key) are also used by FCM but are allowed in the payload, in which case the payload value will be overridden by the FCM value.

Invalid TTL: Check that the value used in ttl is an integer representing a duration in seconds between 0 and 2,419,200 (4 weeks). Invalid parameters: Check that the provided parameters have the right name and type.

^^ from firebase docs

I think this should NOT cause deletion of token. In my case I had a bug in sending message - some arg (TTL) was not proper. This caused tokens to be removed permanently.

Following could be the solution

  1. EITHER remove this from fcm_error_list [my preferred solution]
  2. OR add a config DEACTIVE_ON_INVALID_ARGUMENT_ERROR (or something), to enable/disbale this behaviour
daadu commented 1 year ago

@xtrinch Let me now, what do you think about it - I will file PR for it.

xtrinch commented 1 year ago

I think perhaps you're right that this does not qualify for token deactivation

daadu commented 1 year ago

I also noticed that the token is deleted on the Firebase server as well. Not sure whether the module is pruning it (calling some delete APIs on Firebase) or it happens because of the InvalidArgumentError

daadu commented 1 year ago

I also noticed that the token is deleted on the Firebase server as well.

Noticed that once deleted from Django-server, when I ask for fcmToken on client side I get a new one (not the deleted one).

daadu commented 1 year ago

If firebase also deletes them, then I think it is the correct behavior.

daadu commented 1 year ago

I tested and noticed this with iOS only, not sure it is the same for other platforms.

xtrinch commented 1 year ago

This module doesn't delete any tokens. If firebase deletes them, then it's OK if this module does too

daadu commented 1 year ago

Need to confirm this behaviour, I am using flutter clients - which are wrapper around native libraries. Also not sure if this happens with Android tokens as well.

Keeping this issue open, until this is verified.