Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 Notifycli — Firebase Push Notification CLI

A lightweight Go-based CLI for sending push notifications to mobile and web devices using Firebase Cloud Messaging (FCM). Built with Cobra, designed for developers, DevOps teams, and automation workflows.


⭐ Features

  • 🔥 Send push notifications to a single device
  • 📎 Include custom data payloads (e.g., URLs, actions, metadata)
  • 🎛️ Easy-to-use flags and subcommands
  • 🧩 Clean project structure (Cobra-style)
  • 🔐 Uses Firebase Service Account credentials
  • ⚙️ Works with backend scripts, cron jobs, CI/CD, and automation pipelines

📁 Project Structure

Notifycli/
 ├── cmd/
 │    ├── root.go          # CLI root command
 │    └── notify.go          # "send" command
 ├── internal/
 │    └── firebase/
 │          └── client.go  # Firebase FCM client wrapper
 ├── go.mod
 ├── go.sum
 ├── test/
 └── main.go               # CLI entry point

📦 Installation

Clone the repo:

git clone https://github.com/johnafariogun/Notifycli
cd Notifycli

Build:

go build -o notifcli

Optionally install globally:

go install

🔧 Configuration

1. Firebase Service Account

Download a serviceAccount.json from Firebase Console:

Project Settings → Service Accounts → Generate new private key

Place it in in your project root.


🛠 Commands

### notify — Send notification to a single device

notifcli notify --token <DEVICE_TOKEN> [flags]

Flags

Flag Description Required
--token FCM device token ✅ yes
--title Notification title ✅ yes
--body Notification body ✅ yes
--url Optional link added to data payload no (defaults to https://google.com)
--creds Path to Firebase service account file ✅ yes (default: serviceAccount.json)

📤 Example Usage

Send a simple notification

You can get an fcm token from https://clever-florentine-b7c154.netlify.app/
notifcli notify \
  --token "DEVICE_FCM_TOKEN" \
  --title "Deployment Successful" \
  --body "Your service is live."

Send a notification that includes a URL

notifcli notify \
  --token "DEVICE_FCM_TOKEN" \
  --title "New Article" \
  --body "Tap to read the latest update." \
  --url "https://example.com/articles/42"

When the mobile app receives the notification, the FCM payload contains:

{
   "url": "https://example.com/articles/42"
}

Your app can use this to open a web browser or deep-link into a screen.


🧩 How the URL Works

When calling the CLI with:

--url "https://example.com"

The CLI attaches the link to the FCM data payload:

data := map[string]string{
    "link": url,
}

This ensures the mobile client always receives the link, regardless of platform (Android / iOS).


⚙️ Internal Architecture

internal/firebase/client.go

Handles:

  • Firebase app initialization
  • Authentication using service account key
  • Sending notifications via FCM REST API
  • Support for custom data payloads

Easy to extend with:

  • batch messaging
  • topic messaging
  • image notifications
  • deep links
  • silent pushes

🛡 Error Handling

The CLI prints descriptive errors on:

  • invalid or missing flags
  • missing service account file
  • invalid FCM token
  • Firebase initialization failures
  • network issues

About

A Go cli

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages