noi-techpark / it.bz.noi.community

NOI Community App for the Web
GNU General Public License v3.0
0 stars 1 forks source link

As a developer i want to send Push Notifications for the NOI Community App #21

Open RudiThoeni opened 2 years ago

RudiThoeni commented 2 years ago

Issue where the whole process of Subscribing to push messages / send push messages is described:

Plan is: Every user that agrees on getting Push Messages will be subscribed into Firebase Topic maybe we can use "newsfeednoi" as topic name (https://firebase.google.com/docs/cloud-messaging/android/topic-messaging?hl=en)

Steps:

RudiThoeni commented 2 years ago

@Dimension Is it possible to include in the app the subscription to the topic by the language the user has activated:

(at example "newsfeednoi_de") (at example "newsfeednoi_it") (at example "newsfeednoi_en")

(The backend to send the pushnotifications works this way (by language))

RudiThoeni commented 2 years ago

After subscription to topic we have to define what type of firebase message should be send, i suppose the Data payload because the app then should show the news....... so i think i have to add the NewsId, is this enough?

If you define the Field Names to send would be great?

matax87 commented 2 years ago

@Piiit I need you to perform several steps in order to use push notification via Firebase Cloud Messaging on iOS, since we cannot proceed by ourselves due to the limitation of our developer users in the team:

  1. Create an iOS APNs Auth Key from Apple Developer Member Center, see How to Create an iOS APNs Auth Key
  2. Upload it on Firebase Cloud Messaging, see Upload your APNs authentication key.
RudiThoeni commented 2 years ago

@matax87 I've done all steps please test if it works (in the screenshot i removed the key / team id)

image

matax87 commented 2 years ago

@RudiThoeni and @Piiit we need to plan a session to:

  1. setup iOS push notification on the app in the Apple Apple Developer Member Center and update CD stuff
  2. present you the FCM push notification template that we adopted in order to let push notifications open the app and deep link to a news detail.
RudiThoeni commented 2 years ago

@matax87 Ok sent you an email to schedule the meeting

matax87 commented 2 years ago

After subscription to topic we have to define what type of firebase message should be send, i suppose the Data payload because the app then should show the news....... so i think i have to add the NewsId, is this enough?

If you define the Field Names to send would be great?

The template that we are going to discuss today is:

{
    "notification": {
        "title": "Titolo",
        "body": "Testo della notifica",
        "sound": "default",
        "link": "noi-community://it.bz.noi.community/newsDetails/{newsId}"
    },
    "data": {
        "deep_link": "noi-community://it.bz.noi.community/newsDetails/{newsId}"
    }
}
RudiThoeni commented 2 years ago

@matax87 i checked and compared with our other project and i think there is no other firebase config needed the authentication key should be enough

I only forgot to ask, the Topics are named "newsfeednoi_de / newsfeednoi_it / newsfeednoi_en" right?

matax87 commented 2 years ago

@matax87 i checked and compared with our other project and i think there is no other firebase config needed the authentication key should be enough

Seems fine

I only forgot to ask, the Topics are named "newsfeednoi_de / newsfeednoi_it / newsfeednoi_en" right?

Yes

chiaraDimension commented 2 years ago

@RudiThoeni Android needs another field in notification template to show the icon both in notification banner and in the status bar. Therefore the template becomes:

{
    "notification": {
        "title": "Titolo",
        "body": "Testo della notifica",
        "sound": "default",
        "link": "noi-community://it.bz.noi.community/newsDetails/{newsId}"
                "icon": "ic_notification"
    },
    "data": {
        "deep_link": "noi-community://it.bz.noi.community/newsDetails/{newsId}"
    }
}
RudiThoeni commented 2 years ago

@chiaraDimension ok no problem, i will add this field in my template.

@matax87 I tested on IOS and the push message was delivered, the news opened successfully, on Android i wasn't able to test because of crashes of the current version,

chiaraDimension commented 2 years ago

@chiaraDimension ok no problem, i will add this field in my template.

@matax87 I tested on IOS and the push message was delivered, the news opened successfully, on Android i wasn't able to test because of crashes of the current version,

The push notification arrive on Android too and the news detail is opened successfully (I was testing the app, when arrived your testing notification)

matax87 commented 2 years ago

@chiaraDimension ok no problem, i will add this field in my template.

@matax87 I tested on IOS and the push message was delivered, the news opened successfully, on Android i wasn't able to test because of crashes of the current version,

I got it as well and it worked!

RudiThoeni commented 2 years ago

also on android i was successful on testing push notifications, great work!

RudiThoeni commented 1 month ago

Hi Dimension @matax87 @chiaraDimension

I switched Firebase FCM Api because the old format is deprecated and i got an email that it stopped working on 20.07. I had to change the payload of the notification format from this here

{
    "notification": {
        "title": "Titolo",
        "body": "Testo della notifica",
        "sound": "default",
        "link": "noi-community://it.bz.noi.community/newsDetails/{newsId}"
                "icon": "ic_notification"
    },
    "data": {
        "deep_link": "noi-community://it.bz.noi.community/newsDetails/{newsId}"
    }
}

To the new format

{
     "message" : {
        "topic": "events_de",
    "notification": {
        "title": "Titolo",
        "body": "Testo della notifica",
    },
    "data": {
        "deep_link": "noi-community://it.bz.noi.community/newsDetails/{newsId}"
    }
    }      
}

I had to remove the properties sound, icon, link because i got from the fcm api unknown name \"link\" at 'message.notification': Cannot find field. unknown name \"icon\" at 'message.notification': Cannot find field. unknown name \"sound\" at 'message.notification': Cannot find field.

Not sure if the Detail opening of the Push Message works (without this link property)....... should i add the link property also to the data object? Or do we have to use this platform specific delivery options? (https://firebase.google.com/docs/cloud-messaging/concept-options#example-notification-message-with-platform-specific-delivery-options)

thank you for veryfing,

cheers Rudi

s1g53gv commented 1 month ago

Hi @RudiThoeni the current and previous Android versions of the app use the link field of the Notification object in the RemoteMessage object (on Android). Adding it to the data dictionary might work on a new version of the app but will break existing ones. The FCM V1 APIs documentation does not seems to mention a link field anywhere but - it might be just a deja-vu - it is poorly made and it is likely in the message.android.notification.link just like sound and icon are so, yes, you can try to add the fields the the platform specific message.android.notification object. We might also update the Android app to use the custom deep_link field in the data section so the link will gradually cease to be necessary.

RudiThoeni commented 1 month ago

Thank you for your answer, i think we will request an update on the App which uses directly the deep_link property, so our Project Managers will contact you directly, in the meantime i try to add it to the platform specific object.

s1g53gv commented 3 weeks ago

@RudiThoeni as mentioned in the previous post the legacy link field can be set on FCM V1 by setting message.data.gcm.n.link_android or message.data.gcm.n.link

deep_link = 'noi-community://it.bz.noi.community/newsDetails/{newsId}'

message = messaging.Message(
    notification=messaging.Notification(
        title='Notification title',
        body='...',
    ),
    data={
        'gcm.n.link_android': deep_link, # Backward compatibility
        'deep_link': deep_link,
    },
    android=messaging.AndroidConfig(
        priority='high',
        notification=messaging.AndroidNotification(
            ...
        ),
    ),
    token=...,
)

This should allow already released version of the Android app to keep reading the deep link via Notification.getLink().

RudiThoeni commented 3 weeks ago

@s1g53gv thanks, I've made the changes on backend side, so @sseppi on the next push let's test if it works on old devices........