Push notifications for iPhone and Android apps

:information_source: Summary Send Discourse push notifications to iOS or Android via your own app
:hammer_and_wrench: Repository Link GitHub - Sprachprofi/discourse-fcm-notifications: Send Discourse push notifications through FCM to any custom app
:open_book: Install Guide How to install plugins in Discourse

Features

If you have an app that people can use to browse your Discourse forum, this plugin will let your forum send push notifications via the app. (If you don’t have an app yet but might want one, check out this minimalist solution.)

Convenient for users: when a user receives a push notification about a private message, tapping on that notification will open up your app and directly display that private message. This is a major advantage over using Discourse Pushover Notifications, where push notifications open the Pushover app and it’s not obvious how to get to the message. On the other hand, Pushover Notifications is good if you want push notifications without an app.

Universal: uses Google Firebase as a message layer, so all iOS and Android devices can receive these push notifications, as long as the country hasn’t banned Google.

Configuration

  1. Install and activate the plugin.
  2. Create a free Google Firebase project for your app. Add the Firebase project ID, token and the json (with OAuth data) to the plugin settings in Discourse.
  3. Adjust your app code:
  • Subscribe the active user to push notifications by sending the device token to YOUR_FORUM.com/fcm_notifications/automatic_subscribe?token=… . Be sure to call this every time the device token changes.

  • Unsubscribe the active user by calling YOUR_FORUM.com/fcm_notifications/automatic_subscribe?token=REMOVE

  • Push notifications will have the form:

    'data': {
      "linked_obj_type" => 'link',
      "linked_obj_data" => <url to the post/message referenced in the message>,
    },
    'notification': {
      title: <something like "USERNAME sent you a private message in TOPIC">,
      body: <beginning of the message>,
    }
    

So you need to display the push notification with title/body and tapping on it should open the URL from linked_obj_data in an in-app browser. This is what you have to define in the app’s code.

Example implementation

You can get the code for a minimalist but fully functional app that works with this plugin here. (It’s the whitelabel version of a production app that we created, which needed this plugin.) If you only want an app that displays your forum, sends push notifications and remembers people’s login / last topic read, you just need to change the branding and submit it to the App Stores and you’re done. Otherwise, it could be a foundation.

Proceeds from this app will fund the maintenance and further development of the plugin.

4 Likes

Does the push notification work with the Discourse Hub app?

The Discourse Hub app already comes with push notifications.

Even for self-hosted sites?

1 Like

Hmm… not 100% sure, but I don’t think so. In that case this plugin will be quite useful.

Not right now - whatever app you have, it requires modification to the code.

I don’t think it will be possible to use this plugin with any app that you don’t own, because push notifications depend on sharing Google authentication (or other authentication if not using Google Firebase) between the forum and the app. This is so that Google knows who is responsible for potentially sending malicious or spam notifications and can shut down their account. Also the Google authentication can potentially be used to do other things with the person’s Google account, depending on how it’s set up. So I don’t think that the Discourse Hub app creators (or any app creators) would want to share their Google authentication with everyone who has a self-installed Discourse forum, and of course they cannot add everyone’s Google authentication to the app code (nor ask end users to do it after downloading). For Google Firebase push notifications, the forum and the app must be owned by the same organisation, I don’t see a way around it.

Is there a live app we can test?

See above - you cannot install this plugin on your forum and connect it to any existing app because that would mean the app owner having to share their Google authentication with you.

If you want to see a sample implementation, have a look at https://youtube.com/shorts/iGmTBmhpD4A?feature=share (shown app is this code without any modifications). But your app could look completely different - the plugin only enables your forum to send push notifications to your app, how they are displayed is up to you.