Push notification in chat application

can you give me an example for how to use this plugin to solve my problem to push new messages to user
actually i don’t know why you told me to receive device token
can you explain please?
thanks

First make sure to follow the installation steps.

Download your Firebase configuration files, GoogleService-Info.plist for ios and google-services.json for android, and place them in the root folder of your cordova project

You need to know that each device owns a unique token, so it can be identified and receive push notifications.
You can store this token in your database, under the user node who owns the token.
Then you can use this token to send push notification to this device.

firebasePlugin.onTokenRefresh().subscribe((token: string) => {
    // This is how you get the device token
});

You will also need your server key, you can find it in your firebase settings.
And make sure you test it on a real device, it will not work in the browser or emulator.

Here is how I implemented it in my code:

firebase.database.ref('/users').child(userId).once('value', (user) => {

    let headers = new Headers();
    headers.append('Content-Type', 'application/json');
    headers.append('Authorization', 'key=' + YOUR_SERVER_KEY);

    let body = {
      "notification": {
        "body": message,
        "badge": 1,
        "sound": "default"
      },
      "priority": "high",
      "to": user.val().device_token
    }

    this.http.post('https://fcm.googleapis.com/fcm/send', JSON.stringify(body), { headers: headers })
      .map(res => res.json())
      .subscribe(data => { console.log(data); });

})

It possible to add it to my backend ? I don’t use Firebase

I can’t build with Firebase plugin

I think you can create a Firebase account and use FCM, without needing to use firebase as your backend.
But you need a Firebase account to get the GoogleService-Info.plist, google-services.json files and your server key.

Why? Do you get any error when trying to?

And make sure to read the installation steps fully.

Note that the Firebase SDK requires the configuration files to be present and valid, otherwise your app will crash on boot or Firebase features won’t work.

I’ll post the picture later. Thanks for your reply i’ll try later

i have a problem with firebase plugin, it possible to do it with onesignal ?

Yes, but I do not have any experience with onesignal so I cannot help you with it.

thanks for your help, but as i can with oneSignal so i will do it.

hey @antoinedupont, possible to use it with push plugin ?