Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Migrate from Push Subscriptions to FCM Integration #17

Merged
merged 6 commits into from
May 8, 2024

Conversation

stigi
Copy link
Member

@stigi stigi commented Apr 25, 2024

FCM Integration

In this PR the old push_subscription logic is replaced by the new mobile_push/fcm channel.

To get this to work I had to update the SDK and the example app.
In the SDK I refactored the com.magicbell.sdk.feature.pushsubscription into com.magicbell.sdk.feature.fcmtoken.

In the example I've updated:

  • The Android SDK version to 34 to have support for the new notifications permissions
  • Added the firebase SDK dependency & added a FirebaseMessagingService which is used to register device tokens and receive firebase messages (aka notifications)
  • Added an example implementation of a askNotificationPermission function and updateDeviceToken function

Test Plan

I've registered an app with the com.magicbell.example package in the firebase console and added the resulting google-services.json file to the android project (at example/google-services.json).

I then exported the service account private key and registered it with magicbell by sending a PUT to /integrations/fcm.

Now when the app is launched the token registration can be observed in Proxyman:

CleanShot 2024-05-06 at 18 21 21@2x

When calling the disconnectUser(...) function the token is successfully removed:

CleanShot 2024-05-06 at 18 21 24@2x

While the token is registered a push notifications arrive on the device:

magicbell broadcasts create --action-url "act://ion" --content "Via CLI" --title "Check this Broadcast" --custom-attributes '{custom:"Value"}' --recipients "hi@ullrich.is"

CleanShot 2024-05-06 at 18 30 39@2x

The data of the notification message can be handled in onMessageReceived :

  • message.data constains custom values and action URL
    CleanShot 2024-05-06 at 18 36 53@2x
  • message.notification.title and message.notification.body contain title and body
    CleanShot 2024-05-06 at 18 38 00@2x
    CleanShot 2024-05-06 at 18 38 17@2x

Base automatically changed from ullrich/notification-preferences-update to main April 26, 2024 10:48
@stigi stigi force-pushed the ullrich/integrations-fcm-channel branch 2 times, most recently from 39123e9 to d8f1e71 Compare April 29, 2024 08:40
@stigi stigi force-pushed the ullrich/integrations-fcm-channel branch from d8f1e71 to 67476cf Compare May 2, 2024 08:28
@stigi stigi marked this pull request as ready for review May 6, 2024 16:49
@stigi stigi requested review from unamashana and moxley01 May 6, 2024 16:49
@stigi stigi self-assigned this May 8, 2024
@stigi stigi merged commit 70eb034 into main May 8, 2024
@stigi stigi deleted the ullrich/integrations-fcm-channel branch May 8, 2024 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants