Push Notification - agoenks29D/exzly GitHub Wiki
This guide explains the push notification implementation in the feature/push-notification branch of Exzly, covering how notifications are sent using Web Push and Firebase, and how they are handled by the service worker.
This example demonstrates how to send a push notification using the WebPush.
const { pushNotificationHelper } = require('@exzly-helpers');
// Subscription object received from the browser
const subscription = {
endpoint:
'https://fcm.googleapis.com/fcm/send/duPu_oHMe8E:APA91bEyB3xE4F9ebJi_53JIPuC1bDNn94nhwVipC2IVg2A1c5IV9t-zBiH0pOUlvzGHlP1lC4DiP1rs1tPcCV0V3ymoFFtWi7bDzQkirGKzHQ9SxpaGZYcGKHwfEMThI7cjkGKF8iMO',
expirationTime: null,
keys: {
p256dh:
'BFXWc9abFD8okNvsyngBSfJ3uEBl8obIHeOjETSm30not2Wb3jqSccoBm755TpKfS3KBcMIQMgT6lKIYsCZsjSw',
auth: 'G4lmio_rf5kev73ebveCXg',
},
};
// Sending the Web Push notification
await pushNotificationHelper.webPushSendNotification(subscription, {
title: 'Web Push Notification',
body: 'This is an example of a notification sent through Web Push',
image: 'https://616f-36-71-139-209.ngrok-free.app/2444825.jpg',
});
Example of Web Push Notification Display:
This example demonstrates how to send a push notification using the Firebase Admin SDK.
const { pushNotificationHelper } = require('@exzly-helpers');
// Subscription received from the client (usually a Firebase token)
const subscription =
'elNuWUohhiClK1_FxioURK:APA91bGH6vbm1qy9rn0vWiDjvesSwGHWlHq8bD5CI3RBJ1JIjmj1Q6r7GAmeByYmOmfZqUrpygNP7JPfc1mJJ8kQBplrxAajW1BDsOVPCddE9b8J_XduiUI';
// Sending the notification using Firebase Admin SDK
await pushNotificationHelper.firebaseSendNotification(subscription, {
title: 'Firebase Notification',
body: 'This is an example of a notification sent through Firebase',
image: 'https://616f-36-71-139-209.ngrok-free.app/2444825.jpg',
});
Example of Firebase Push Notification Display: