Skip to main content

Dive Into Code: How to Use Google Firebase Cloud Notifications with Hypi

Explore Hypi's serverless functions

written by:
Courtney Robinson

Excited to integrate Google Firebase Cloud Notifications into your Hypi app? Let's get hands-on with some real GraphQL examples to show you exactly how to set things up. This mini-tutorial will guide you through subscribing to topics, sending personalized notifications, and broadcasting messages. Let’s code!

Step 1: Subscribe to a Topic

First off, let’s subscribe a user to a topic so they can receive updates. Add this mutation to your Hypi app schema to start receiving notifications on a specific topic.

mutation {
subscribeFCM(
topic: "news",
token: "<A FCM token>"
)
}

Replace "<A FCM token>" with the actual FCM token of the user's device. This example subscribes the user to the "news" topic.

Step 2: Send a Personalized Notification

Want to send a custom notification to a user? Use this mutation to push a notification directly to a device using its FCM token. This can include a message with a title, body, and even an image!

mutation {
sendFCM(
message: {
data: { new_msg_id: "msg1" },
notification: {
title: "Hello world",
body: "Hello there!",
image: "https://images.pexels.com/photos/1629781/pexels-photo-1629781.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2"
}
},
token: "<A FCM token>"
)
}

Customize the title, body, and image URL to fit your notification content.

Step 3: Broadcast to a Topic

Need to send a message to all users subscribed to a topic? This mutation allows you to broadcast a notification to everyone subscribed to the "news" topic, for instance.

mutation {
sendToTopicFCM(
topic:"news",
message: {
data: {new_msg_id: "msg1"},
notification: {
title: "Breaking News",
body: "Stay tuned for more updates.",
image: "https://images.pexels.com/photos/1629781/pexels-photo-1629781.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2"
}
}
)
}

This sends a notification to all devices subscribed to "news" with the provided message content.

Putting It All Together

Integrating FCM with your Hypi app opens up endless possibilities for engaging with your users through timely and relevant notifications. Whether you're sending a warm welcome message, the latest news updates, or personalized alerts, the power is now at your fingertips.

Remember, the examples above are just the beginning. Feel free to tweak the mutations to suit your app’s specific needs and user engagement strategies. Happy coding, and here's to skyrocketing your app's engagement with Hypi and Firebase Cloud Notifications! 🚀

P.S. Don't forget, if you haven't signed up for Hypi yet, now's the perfect time to jump in and start experimenting with these powerful notifications. Register today and give your users the engaging experience they deserve!

Powered By Hypi.
Loading...
X

Still not convinced? Contact our sales team for a free demo, we’ll get you started

Make it happen! Access scalable platform for your customers needs.

Phone

By registering you agree to the Terms & Conditions