Push notification in chat application

hey guys, i have a ionic chat application who works we’ll. but i want to send push notification whene a user receive new message.

message.subscribe((msgData)=> {
     console.log("from message data : => " + msgData.record);
      // Handle Message data here
      //if (msgData.record.conversation_id.id === this.id) {
         this.conversation.push(msgData.record); // content is my variable who receve's data
      
    });

And your question or problem?

Problem ? I want to implement this in my application

What exactly?
What does the code have to do with “notification whene a user receive new message.”?

This is my code for user to receive new message on Realtime. My problem is to add Push notification when a user have new message

Push notifications are sent from the server to the Ionic app.
If this code is in your Ionic app, it is only executed when the user is already in the app and he doesn’t need a push notification.

It possible to do it directly from the app ? Or to configure from server like Onesignal or Firebase ?

I repeat:

So this doesn’t really make sense.

yes this, my worry is to send a push when the user is not connected or even to the same application. as whatsapp. Thanks

Then send the push notification in the server when the other user’s message is received there.

thank you, but sorry for the question it may seem absurd. then how to do it?

That depends on your backend application. I guess you have something like “send message from A to B”, then you write the message to the database, and at that moment you can also send a push notification to the user B. If they are already in the app you can handle that whatever way you want, but if not they will see this notification.

i want to try with localNotification plugin!!! good idea?

No as if the user is not running the app, you can’t trigger a local notification.
Push notifications were made exactly for this and how Whatsapp, Facebook Messenger and all the other chat apps do it.

i’ll try to look to my backend. thanks

Did you find any solution on how to make it work?
i face same problem in my real time chat app
i need when some one send message to other send to that user notification that some one message you
like whats app and other apps

If you are using Firebase, you can use this plugin to retrieve the device token and send push notification.

1 Like

Not yet, what is your backend ?

i ’ am using firebase as backend

thanks will use it any tell you if it helped me