107
Views
3
Comments
[OneSignal PWA/Web Push Notifications] How does it support Web Push Notification?
Question
web-push-notifications
Mobile icon
Forge asset by João Amaral
Application Type
Mobile

Hi,

I was wondering how to use this forge as I cannot consume mobile's client action in reactive application (obviously) and can we have a demo on how to register the user on RWA?

OR.. does it mean we have to register ourselves on mobile, only then the push notification will be sent to my "web application" after logging into my web application?  Thanks!

Kenny

2023-08-20 04-20-03
RAD Manage

Kenny,

The OneSignal Forge component is initially designed for mobile applications. However, you can definitely adapt it to work with a Reactive Web Application.

Here are some steps you can follow to implement OneSignal API for Web Push Notifications in your RWA:

  1. Initialize OneSignal SDK: Include the OneSignal JavaScript SDK in your application. You can do this by placing the SDK script in the Head section of your main layout.

  [ <script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async=""></script> ]

  1. Initialize User: Once the SDK is loaded, you'll need to initialize your OneSignal app by providing the appId. You can do this using client actions or JavaScript code in the OnInitialize or OnReady event of your page.

[ OneSignal.init({ appId: "your-app-id-here", autoRegister: false, }); ]

  1. Register User: Call OneSignal’s register method to register the user for push notifications.

[ OneSignal.registerForPushNotifications(); ]

  1. Handle Notifications: You can set event handlers to take specific actions when a notification is received or clicked. These can trigger client actions if you so desire.

[ OneSignal.on('notificationDisplay', function(event) { console.log('OneSignal notification displayed:', event); }); ]

  1. Server-side Logic: For server-side triggering of notifications, you can use the REST API provided by OneSignal. Create a server action in OutSystems to handle this. Additionally you can use the client actions from the notifications above to trigger server actions of any sort.

Please note that you don't have to register the user on mobile to receive notifications on the web application. You can directly register your web users for push notifications using the existing structure available.

The Web Quickstart documentation on OneSignal's website should fill in the blanks:
https://documentation.onesignal.com/docs/web-push-quickstart


Feel free to reach out if you have more questions or need further clarification.

Best regards,
RAD Manage


UserImage.jpg
João Amaral

Hi Yung Shin ,

Basically a mobile PWA application is just a web application running on a shell over the the phone browser, so the mobile OneSignal Forge component won't work on PWA applications, just the native mobile ones.

This component will implement the notification with OneSignal on mobile PWA apps. For Web app the code is exactly the same, you just need to copy the logic to a Web app module, as I forgot that a reactive application can't consume a mobile's client action.

To register the user you just have to run the RegisterUser client action anywhere you see fit on your application, depending on the use case. As you do that this component will automatically save the OneSignal PlayerId, that you can use later to send notification to that user phone (or web browser), trough the One Signal API. 

This is just the basics but you can check the OneSignal Documentation to customize and add features to your notifications.

Let me know if you need any further clarification.

Best regards,

João Amaral


2023-11-14 07-36-16
Yung Shin

Hi Joao,

Thanks for your reply. I tried to implement it in my RWA, but I'm receiving the following message.

I've copied the sw.js to my RWA and set the module name as 'SandboxReactive'. The playerId is not captured/stored in the database.

Not sure if I missed anything here.. 

Kenny

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.