OneRoute
  • Introduction
  • Prerequisites
  • Whatsapp API
    • Sandbox (Test API Key)
    • Getting Started
    • Endpoints
      • Fetch Channels
      • Fetch Channel Templates
      • Send Template Message
      • Send Campaign Message
      • Send Session Message
    • FAQ
  • EMAIL API
    • Getting Started
    • Endpoints
      • Fetch Email Channels
      • Send Email to Customers
  • SMS API
    • Getting Started
    • Endpoints
      • Fetch SMS Channels
      • Send SMS to Customers
      • Send OTP SMS to Customers
      • Fetch SMS Messages
      • Get SMS DLR Message
  • ONEOTP API
    • Getting Started
    • Endpoints
      • Fetch OTP Templates
      • Send OTP
      • Verify OTP
  • EMBED
    • Getting Started
    • Installation
    • Push Notification
  • OTHERS
    • Receiving Events - Webhooks
    • Fetch Channel By Id
    • Fetch Logs
Powered by GitBook
On this page

Was this helpful?

  1. EMBED

Push Notification

OneRoute Embed also supports push notifications and requires some dependencies from your Web App.

How to Install

  • Create a firebase-messaging-sw.js file in your public folder (make sure to use the exact filename).

  • Copy and paste the code below in the file created:

/* eslint-disable no-restricted-globals */
/* eslint-disable no-undef */

importScripts(
  "https://www.gstatic.com/firebasejs/9.0.0/firebase-app-compat.js"
);
importScripts(
  "https://www.gstatic.com/firebasejs/9.0.0/firebase-messaging-compat.js"
);

const firebaseConfig = {
  apiKey: "<-- Check dashboard -->",
  authDomain: "<-- Check dashboard -->",
  projectId: "<-- Check dashboard -->",
  storageBucket: "<-- Check dashboard -->",
  messagingSenderId: "<-- Check dashboard -->",
  appId: "<-- Check dashboard -->",
};

firebase.initializeApp(firebaseConfig);

// Retrieve firebase messaging
const messaging = firebase.messaging();

messaging.onBackgroundMessage(function (payload) {
  const message = JSON.parse(payload.data.message);
  console.log("NBMA");

  const notificationTitle = `New message from ${message.sender.name}`;
  const notificationOptions = {
    body: message.content,
    icon: "/favicon.ico", // Your WebApp's favicon.
  };

  self.registration.showNotification(notificationTitle, notificationOptions);
  self.addEventListener("notificationclick", function (event) {
    event.notification.close();
  });
});
  • Redeploy your WebApp, and you should start getting push notifications.

PreviousInstallationNextReceiving Events - Webhooks

Last updated 1 year ago

Was this helpful?

You can find the values for the firebaseConfig keys on your OneRoute Dashboard > Settings > > Notifications.

Account Settings