Giter VIP home page Giter VIP logo

notification-sender's Introduction

notification-sender

This is a demo Java Spring Boot application to generate FCM notifications. The App uses REST API to send a notification with a random meme embed in it.

Firebase configurations are setup in FirebaseConfig.class, and its implementation is done on FirebaseServiceImpl.java, A Java Bean is already created that will be used to use Firebase Services throughout the Application.

    @Bean
    FirebaseMessaging firebaseMessaging() throws IOException {
        GoogleCredentials googleCredentials = GoogleCredentials
                .fromStream(new ClassPathResource("firebase-service-account.json").getInputStream());
        FirebaseOptions firebaseOptions = FirebaseOptions
                .builder()
                .setCredentials(googleCredentials)
                .build();

        FirebaseApp app = FirebaseApp.initializeApp(firebaseOptions);
        return FirebaseMessaging.getInstance(app);
    }

Quickstart

First, you need atleast JDK 17 or above and Maven installed on your machine.

Then you must provide your Firebase Account Credentials, if you dont have, then generate from firebase.google.com, After getting your own firebase account and credentials of a new project, create a file at /src/main/resources/ called firebase-service-account.json. Then fill the following data with your Firebase account keys.

{
  "type": "your_type",
  "project_id": "your_project_id",
  "private_key_id": "your_private_key_id",
  "private_key": "your_private_key",
  "client_email": "your_client_mail",
  "client_id": "your_client_id",
  "auth_uri": "your_auth_uri",
  "token_uri": "your_token_uri",
  "auth_provider_x509_cert_url": "your_auth_provider_x509_cert_url",
  "client_x509_cert_url": "your_client_x509_cert_url",
  "universe_domain": "your_universal_domain"
}

API

The App has a public REST API endpoint {DOMAIN}/api/v1/sendNotifications, Method: POST, Request Body: RAW JSON Body of structure:

{
  "fcmToken" : "your_unique_app_device_token_generated_by_firebase"
}

So all the client-app is need to do is sent its fcmToken as a Request Body field into this API to get a random meme notification.

Dependencies

App requires Java 17 or above installed on the machine and uses 2 Dependencies imported from Maven Central called firebase-admin and spring-webflux.

firebase-admin is used to generate and sent push notifications to the located device using FCM TOKEN, and spring-webflux is used to call external APIs, in our case, its used to get a random meme from https://meme-api.com/gimme using GET method.

notification-sender's People

Contributors

ishantsikdar avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.