firebase-admin-node icon indicating copy to clipboard operation
firebase-admin-node copied to clipboard

Sending string values vs. objects

Open gotmikhail opened this issue 8 years ago • 6 comments

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.

gotmikhail avatar Oct 09 '17 15:10 gotmikhail

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 avatar Oct 10 '17 17:10 hiranya911

@shasd can you also please take a look?

hiranya911 avatar Oct 10 '17 17:10 hiranya911

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'
    }
};

stychu avatar Nov 14 '17 11:11 stychu

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

[key: string]: string;

hiranya911 avatar Jan 26 '18 23:01 hiranya911

string;

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

redward avatar Jan 21 '21 10:01 redward

@redward You'll have to stringify the object.

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

mohammad-kazemzadeh avatar Feb 28 '22 14:02 mohammad-kazemzadeh