Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

push notification to topic throws #584

Open
boscoseries opened this issue Jul 13, 2020 · 4 comments
Open

push notification to topic throws #584

boscoseries opened this issue Jul 13, 2020 · 4 comments
Labels

Comments

@boscoseries
Copy link

boscoseries commented Jul 13, 2020

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
Copy link

pydlv commented Oct 3, 2020

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

@boscoseries
Copy link
Author

I did that. Did yours get solved with it?

@pydlv
Copy link

pydlv commented Oct 3, 2020

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

@boscoseries
Copy link
Author

boscoseries commented Oct 3, 2020

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

@azmeuk azmeuk added the gcm/fcm label Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants