Push notification in chat application


#1

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
      
    });

#2

And your question or problem?


#3

Problem ? I want to implement this in my application


#4

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


#5

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


#6

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.


#7

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


#8

I repeat:

So this doesn’t really make sense.


#9

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


#10

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


#11

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


#12

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.


#13

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


#14

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.


#15

i’ll try to look to my backend. thanks


#16

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


#17

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


#18

Not yet, what is your backend ?


#19

i ’ am using firebase as backend


#20

thanks will use it any tell you if it helped me