Notifier Bot: Use Discord To Send Push Notifications to Devices

Did you know that you can send Firebase Cloud Messages (FCM) to devices directly from Discord chat? Well yes, and this blog covers it all.

Vishesh Bansal
GDSC VIT Vellore
4 min readAug 2, 2021

--

Notifier developed by Vishesh Bansal at the Developer Students Club, Vellore Institute of Technology, India, sends Firebase Cloud Messages (FCM) directly from Discord, without ever leaving the Discord Chat. Written in JavaScript, it not only provides sends neatly formatted messages to apps but also sends those to the desired announcements channels in a Discord Server, making it a one-stop tool for conveying messages during an event to all participants.

Since Notifier is powered by the Discord.js Library, it makes an excellent use case, better than other Discord Bots, since you can easily customize it according to your needs and use-cases. You can write your own methods to perform specific functions. Moreover, it is completely open-source!

How to Set it Up?

Well, it is quite simple to use. The setup takes about 5–7 minutes.

Head over to Discord’s Developer Portal. Create a new application.

Create New application
  • Give a name to your application.
  • Invite your Bot to your Discord Server with these permissions (Note: you have to be a server administrator for this).
The permissions needed for the bot to work in the server.
  • Clone the repository. Install the dependencies by running npm install. (Note: You need to have Node.js installed on your system).
  • Create a .env file and store your Bot Token.
Click on Copy Token to Copy the Token
  • Enter a prefix for the bot, ID of the role to be pinged, along with the Role Names of the users having permissions to run the bot in the config_sample.json and change the name to config.json.
  • Go to your Firebase Project, Click on Settings -> Project Settings. Select Service accounts. Now click on Firebase Admin SDK and select Node.js and click on Generate New Private Key. This will generate and download a JSON containing your keys. Rename this and save it in the root folder of your project.

Keep this safe with you at all times, since it gives admin access to your Firebase Project and can be misused.

Generate a new Firebase Admin SDK Service Account
  • In the files, index.js and firebase_tokens.js change the path:
var serviceAccount = require("./FIREBASE_ADMIN_SDK.json")

to your Firebase Admin SDK credentials with the name, you had used to save it with, in the previous step. For more information refer to Firebase Setup Documentation.

  • In the files firebase_tokens.js change ENTER_COLLECTION_NAME_HERE to the Collection Name for your token documents in Cloud Firestore.

That’s it you are good to go!

Type npm start in your console, and start using it!

It can be deployed on AWS Lambda as well very easily, or run locally. Both ways it will function.

Notifier in Action

Once you are done setting up the steps mentioned above, head over to Discord. You will now see your bot showing Online. Voilà!

Here goes Notifier informing people about all important announcements!

Command to run Notifier in Admin channel
Notifier making announcements in announcement channel as well sending FCM message implemented inside the WomenTechies ’21 app.

Conclusion

Notifier successfully delivers what it promises: Wide reach from one platform”. The goal for future implementations is to integrate it with other services, and improve its overall functionality and further promote a better user experience.

And it does its job quite well! It increases the efficiency of the organizing team by many folds since they can devote their time to other tasks to focus on other tasks smoothly.

So the next time you are conducting a hackathon, do try it out!

Feel free to contribute to it here :)

--

--