/firebase-push

Small scripts for working with Firebase Cloud Messaging (FCM) web push notifications

Primary LanguageJavaScriptMIT LicenseMIT

Test Firebase Cloud Messaging

Small scripts for working with Firebase Cloud Messaging (FCM) web push notifications. Based on quickstart-js

  • Clean scripts without excess code. Ready to use;
  • Added opportunity to work and test on github pages;
  • Added possibility to process click on a notification: open or focus a linked page.

There are four scripts here:

  • firebase_client.js - which used on a client side for subscription for notifications;
  • firebase-messaging-sw.js - is the ServiceWorker;
  • firebase_webhook.php - which process users token on a server side and save it to storage for future usage;
  • firebase_notifications_sender.php - sample script for sending notifications.

The best way to test client side is use Postman with sending POST messages with:

{
    "data": {
    "title": "Title",
    "body": "Notification message",
    "icon": "https://kulikov-dev.github.io/firebase-push/notification_logo.jpg",
    "click_action": "https://kulikov-dev.github.io/firebase-push/"
  },
  "to": "user-token-id" 
}
  • To get 'Server key' you need to enable 'Cloud Messaging API (Legacy)'.