codeforbtv / cvoeo-app

The "Money on My Mind" app helps CVOEO's Reach-Up clients stay on track with their personal finance coaching.
Apache License 2.0
11 stars 4 forks source link

Research whether a firebase function that can send push notifications to the app #88

Open doub1ejack opened 5 years ago

doub1ejack commented 5 years ago

Research whether we can use a firebase function to trigger push notifications going to the app.

This is more of a R&D project than an app feature, but it would be super valuable to better understand how P.N.s are sent, what info they need, and how they are received. It seems likely that they could be sent from a F.B. function, but not guaranteed.

A F.B. function can easily be triggered with a GET request (see https://us-central1-cvoeo-45350.cloudfunctions.net/helloWorld) so that would be a very convenient development tool for the whole team if we could get it working.

To make the work sharable, create a new function in the root /functions directory, update the repo's firebase conf file (optional), and push your changes to a draft PR regularly.

johnneed commented 5 years ago

@doub1ejack @jfenner @iritush

It can.

Currently your goals for each user are stored as an array in the user object. I'd recommend adding the goals as a collection underneath the user. You'll be able to listen directly to changes on this collection, which will make your code simpler.

Here's some example code on how to set up a function to listen to changes, if goals are moved to a collection.

// Send Push Notification when a new goal is created for a user
exports.onGoalCreate = functions.firestore.document('users{userIdl}/goals/{goalId').onCreate(
    (snap, context) => {
        const goal = snap.data();
        const userId= context.params.userId;
        const goalId = context.params.goalId;
       // some function to retrieve the push notification token for that user.
        const  pushToken = getToken(userId); 
       // some function to send data to the Expo push notification service
        return sendPushNotification(userId,  pushToken, goal); 
    });

Here's the info on how to setup Push Notifications

I believe this ticket is technically complete

johnneed commented 5 years ago

@kmeyersvt Can we get a judgment on whether this ticket should be closed?