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

Send additional fields in kwargs #12

Closed
monicaphalswal opened this issue Mar 22, 2017 · 10 comments
Closed

Send additional fields in kwargs #12

monicaphalswal opened this issue Mar 22, 2017 · 10 comments
Labels

Comments

@monicaphalswal
Copy link

extra_kwargs = {
'content_available': True
}
devices.send_message(
title="Syncup",
body=".",
icon="appicon",
data={
"notification type" : 20
},
kwargs=extra_kwargs
)

I am trying to send additional fields in kwargs but I am getting notify_multiple_devices() got an unexpected keyword argument 'kwargs'. Please help.
Also, I don't want to send the key "body" but when I skip it or make it None, the payload gets messed up. So, is it possible it skip this key entirely?

@xtrinch
Copy link
Owner

xtrinch commented Mar 22, 2017

'kwargs' is not a keyword argument, so don't name it, just pass it as the last argument.

Also please be more specific as to how the payload gets 'messed up'.

@monicaphalswal
Copy link
Author

monicaphalswal commented Mar 22, 2017

I changed the code to:

kwargs = {
        'content_available': True
}
devices.send_message(
                title="Syncup", 
                body=".", 
                icon="appicon", 
                data={
                    "notification type" : 20
                },
                kwargs
           )

But now I am getting error:
SyntaxError: non-keyword arg after keyword arg

And for the missing 'body' part, the payload changes from
{"data":{"notification type":20},"notification":{"body":".","icon":"appicon","title":"Syncup"},"priority":"high","to":"cF3VXFqliZQ:APA91bG3xXHeuoIx2TMYXLcTXooqQyRPiKzfGL4l4h8Cfxpl3vFBVmYY2YuqV6odipSnET2LNv3q4th5qxstNmonf_w2MnUrP77TNWfLV4iDlmNc_gCQPoR_w6F4U-3hJkVAM3ujNKMY"}
to(title goes missing)
{"data":{"notification type":20},"notification":{"icon":"appicon"},"priority":"high","to":"cF3VXFqliZQ:APA91bG3xXHeuoIx2TMYXLcTXooqQyRPiKzfGL4l4h8Cfxpl3vFBVmYY2YuqV6odipSnET2LNv3q4th5qxstNmonf_w2MnUrP77TNWfLV4iDlmNc_gCQPoR_w6F4U-3hJkVAM3ujNKMY"}
(when I remove key "body" from above code).

@xtrinch
Copy link
Owner

xtrinch commented Mar 22, 2017

@xtrinch
Copy link
Owner

xtrinch commented Mar 22, 2017

For the second part - pyfcm's github page is where that question would be answered best, because that part is handled in this file.

@monicaphalswal
Copy link
Author

Thank you for the help. But, I'm still not able to send "mutable_content": True even in kwargs. I am getting notify_single_device() got an unexpected keyword argument 'mutable_content' error.

@ipoogleduck
Copy link

How did you end up fixing this? @monicaphalswal

@merwok
Copy link

merwok commented Jan 30, 2024

The initial problem was that the function call had kwargs=extra_kwargs instead of the correct **kwargs (dictionary unpacking, to add more param=value parameters to the call).

The second problem is different (passing an unknown parameter to a function).

@xtrinch
Copy link
Owner

xtrinch commented Jan 30, 2024

The question is for an obsolete version which used the legacy API, so this question is most likely not relevant anymore

@ipoogleduck
Copy link

Ah okay. I want to add channel_id from https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#androidnotification to my notification payload so I was looking at this to see how it would be possible. I was thinking this would work but maybe I am on the wrong track?

fcm_send_topic_message(message_title=messageTitle,
                                   message_body=messageBody,
                                   condition=favoritesConditions, 
                                   data_message=notif_data,
                                   sound="Default",
                                   extra_kwargs={"android": "{\"notification\": {\"channel_id\": \"" + time_topic + "\"}}"})

@xtrinch
Copy link
Owner

xtrinch commented Feb 2, 2024

@ipoogleduck

from firebase_admin.messaging import Message, Notification
topic = "A topic"
FCMDevice.objects.handle_subscription(True, topic)
FCMDevice.send_topic_message(Message(data={...}), "TOPIC NAME")

And the channel ID you would pass into the Message constructor under android_config, see
https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#resource:-message

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

4 participants