Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

send push notifications from app + small callback fix for push #286

Closed
ButterMeWaffle opened this issue Feb 16, 2017 · 4 comments
Closed
Assignees
Milestone

Comments

@ButterMeWaffle
Copy link

ButterMeWaffle commented Feb 16, 2017

Hey Eddy,

Not an issue but I just managed to turn the curl into an http.request so we can send push notifications from the app itself. I thought it might be a good idea to add this code to the push section for others to use.

required --

var http = require("http");

the code

http.request({
    url: 'https://fcm.googleapis.com/fcm/send',
    method: "POST",
    headers: { 'Authorization': 'key=myFBKey', 'Content-Type': 'application/json' },
    content: JSON.stringify({
        "notification": {
            "title": "testingtesting",
            "text": "some text",
            "sound": "default",
            "priority": "High"
        },
         'data': { "foo": "bar" },
        'to': "usersPuchKey"
    })
}).then((response) => {
    //HttpResult = response.content.toJSON();
    console.log('----------------------------------------------------');
    console.log(JSON.stringify(response));
}, (e) => {
    console.log("Error occurred " + JSON.stringify(e));
});

of course you would need to switch out the myFBKey and the usersPushKey for the proper keys.

(sorry is this is the wrong place to post this, also cant seem to fix the formatting of my code :( sorry) [EV: fixed, check the source to see how :)]

@ButterMeWaffle
Copy link
Author

ButterMeWaffle commented Feb 16, 2017

something i noticed, on the onMessageReceivedCallBack function, message.foo throws an error unless to set message to any. Here is code that does not throw an error (very small change to yours)

onMessageReceivedCallback: function (message: any) {
        console.log("Title: " + message.title);
        console.log("Body: " + message.body);
        // if your server passed a custom property called 'foo', then do this:
        console.log("Value of 'foo': " + message.foo);
}

@ButterMeWaffle ButterMeWaffle changed the title send push notifications from app send push notifications from app + small callback fix for push Feb 16, 2017
@EddyVerbruggen
Copy link
Owner

Thanks, will take a look. Planning on releasing a new version today, so would be nice to add this as well.

@EddyVerbruggen
Copy link
Owner

I've now added a data: any property to the message, so we can still use it as message: Message. With backward compatibility.

@EddyVerbruggen
Copy link
Owner

I've opened an issue in the demo app repo to add an in-app push button. Not sure it belongs in the plugin, but it's a great addition to the demo app.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants