-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
489 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// eslint-disable-next-line import/no-unresolved | ||
const { getMessaging } = require('firebase-admin/messaging'); | ||
/** | ||
* @typedef {Object} PushConfig | ||
* @property {string} fcmToken | ||
* @property {string} senderName | ||
* @property {string} message | ||
* @property {string} messageUrl | ||
* @property {boolean} superfan | ||
* @property {string} language | ||
*/ | ||
|
||
/** | ||
* @param {PushConfig} config | ||
* @returns | ||
*/ | ||
exports.sendNotification = async (config) => { | ||
const { fcmToken, senderName, message, messageUrl } = config; | ||
|
||
/** | ||
* @type {import('firebase-admin/messaging').Message} | ||
*/ | ||
const fcmPayload = { | ||
notification: { | ||
title: `Message from ${senderName}`, | ||
body: message | ||
}, | ||
webpush: { | ||
fcmOptions: { link: messageUrl } | ||
}, | ||
token: fcmToken | ||
}; | ||
|
||
// Send a message to the device corresponding to the provided | ||
// registration token. | ||
return getMessaging() | ||
.send(fcmPayload) | ||
.then((response) => { | ||
// Response is a message ID string. | ||
console.log('Successfully sent message notification:', response); | ||
}) | ||
.catch((error) => { | ||
console.log('Error sending message notification:', error); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.