How to send FCM message with only data payload via PyFCM?

4.1k Views Asked by At

I'm trying to send data-only FCM message to topic subscribers. But it not works nether when app in background or closed.

My android app have following code:

FirebaseMessaging.getInstance().subscribeToTopic("topicname");

My FCM-sender code

from pyfcm import FCMNotification

API_KEY = "AAAA....akZKg"

push_service = FCMNotification(api_key=API_KEY)

data = {
        "title":"mytitle",
        "body":"mybody",
        "url":"myurl"
        }

print(push_service.notify_topic_subscribers(topic_name="topicname", data_message=data))

outputs

{'canonical_ids': 0, 'results': [], 'failure': 0, 'success': 1, 'multicast_id': None}

But notification not appear. Need to show message to all topic subscribers that are not have running-right-now-app (have background or closed state)

1

There are 1 best solutions below

0
On

Hi Please upgrade to the latest version of pyfcm.After going through the source code i find that pyfcm always added a 'notification' dict in payload,but now they introduce a option "remove_notification" option in its source code which prevent the addition to payload. So as pyfcm does not provide any method for data only "notify_topic_subscribers" we have to override the fcm.py or fork the project and change. In fcm.py method add "remove_notification" to "notify_topic_subscribers" method and make it true in "parse_payload" call in that function.Thats it.