Skip to content

Instantly share code, notes, and snippets.

@essejose
Created February 8, 2018 11:19
Show Gist options
  • Save essejose/30b177ac5507186776180b7fa7d4b4fa to your computer and use it in GitHub Desktop.
Save essejose/30b177ac5507186776180b7fa7d4b4fa to your computer and use it in GitHub Desktop.
Server Admin SDK do Firebase,
/*
Snippet
Admin SDK do Firebase
Firebase features such as Database, Storage, and Auth by the unified Admin SDK.
Go https://console.firebase.google.com/project/meu-instalador-teste/settings/serviceaccounts/adminsdk
Download your private key
npm install --save firebase-admin
see more https://www.npmjs.com/package/firebase-admin
*/
var admin = require("firebase-admin");
var serviceAccount = require("./private_key.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "databaseURL"
});
// This registration token comes from the client FCM SDKs.
var registrationToken = "token to send push";
// See the "Defining the message payload" section above for details
// on how to define a message payload.
var payload = {
data: {
title: "Titulo",
body: "mensagem",
sound: "sound.mp3",
//this data go inside additionalData
Custom:"string",
OtherCustom:"string"
},
};
// Set the message as high priority and have it expire after 24 hours.
var options = {
priority: "high",
timeToLive: 60 * 60 * 24
};
// Send a message to the device corresponding to the provided
// registration token with the provided options.
admin.messaging().sendToDevice(registrationToken, payload, options)
.then(function(response) {
console.log("Successfully sent message:", response);
})
.catch(function(error) {
console.log("Error sending message:", error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment