jazzband / django-push-notifications

Send push notifications to mobile devices through GCM or APNS in Django.
MIT License
2.24k stars 609 forks source link

push notification to topic throws #584

Open boscoseries opened 4 years ago

boscoseries commented 4 years ago

from the documentation here https://github.com/jazzband/django-push-notifications

from push_notifications.gcm import send_message

# First param is "None" because no Registration_id is needed, the message will be sent to all devices subscribed to the topic.
send_message(None, {"body": "Hello members of my_topic!"}, to="/topics/<my_topic>_here")

when I do as stated above, I get this error

send_message(None, {"body": "Hello members of my_topic!"},
TypeError: send_message() missing 1 required positional argument: 'cloud_type'

I look up the send_message function in site-packages, it is defined like this def send_message(registration_ids, data, cloud_type, application_id=None, **kwargs)

then I modify my arguments to send_message to contain my cloud_type and application_id thus:

    send_message(None, {"body": "Hello members of my_topic!"}, cloud_type='FCM',
                 to="/topics/<my_topic_here>", application_id="my application id")

I then get this error

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/celery/app/trace.py", line 385, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/celery/app/trace.py", line 650, in __protected_call__
    return self.run(*args, **kwargs)
  File "/usr/src/app/competition/tasks.py", line 10, in pushnotification_to_topic
    send_message(None, {"body": "Hello members of my_topic!"}, cloud_type='FCM',
  File "/usr/local/lib/python3.8/site-packages/push_notifications/gcm.py", line 209, in send_message
    return _cm_send_request(None, data, cloud_type=cloud_type, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/push_notifications/gcm.py", line 159, in _cm_send_request
    response = json.loads(_fcm_send(
  File "/usr/local/lib/python3.8/site-packages/push_notifications/gcm.py", line 60, in _fcm_send
    key = get_manager().get_fcm_api_key(application_id)
  File "/usr/local/lib/python3.8/site-packages/push_notifications/conf/app.py", line 312, in get_fcm_api_key
    return self._get_application_settings(application_id, "FCM", "API_KEY")
  File "/usr/local/lib/python3.8/site-packages/push_notifications/conf/app.py", line 274, in _get_application_settings
    raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: push_notifications.conf.AppConfig requires the application_id be specified at all times.

here is my settings:

PUSH_NOTIFICATIONS_SETTINGS = {
    "CONFIG": "push_notifications.conf.AppConfig",
    "APPLICATIONS": {
        "<my application_id>": {
            "PLATFORM": "FCM",
            "API_KEY": <my api key>,
        },
    }
}
pydlv commented 3 years ago

I encountered this issue. You have to fill out the application_id column in the push_notifications_gcm table in your database.

boscoseries commented 3 years ago

I did that. Did yours get solved with it?

pydlv commented 3 years ago

Yes, it solved it for me. But I am sending only to a single user and not an entire topic.

boscoseries commented 3 years ago

Yes, it solved it for me. But I am sending only to a single user and not an entire topic.

I can send to a single and multiple devices via the device.send_message method and it works. It is only when I try to send to users subscribed to my topics (see the directive in the screenshot) that I get that error.

Screenshot 2020-10-03 at 8 19 49 PM