muraliwebworld / push-notification-plugin-for-wordpress-websites

Push Notification WordPress plugin in php, javascript using Firebase httpv1 for websites, Android/IOS mobile apps with PWA progressive web app
https://wordpress.org/plugins/push-notification-for-post-and-buddypress/
GNU General Public License v3.0
12 stars 1 forks source link

Not saving or sending push notifications #6

Closed mattprudente closed 3 months ago

mattprudente commented 4 months ago

Hi there

We have an issue with the plugin as follows:

When sending a one time push notification it doesn't save to the "Notifications" list. The list just displays "No registered device tokens available.", despite there being one in the Device Tokens list. The device registered is a native iOS app. I don't want to send browser notifications.

I've tried adding/updating a post and checking notifications and that doesn't do anything either.

We are using Firebase Cloud Messaging API (v1) and I have uploaded the service account JSON file and completed the configuration fields apart from Firebase Server Key and Firebase Public key (could this be the issue? I thought these were only used before the new API?!).

We do run on NGINX, but I am guessing that the service worker files are for PWAs and not native app notifications? I have had to modify some URLs in PHP to work with root.io Bedrock setup ( /wp-admin is actually /wp/wp-admin).

Any thoughts on why it's not sending please?

muraliwebworld commented 4 months ago

Please let me know console error messages , if possible please attach screenshots. httpv1 version will work by uploading json file. I think it might be due to scope different for service worker, because service worker file which is important thing to subscribe notifications will be created in root directory. Please let me know console messages from browser (chrome browser - developer tools - inspect - console), today only i saw your message in github, sorry for my late reply

mattprudente commented 3 months ago

Not a problem! I've had a 504 when enabling the settings for NGINX server. Once I turn that off I can load the site, but I don't see any console messages when trying to send a push.

The firebase-messaging-sw.js and pnfpb_icpush_pwa_sw.js are created but located in the "html_root/wp/ "folder (Bedrock structure).

Screenshot 2024-03-19 at 17 12 22
muraliwebworld commented 3 months ago

Please verify whether you are able to access service worker file from your domain https:///pnfpb_icpush_pwa_sw.js

Also check in application tab whether service worker is registered like this in attached screenshot. Please also check in your hosting file manager in root directory above file should be created if NGINX static file option is turned on.

Thanks Murali Screenshot 2024-03-20 at 6 17 09 PM

mattprudente commented 3 months ago

I can see the file has been created and I can access it via https://sbox-petworthplaces.srgry.uk/pnfpb_icpush_pwa_sw.js, but I'm not getting any service workers in Chrome (https://sbox-petworthplaces.srgry.uk).

mattprudente commented 3 months ago

I've managed to get the PWA service worker running, but still no messages are saving to the sent notifications list, nor is my iOS app receiving anything.

muraliwebworld commented 3 months ago

While creating IOS app in firebase console, please make sure ios app is within same project as web app, the credentials api key and public key must be from same project where both web app and ios app present inside same project in firebase console. Please make sure google-info.plist for ios app needs to contain same api key like in your web app which you are filling in plugin settings. If both web app and ios app in firebase console are from same firebase project then it will work without any problem. i have verified for android webview by having only one webview token , it is working fine. i have attached video, screenshots below for your reference. it is also saving notifications in notification list. The message related to device token list is not relevant as i made mistake by giving same error message from device token list because both device token list and notification list uses same logic, while duplicating the logic i forgot to update error message, it is only cosmetic text problem, i will update it in next release otherwise function is working as expected as shown below,

Screenshot 2024-03-22 at 6 12 07 PM Video showing on demand/one time push notification and notification list https://github.com/muraliwebworld/push-notification-plugin-for-wordpress-websites/assets/32461311/f57e6bdf-1b67-4242-a426-b433ae3fd227

https://github.com/muraliwebworld/push-notification-plugin-for-wordpress-websites/assets/32461311/db748ac3-4a84-48c5-9e43-359f51e0f611

Screenshot_20240322_181215_One UI Home

mattprudente commented 3 months ago

Thank you for coming back with those details. However, the iOS app and Firebase setup is correct. I go to one time push notifications, hit send and it clears the form but doesn't send a notification or save to the sent list. Is it to do with the Bedrock by roots.io wordpress setup?

muraliwebworld commented 3 months ago

In PWA settings, please turn on Exclude all Urls from PWA offline cache and List of urls to be excluded from cache separated by comma - in this enter /domainname/ to exclude all urls starting with your domain name. Also in chrome in application tab go to service worker tab under cache storage, please check if it creates any cache urls starting with your domain name. Since google required PWA with cache, i have introduced we can ignore the cache by turning on above option and also by including url to exclude like i said above

Also in application tab, please verify any other service worker file is present, at a time browser will take only one service worker but that is needed only if we use website push notifications. For webview service worker is not needed as we are subscrbing from the app pass it to wordpress.

muraliwebworld commented 3 months ago

I will also try to create a test site using bedrock roots.io, i will let you know in 1 or 2 days

muraliwebworld commented 3 months ago

I have tried by installing bedrock roots.io wordpress along with this plugin PNFPB, i found the problem why it is not creating service worker file, since i included ABSPATH in static file creation logic to create service worker file, it created inside wp folder(subfolder of web) instead of in its parent web folder. I tried again by changing logic to with home path (absolute path) to create service worker file, it created in correct folder, I am able to send push notifications. I will release the changes to wordpress repo by tomorrow . I will update you once it is released to wordpress repo 1.82 version by tomorrow GMT+5.30

muraliwebworld commented 3 months ago

I have released 1.82 version in WordPress repo, now it is compatible with bedrock roots.io WordPress boilerplate. Whenever you change PWA admin settings or push notification settings, please regenerate static service worker file(push notification) and PWA manifest.json files in NGINX tab to reflect the changes, since these are static files we need to do do this. Switch off the option, save changes, turn on again and save changes to get latest service worker and PWA mainfest static files. For hosting which supports dynamically generated service worker file and PWA manifest.json this option is not needed.

muraliwebworld commented 3 months ago

I have verified by installing bedrock roots.io WordPress boilerplate, push notifications are working fine and one time notifications are working fine, attached are screenshots (in below screenshots wordpress admin is inside /wp/ subfolder - bedrock roots.io WordPress boilerplate. I am closing this issue, Screenshot 2024-03-26 at 6 30 12 PM Screenshot 2024-03-26 at 6 30 02 PM Screenshot 2024-03-26 at 6 27 38 PM Screenshot 2024-03-26 at 6 27 21 PM