How can I get the status of push notification permission from browser? - push-notification

I'm developing an web site in PWA way, I'd like to use push notification function.
But I can not find the way to get the status of push notification permission(not asked/blocked/permitted) from browser with javascript code.
Is there any handy way to get it? Or any complicated way?
Currently I'm using firebase messaging's requestPermission() function, which always request the permission to user. I want to get the status of permission without any request to user.

There's Notification object in browser. I could check permission status with Notification.permission which returns granted, default, denied in string.

Related

Firebase Cloud Messaging (FCM) getToken() without requesting browser permission

I am trying to push some data messages to my clients from my cloud functions. These are not really notifications rather they are client specific confidential data that I need to push to the appropriate client.
I do not want to show a notification prompt to my clients, as there is always a chance that some of them might disallow notifications. I need them to always allow by default.
Is there a way to suppress these browser's notification requests? Or is it always mandatory?
In other words, do I always need to call
messaging.requestPermission() before calling messaging.getToken()? Or can I call messaging.getToken() independently?
As far as I know there is currently no way to use the feature to send background messages without requesting permission to display push notifications. So even when you don't display the contents of the messages as a notification, you will have to request permission to do so.
Note that there is movement on this front, such as the quieter permissions UI in Google Chrome, and the quiet notification requests in Firefox.

Dialogflow and Push notification

I'm actually implementing the push notification (https://developers.google.com/actions/assistant/updates/notifications) and I'm not sure to understand everything.
I'm using dialogflow through webhook json with php webservices, and meant to be used with google home (and phone).
All my tests are done through simulator.
I've created an intent get_store
I've created 2 implicits intents (notification_store and notification_text) and activated them as notification in the action console.
When I go into get_store, i'm asking a permission to send notification for notification_store (to send a gmap link), when the user respond yes, it returns me an UPDATES_USER_ID and set the user permission as true in all next requests.
Then, I use this UPDATES_USER_ID and the get_store to send the notification (it responds with a 200 ok)
Questions :
- Once I've accepted the permission, it will not ask me any new permission, even if I want to send notification for notification_text, which means it's one update permission for all notifications intents?
- I can't delete UpdatePermission from my user, even after using reset button or change version
- I have a doubt, does it work only with a released version (alpha/beta/prod) or even with a draft?
If someone can help me to understand what's possible so I could be able to know what is working, not working, not possible.
Thanks.
When you ask for permission to send push notifications, the UPDATE permission gets cached so you don't have to repeatedly ask the user for permission. However this permission is unique to the intent specified when asking for permission.
When asking for a user's permission to send push notifications, you must specify the implicit intent you are asking permission for. So in get_store, I imagine this intent is set to notification_store.
The following code uses the Node.js client library, but the concept is the same:
app.intent('get_store', (conv) => {
conv.ask(new UpdatePermission({intent: 'notification_store'}));
});
Because of this, you can't use get_store to ask for permission for notification_text. Instead you will need to create a separate intent such as get_text, which specifically asks for permission to send push notifications for notification_text.

Firebase notifications security / console activity log

i'm thinking about using Firebase for the notification service that my app needs. However, its important that the process of sending notifications is secure. I want to avoid a notification being sent from any member of the team without permission.
One way could be assigning restricted roles and permissions for the team members. However it also would be good to have any kind of activity log in the console, or have a log of all notifications sent including the name of the user. The console currently allows you to see all notifications sent, but i cannot see who sent it, and also the notification can be deleted from the log.
Any ideas on how to manage this? Which specific roles would you recommend me to use? Is it possible with Firebase?
You could write a function in Firebase which sends notifications, and you have logs on that function. Here is how to write a function which send notifications

Firebase Cloud Messaging for Web - How to maintain the token list in the database and ensure they are valid or up-to-date

With Firebase Cloud Messaging for Web,
How do I maintain the list of valid tokens in my database? For example I've noticed when a user turns off notifications and revisits the site, a new token will be generated and the old token in my database is useless.
I've also tried using Firebase messaging.onTokenRefresh() callback, but it does not get called when I turned off notifications. Also in this case, even if it did get triggered, it returns a new token that was refreshed. How do I keep track of the old token that was refreshed?
Can someone please share with me their thoughts/ways to maintain and ensure the token list in the database are valid or up-to-date?
Any feedback is much appreciated.
Thank you,
Christina
messaging.onTokenRefresh() is probably a wrapper around the event onpushsubscriptionchange.
Indeed that event is currently only called when the subscription is enabled (or enabled again), but not when the permission for push notifications is revoked. So at the moment you can only know that an endpoint has expired when you try to send a notification to it.
More details:
http://blog.pushpad.xyz/2016/05/the-push-api-and-its-wild-unsubscription-mechanism/
In any case you can use the callback to send any new token to the server: at first you will have two tokens stored for the same browser, one expired and the other valid.
Some problems arise if you have data associated to the endpoint (e.g. tag) that you want to preserve during the endpoint change: see the blog post for some suggestions.

Can I register devices from a backend or only from the apps?

the thing is that we already have a backend that handles all the push notification process. From device registration on our DB and notification handling on the device and notification sending to Apple and Google servers...Looking into Parse I saw that it has a lot of things that will take us a lot of time to develop but mostly on the process that sends the notification to the devices.
So...I need to know if devices can register in our backend, then from our backend to Parse and then send push trough Parse. Is this possible? Image below.
Thanks!!
Yes this is possible. You'll need setup your push certificates with Parse and register each device's push token with a Parse Installation object's deviceToken field for it to work. All this is documented on their web site. You'll need to setup a Parse User object for each user as well as each Installation is associated with a single User.

Resources