Troubles with Push Notifications setup


#1

I’m trying to get Push Notifications to work but having some issues.

I have pretty standard setup and tried to follow the manual:

  • installed plugin discourse-push-notifications
  • setup SSL via Let’s Encrypt
  • created an app in Google Cloud with GCM API
  • setup credentials
  • set api key and project id in plugin settings

When I reloaded my app in Chrome on Android, Chrome suggested to add site onto home screen (as an app). But no question on push notifications was asked. So they don’t work.

In Google cloud console I can’t see any traffic for GCM.

What to check? How to debug? Any help is appreciated.


(Rafael dos Santos Silva) #2

To get notifications you must go to your profile and click the Enable Push Notifications button.


#3

Ok, found it and enabled. But still there’re no notifications…


#5

I have to dump the topic up and tried to ask advice one more time as I really have no idea what to check more.
So I’d narrow the question to: how to check that Discourse tries to send any push notifications?

I setup GCM but I can’t see any incoming activity in its stats, so problems is obvious on my server side, “push notifications” were activated in user settins, tried different browsers (push notifications work fine for meta.discource for me, so the problem is not with the browser/device)


(Alan Tan) #6

Can you try the following steps?

  1. Enable push notifications for your user
  2. Run this command from your rails console: DiscoursePushNotifications::GCMPusher.push(User.find_by(username: '<your username>'), {})

You should receive a push notification almost immediately. If not, it’ll indicate that the configurations for google cloud messaging might be incorrect.


#7

I got nil and no notifications:

[7] pry(main)> DiscoursePushNotifications::GCMPusher.push(User.find_by(username: 'Shrike'), {})         => nil

So, something wrong is with my GCM settings… Is there some logs somewhere? I checked:

/shared/log/rails/production.log 
production_errors.log
unicorn.stdout.log
unicorn.stderr.log

but there’s nothing there


(Alan Tan) #8

Hmm maybe try going through the setup GCM again? Is Firefox push notification working for you?


#9

Done this several times

Found this interesting warning in GCM docs:


So I migrated my GCM project to Firebase, and tried using new server key (longer)
(Sign in - Google Accounts/settings/cloudmessaging)
But it changed nothing.

No (
(tried two accounts and desktop and Android)

Right after I recreated GCM app and re-run the code I got some different result:

[8] pry(main)> DiscoursePushNotifications::GCMPusher.push(User.find_by(username: 'Shrike'), {})
=> {"discourse_push_notifications"=>{"google-cloud-messaging"=>{}, "push-services-mozilla"=>{}}}

(instead of nil)
But still there’re no notifications.
Next run returned again nil.


(Alan Tan) #10

Are there any subscriptions in

User.find_by(username: <user>'').custom_fields


#11

Yeah:

[1] pry(main)> User.find_by(username: 'Shrike').custom_fields
=> {"discourse_push_notifications"=>{"google-cloud-messaging"=>{}, "push-services-mozilla"=>{}}}

#12

Finally I got it working!

I came into GCM again and noticed that now I have not only API key but also Server Key.
Probably it’s after I migrated my app to Firebase.
I used the server key and finally it starts working.
So the manual is outdated and the warning in the docs makes sense. For push notifications to work we need server key which cannot be created in https://console.developers.google.com/apis/ anymore.
Instead we have to use https://console.firebase.google.com/

BTW: there’re two server keys there: long (“Server key”) and short (“legacy server key”). For GCM we need the legacy one.
(I previously tried the long one)


(Alan Tan) #13

Ah ha. Let me update the docs soon :slight_smile: Thanks for debugging this!

Hmm still Mozilla push notification should work automagically.


#15

maybe, but for me they don’t.

also after some time of celebrating it stops working again :frowning: All I did as I can remember - edited credentials (restrictions/name), rolling back, creating new credentials (in Firebase) and a new project in Firebase didn’t help.


(Ed Arcos) #16

For several days I’ve been trying to make the plugin work without success. I’ve followed the very outdated guide, then I’ve discovered exactly what @Shrike found out. But it just doesn’t work.

I’ve tried creating a new project, but that is not helping either.

I deleted everything, uninstalled the plugin, re-installed it again, nothing.

Even though the settings are correct (Organization ID + legacy server key entered in settings) I get the following error in the console when pressing the push notifications button on my profile:

Registration failed - missing applicationServerKey, and manifest empty or missing

Also, button dissapeared on Firefox browsers ¯_(ツ)_/¯


(Alan Tan) #17

Can you try upgrading again? I just pushed a new version of Discobot that wouldn’t require you to register an app with Google at all.


(Ed Arcos) #18

Now it works like a charm. Thank you!!


#19

It works for me on desktop and mobile (Chrome & Firefox). Thanks a lot!


(Alan Tan) #20