react-native-onesignal icon indicating copy to clipboard operation
react-native-onesignal copied to clipboard

Can't find any documentation on how to handle the actions buttons in my notification

Open sleekLancelot opened this issue 10 months ago • 2 comments

How can we help?

I need some help on how to handle action buttons, they are already been sent from the server, i just need to lead the user to a screen in the app when the button is clicked.

I can see a "How can I use the action button click event?" Section in the docs. But the only part of that section that seems useful to my use-case leads to "page not found". https://documentation.onesignal.com/docs/web-push-sdk#addlistenerfornotificationopened

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

sleekLancelot avatar Apr 09 '24 03:04 sleekLancelot

Not got all the answers for you as I don't work for OneSignal, but:

The broken link will work if you change the URL to v9 (their previous version) https://documentation.onesignal.com/v9.0/docs/web-push-sdk#addlistenerfornotificationopened . If you're using the latest, this may obviously not be what you want. Note that it's a page for the web SDK though.

There's a similar page in the old docs here too https://documentation.onesignal.com/v9.0/docs/action-buttons#how-can-i-use-the-action-button-to-do-some-work-on-my-page-without-opening-extra-windows

If you're using the latest version of RN OneSignal, though, I'm pretty sure you can do the following:

OneSignal.Notifications.addEventListener('click', event => {
  // check the actionId of the notification button that you set via: `event.result.actionId`
  // Now you have access to the actionId and can redirect (navigate) accordingly

VirtualDOMinic avatar Apr 09 '24 23:04 VirtualDOMinic

Thanks a lot for helping @VirtualDOMinic, i was able to get it to work by reading the docs of other SDK's and even older ones like the one you shared too. Thanks man!

sleekLancelot avatar Apr 20 '24 15:04 sleekLancelot

Thank you for your help here, @VirtualDOMinic!

jennantilla avatar Jun 04 '24 19:06 jennantilla