feat: browser push notifications (#14888)
* feat: web push notifications feature * Revert yarn.lock changes * added new env variables requirement in .env.example * moved useNotifications hook in packages/lib/hooks * fix: bug * use i18n * chore: move to new file * chore: add yarn.lock * Update .env.example Co-authored-by: Amit Sharma <[email protected]> * chore: add instruction for brave browser * fix: tooltip * chore: use enum * chore * small update --------- Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: Udit Takkar <[email protected]> Co-authored-by: Udit Takkar <[email protected]> Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: Amit Sharma <[email protected]> Co-authored-by: Carina Wollendorfer <[email protected]> Co-authored-by: unknown <[email protected]> Co-authored-by: Anik Dhabal Babu <[email protected]>
This commit is contained in:
17 files changed
+465
-11
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import webpush from "web-push";
|
||||
|
||||
const vapidKeys = {
|
||||
publicKey: process.env.NEXT_PUBLIC_VAPID_PUBLIC_KEY || "",
|
||||
privateKey: process.env.VAPID_PRIVATE_KEY || "",
|
||||
};
|
||||
|
||||
// The mail to email address should be the one at which push service providers can reach you. It can also be a URL.
|
||||
webpush.setVapidDetails("https://cal.com", vapidKeys.publicKey, vapidKeys.privateKey);
|
||||
|
||||
type Subscription = {
|
||||
endpoint: string;
|
||||
keys: {
|
||||
auth: string;
|
||||
p256dh: string;
|
||||
};
|
||||
};
|
||||
|
||||
export const sendNotification = async ({
|
||||
subscription,
|
||||
title,
|
||||
body,
|
||||
icon,
|
||||
}: {
|
||||
subscription: Subscription;
|
||||
title: string;
|
||||
body: string;
|
||||
icon?: string;
|
||||
}) => {
|
||||
try {
|
||||
const payload = JSON.stringify({
|
||||
title,
|
||||
body,
|
||||
icon,
|
||||
});
|
||||
await webpush.sendNotification(subscription, payload);
|
||||
} catch (error) {
|
||||
console.error("Error sending notification", error);
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user