https://remoteindian.com/ logo
#random
Title
# random
t

thankful-dusk-45985

02/21/2022, 4:43 PM
Anyone here who has worked with Hasura and Firebase? I'm struggling to setup push notifications for my mobile app that go from Hasura to FCM. Can pay a small consultation fee as well. (posting more deets in reply, mods do lmk if this is the wrong channel)
• Building an Android app in Kotlin with some social features like following users, likes, comments, replies etc. • Currently using Hasura as our main backend (works on a postegreSQL DB). We also use Firebase for authentication. • Already have a notifications table setup in Hasura, where notifications are recorded on like/comment/follow etc. No push notifs tho. • We need to send a push notification to the user whenever someone follows them, likes their post or replies to their comment. • Essentially, this would require setting up an event trigger on Hasura, that whenever there is an update to our table, it should send an entry to Firebase Cloud Messaging (FCM), which sends a notification to the user's phone. • This would likely involve using serverless functions on Google Cloud, Lambda or anything else that works. However, as am not an expert on this, am totally open to any other approach/solution as well.
k

kind-france-68039

02/22/2022, 11:48 AM
Hello @thankful-dusk-45985 one approach which I can suggest to work with it faster is following This is the workflow assuming you have installed and setup the required steps • Duplicate notifications data in firestore in a collection say
notifications
• Since you wanted to however use firebase functions for this write a
onCreate
event by giving a path
notifications/{id}
• Now in that function use firebase messaging so send notifications, simplest way to do is to
sendToTopic
and topic id would be
uid
and in the client application you need to
subscribeToTopic
uid
on login • Then this should technically work out of the box for android. • If extending to iOS you would need to add the
.p8
file to the firebase console, without this file firebase can’t send notifications. • Example snippet can be this, note
click_action
is here for flutter thingy so need not worry about that.
Copy code
promises.push(
            admin.messaging().sendToTopic(uid, {
              data: {
                storyId: context.params.storyId,
                click_action: "FLUTTER_NOTIFICATION_CLICK",
              },
              notification,
            })
          );
• The
notification
above is a json object, which looks like this
Copy code
{
    title: `Title.`,
    body: "Message!",
    image: "Image",
    icon: "icon",
    content_available: "true",
  };
• Again the
content_available
is only for
iOS
t

thankful-dusk-45985

02/22/2022, 1:25 PM
Thank you so much @kind-france-68039<3 ! That makes it very clear. It's probably simpler to do this than to setup event triggers >> serverless functions >> FCM I suppose.
🙌 1
k

kind-france-68039

02/22/2022, 1:27 PM
Yeah and what you also do is to run a cron job to delete notifications of the previous day. Something like that so the firebase firestore bill is 0$ 😛
😂 1
t

thankful-dusk-45985

02/22/2022, 2:16 PM
so far full backend $0 cost, so this will help keep it that way 🙏
🙌 1
3 Views