While testing the FCM for Hybrid apps, i depend on some 3rd party to testing it, I thought to create it on my own, and here's it on Heroku !
https://fcm-push.herokuapp.com/
If you need the code, go get here on Github
https://github.com/sulthanallaudeen/fcm-push
I am saving a bit of code here in order to save !
var serverKey = req.body.key;
var fcm = new FCM(serverKey);
var message = {
to: req.body.to,
collapse_key: 'your_collapse_key',
data: {
key: req.body.title
},
notification: {
title: req.body.title,
body: req.body.body
}
};
//callback style
fcm.send(message, function(err, response) {
if (err) {
res.status(200).json({
"success": "0",
"message": err
});
} else {
res.status(200).json({
"success": "1",
"message": response
});
}
});
And the client part will be
$(document).ready(function() { $("#sendPush").click(function() { var url = window.location.href + '/'; var key = $("#key").val(); var to = $("#fcm_token").val(); var title = $("#title").val(); var body = $("#body").val(); $.post("sendPush", { key: key, to: to, title: title, body: body }) .done(function(data) { alert("Pls check console for now !!"); console.log(data); }); }); });
There you go !