How to send chat notifications ionic +4 firebase

I have a chat app that save messages in an array in firebase but I want to generate notifications with every message sent.

I already did push notifications from firebase console with cordova and capacitor, but I need to send them from my app.

I need help, I have almost a week trying to do this…

hola Jorge and welcome to the Ionic community!

could it be that your app can call a firebase function that will ultimately send the notifications from the cloud?


¿Hablas español?

I don’t know how to do that function, I think it can be with http but I don’t really know

the structure in Node is like this:

var message = {

        to: 'userToken', 
        collapse_key: 'storekey',
        notification: {
            title: 'Hi', 
            body: 'Notification from node',
            click_action: 'FCM-PLUGIN-ACTIVITY'             
        data: { 
            user: 'name',
            email: ''

so in Ionic it must be something like that but with http request and response, I don’t know

I never did something like that but I would try my luck with your “tocayo” Jorge Vergara.
His site is here and I’m hoping he wrote about firebase and push notifications.
I found this one but I think is the other way of what you need, perhaps?

Buena suerte,
PS: si, hablo español :argentina:

EDIT: can this one help?

1 Like

I solved already with this function:

    let topic = {
    "to": "/topics/yourtopic",
    "notification": {
    "title": "Breaking News",
    "body": "New news story available."

    let token = {
    "to": "token",
    "notification": {
    "title": "Hola",
    "body": "New news story available."
    fetch("", {
    method: 'POST',
    body: JSON.stringify(token),
    'Content-Type': 'application/json',
    'Authorization': 'Bearer ' + "key"
    }).then(res => res.json())
    .catch(error => console.error('Error:', error))
    .then(response => console.log('Success:', response));

que buena noticia!