firebase / firebase-admin-node

Firebase Admin Node.js SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
1.6k stars 358 forks source link

Sending string values vs. objects #102

Open gotmikhail opened 6 years ago

gotmikhail commented 6 years ago

Operating System version: CentOS Firebase SDK version: 5.4.1 Firebase Product: Cloud Messaging

https://github.com/firebase/firebase-admin-node/blob/fc45c4f5da404e21934cbd9f5a4e7116cb744f0a/src/messaging/messaging.ts#L715

Is there any particular reason why we're restricting the values of the key:value pairs in data to just strings?

If calling https://fcm.googleapis.com/fcm/send directly, you can include objects within data.

hiranya911 commented 6 years ago

The FCP server API reference states:

Values in string types are recommended. You have to convert values in objects
or other non-string data types (e.g., integers or booleans) to string.
hiranya911 commented 6 years ago

@shasd can you also please take a look?

stychu commented 6 years ago

yeah Im also curious aboyt this. Im facing the problem how to send my data payload from server to the client. Any suggestions on how to stringify/parse the payload automatically so i dont have to remember that data payload can be set as

const payload = {
    data: {
        body: 1
    }
};

and it will be stringified or somthing.

rather than always remeber to make this as string ?

const payload = {
    data: {
        body: '1'
    }
};
hiranya911 commented 6 years ago

Perhaps look into TypeScript? Our type definitions enforce this correctly:

[key: string]: string;
redward commented 3 years ago

string;

Any changes ? how to add JSON object within data payload ?

mohammad-kazemzadeh commented 2 years ago

@redward You'll have to stringify the object.

const payload = {
    data: {
        foo: JSON.stringify({foo: "bar"}),
        body: "Notification Body",
        ...
    }
};