Raudius / Pushraven

A simple Java library to interface with Firebase Cloud Messaging (FCM) API. Pushraven allows you to push notifications to clients in very few lines of code.
MIT License
78 stars 34 forks source link

how to use .addAttributeMap(key, map) #23

Closed fuj1w4r4 closed 6 years ago

fuj1w4r4 commented 6 years ago

Hi there,

can I know how to use .addAttributeMap(key, map)?

//my code Map<String,String> map=new HashMap<String,String>();
map.put("name","Amit");
map.put("abc","Vijay");
map.put("haha","Rahul");

    Notification not = (Notification) new Notification()
            .title(applicationName)
            .body(notificationBody)
            .addAttributeMap("extraField", map);

I got this error: Error Message: '{ "error": { "code": 400, "message": "Invalid JSON payload received. Unknown name \"extra_field\" at 'message.notification'

Raudius commented 6 years ago

The attributes you use must be fields which are supported by the API https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages

For example: addAttribute("title", applicationName) is the same as title(applicationName).

The addAttribute methods exist in case the API gets updated and I have not added the fields into Pushraven. You cant just make up attributes (i.e. extraField) because the API would not know how to interpret that data which is why you got the error.

Raudius commented 6 years ago

Also, I am not sure what you are trying to do in your code but it is possible what you are looking for is:

Notification not = (Notification) new Notification()
            .title(applicationName)
            .body(notificationBody)
            .data(map);
fuj1w4r4 commented 6 years ago

yup, thats the one i am looking for, the extra payload, thanks =D Man, I really love this API, i been checking around, some write their own code to do it, but still i find this API is simple and easy to use. So are you gonna maintain it actively?

Raudius commented 6 years ago

Thanks.

I will try to keep it updated with the API. There are a few improvements that should be done behind the scenes but I have been busy with other things lately. If you find any bugs or come up with improvements just write an issue and I'll have a look.