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

How should we send notifications to multiple tokens with the updated API? #338

Open
sgserg opened this issue Jun 20, 2024 · 16 comments
Open

Comments

@sgserg
Copy link
Contributor

sgserg commented Jun 20, 2024

Attempting to use async_notify_multiple_devices yields

Traceback (most recent call last):
   ...
   ...
  File "/usr/local/lib/python3.6/dist-packages/pyfcm/fcm.py", line 81, in async_notify_multiple_devices
    return self.send_async_request(payloads=payloads, timeout=timeout)
TypeError: send_async_request() got an unexpected keyword argument 'payloads'
@olucurious
Copy link
Owner

Please use v2.0.3

@sgserg
Copy link
Contributor Author

sgserg commented Jun 20, 2024

Thanks for the quick response!
I've just updated the package with pip install --upgrade pyfcm and it ended up installing 2.0.0.

I'm on Python 3.6.9.
Could that be the reason?

@sgserg
Copy link
Contributor Author

sgserg commented Jun 20, 2024

Tried pip-installing 2.0.3 from github, but it failed with google-auth being too old (2.22.0 being the latest for Python 3.6 according to this).

Sending notification to a single device works fine, so there is no problem with auth in itself.

Is there a way we could make it work with older google-auth?

@sgserg sgserg changed the title How should we send multiple notifications with the updated API? How should we send notifications to multiple tokens with the updated API? Jun 20, 2024
@sgserg
Copy link
Contributor Author

sgserg commented Jun 20, 2024 via email

@sgserg
Copy link
Contributor Author

sgserg commented Jun 20, 2024

Changing the requirement to 2.22.0 and installing aiohttp makes our tests pass on 2.0.3.

What might break due to this requirement change?

@olucurious
Copy link
Owner

Can you try the new version

@sgserg
Copy link
Contributor Author

sgserg commented Jun 25, 2024

Could you please update setup.py too? (reference 2.22.0 instead of 2.29.0)

@sgserg
Copy link
Contributor Author

sgserg commented Jun 25, 2024

Also, annotations import fails on 3.6.9:

  File "/usr/src/app/coral/PyFCM/pyfcm/__init__.py", line 14, in <module>
    from .fcm import FCMNotification
  File "/usr/src/app/coral/PyFCM/pyfcm/fcm.py", line 1, in <module>
    from .baseapi import BaseAPI
  File "/usr/src/app/coral/PyFCM/pyfcm/baseapi.py", line 1
    from __future__ import annotations
    ^
SyntaxError: future feature annotations is not defined

@sgserg
Copy link
Contributor Author

sgserg commented Jun 26, 2024

(also, aiohttp (3.8.6) dependency still needs to be manually installed)

@sgserg
Copy link
Contributor Author

sgserg commented Jun 26, 2024

one more thing: the following comma in pyfcm/baseapi.py seems to cause troubles for both iOS and Android:

 34         proxy_dict=None,
 35         env=None,
 36         json_encoder=None,
 37         adapter=None >>> , <<<<
 38     ):

@sathvik-grexit
Copy link

Can someone please help me with the structure of the payload that needs to be passed to async_notify_multiple_devices()
I have fcm_token, notification_title, notification_body, data_payload params that can be passed to the above function.

@sgserg
Copy link
Contributor Author

sgserg commented Jun 26, 2024

@sathvik-grexit it's apparently the same as for a single notify you just make an array of those.

@tronku
Copy link

tronku commented Jul 18, 2024

@sgserg can you please add an example in readme or here?
older -

pushService.notify_multiple_devices(
        registration_ids=tokens,
        data_message=data
    )

what should be the new way?

@dr0g0
Copy link

dr0g0 commented Jul 21, 2024

Attempting to use async_notify_multiple_devices yields

Traceback (most recent call last):
   ...
   ...
  File "/usr/local/lib/python3.6/dist-packages/pyfcm/fcm.py", line 81, in async_notify_multiple_devices
    return self.send_async_request(payloads=payloads, timeout=timeout)
TypeError: send_async_request() got an unexpected keyword argument 'payloads'

push_service = FCMNotification(service_account_file="", project_id="")

fcm_tokens = []
notification_title = "Notification Title"
notification_body = "Notification Body"
data_payload = {}

params_list =[{"fcm_token":fcm_token,"notification_title":notification_title,"notification_body":notification_body,"notification_image":'https://synak.pro/static/img/about-1.png',"data_payload":data_payload} for fcm_token in fcm_tokens]

result = push_service.async_notify_multiple_devices(params_list=params_list, timeout=5)

@criptocoko
Copy link

criptocoko commented Aug 1, 2024

params_list =[{"fcm_token":fcm_token,"notification_title":notification_title,"notification_body":notification_body,"notification_image":'https://synak.pro/static/img/about-1.png',"data_payload":data_payload} for fcm_token in fcm_tokens]

result = push_service.async_notify_multiple_devices(params_list=params_list, timeout=5)

Why are we repeating the same data for each key instead of just sending a list of registration_ids as we did in older versions? This approach seems redundant and might complicate the process. Could we simplify this by going back to the previous versions (sending the registration_ids)

Thanks!

@dhevendhiran-adt
Copy link

params_list =[{"fcm_token":fcm_token,"notification_title":notification_title,"notification_body":notification_body,"notification_image":'https://synak.pro/static/img/about-1.png',"data_payload":data_payload} for fcm_token in fcm_tokens]

result = push_service.async_notify_multiple_devices(params_list=params_list, timeout=5)

Why are we repeating the same data for each key instead of just sending a list of registration_ids as we did in older versions? This approach seems redundant and might complicate the process. Could we simplify this by going back to the previous versions (sending the registration_ids)

Thanks!

Actually this is solving the another issue, If we have to send different notification messages to difference users at the same time. Comparing with multiple single notify() call in the loop, this is better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants