ionic-team / capacitor-plugins

Official plugins for Capacitor ⚡️
517 stars 583 forks source link

feat: Support for Action Buttons in Push Notifications Plugin #213

Open fromage9747 opened 3 years ago

fromage9747 commented 3 years ago

Feature Request

Support for Action Buttons in Push Notifications Plugin.

Description

Whilst Local Notifications can produce the Action Buttons, it is a workaround, and it relies on the ability of "PushNotifications.addListener( 'pushNotificationReceived'" to run in the background, which it does not. "pushNotificationReceived" only fires when the app is in the foreground.

Platform(s)

[x ] Android [x ] iOS [ x] web

Preferred Solution

Just like how LocalNotifications has the registerActionTypes Method, Push Notifications should have the same.

PushNotifications.registerActionTypes({ types: [ { id: 'alert', actions: [ { id: 'read', title: 'Mark as Read' }, { id: 'archive', title: 'Archive Alert', destructive: true }, { id: 'delete', title: 'Delete Alert', destructive: true } ] } ] });

Alternatives

I have looked into triggering the action types via LocalNotificaitons but it does not produce the desired effect as "pushNotificationReceived" does not trigger when the app is running in the background. it only triggers when the app is running in the foreground.

Additional Context

this was closed when it shouldn't have been: https://github.com/ionic-team/capacitor/issues/1938 "pushNotificationReceived" issues: https://github.com/ionic-team/capacitor/issues/1928#issuecomment-767127172 https://github.com/ionic-team/capacitor-plugins/issues/200

danbirle commented 3 years ago

bump; did the triage happen at all? 😄 may we please know the outcome, if any?

shanike commented 2 years ago

End of 2021, Any update ?? This is important (:

danbirle commented 2 years ago

End of 2020, Any update ?? This is important (:

you mean 2021*?

fromage9747 commented 2 years ago

He's been in quarantine so long he didn't realize that another year had rolled by.

shanike commented 2 years ago

End of 2020, Any update ?? This is important (:

you mean 2021*?

Thanks lol

He's been in quarantine so long he didn't realize that another year had rolled by.

She* 😊

riderx commented 2 years ago

2022 and still no solution ?

MohsinJamadar09 commented 2 years ago

+1

JustDoItSascha commented 2 years ago

+1

fromage9747 commented 2 years ago

@JustDoItSascha as I would of course like this I have figured out why there is no work being done on it. Normal push notifications can been configured to be sent only as data so there is no popup notification. Now with this data only notification, it also works in the background, or I have read it does in documentation. So when the data is received, you can then launch a local notification which has action buttons.

I am currently in the process of implementing this as the normal push notifications module from ionic does not have the ability to refresh a token. Mine just expired. Die to this I am moving to firebase messaging which has delete token and get token in order to refresh the token.

I will then be moving forward with the local notifications and action buttons.

JustDoItSascha commented 2 years ago

@fromage9747 I think that even "only data" push notifications are not working in the background, but I'm absolutely willing to be convinced it does ;-)

I would be happy if you could post when you're 100% sure that data only push will be handled when the app is closed?

fromage9747 commented 2 years ago

@JustDoItSascha Well, I finished implementing this and am very disappointed. The data-only push does not trigger anything when the app is in the background and there is no way of getting action buttons implemented when sending it via the payload. Every search result I have checked and tried to implement has not worked.

Foreground notifications work with Local Notifications but not the background, I have had to add the Notification payload to at least receive a notification. This is such a PITA. Trying to look into writing Android native code to see if I can get the action buttons.

My PWA side of things works perfectly though with action buttons as well. All handled by the service worker

terryjiang2020 commented 1 year ago

@fromage9747 Just to ask, have you tried third-party providers like OneSignal? Would they work?

typefox09 commented 1 year ago

+1