Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we send object into data using fcm-node push notification

let messages = {
        
        registration_ids: tokenId,

        notification: {
          title: 'WebServer',
          body: 'Message from center'
        },

        data: { result: { type: 'add', data : 'New Record' }, sender: {'first_name': 'James', 'last_name': 'Antony' } },
      };

      fcm.send(messages, function (err, response) {
        if (err) {
          return err
          console.log("Something has gone wrong!", err);
        } else {
          console.log("Successfully sent with response: ", response.results);
         
        }
      });

Can we send object inside data i.e result can supply type and message.

If I put inside object it does not send notification but if I do toString() it does work but at mobile end it shows [object][object].

How can we Make it correct.

like image 401
simon Avatar asked Sep 17 '25 12:09

simon


1 Answers

The data node can only contain string values. It cannot contain more complex values, such as objects.

If you want to send more complex data, encode it as a string in your message, and decode that string in your application code. For example, you can use JSON.stringify and JSON.parse to send JSON objects.

like image 125
Frank van Puffelen Avatar answered Sep 19 '25 05:09

Frank van Puffelen