android - Sending Arbitrary data with notification style Firebase cloud messaging -


i have short question. want send custom value cloud function listens onwrite events in firebase database. code cloud function:

const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeapp(functions.config().firebase);  exports.pushnotification = functions.database.ref('/chats/notifications/{pushid}').onwrite( event => {   var values = event.data.val();  const payload = {     notification: {         title: values.username,         body: values.message,         sound: "default",         displayname: values.username,         uid:  values.recieveruid     }, }; const options = {     priority: "high" }; return admin.messaging().sendtotopic(values.recieveruid, payload, options);}); 

and database structure looks this:

chats

-notifications

-some id

-username: fdsdf

-uid: 9043554

how can send uid device? way in code not work displayname... how supposed it

you can pass arbitrary key value pairs in notification message adding data key same level notification key in payload:

{"notification": {...}, "data" : {       "uid": 9043554     } } 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -