For the complete documentation index, see llms.txt. This page is also available as Markdown.

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();
  });
});

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

  • Redeploy your WebApp, and you should start getting push notifications.

Last updated