-
Notifications
You must be signed in to change notification settings - Fork 0
/
Notifier.gs
37 lines (35 loc) · 1012 Bytes
/
Notifier.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function TelegramNotifier(message) {
UrlFetchApp.fetch('https://api.telegram.org/bot' + this.botToken + '/', {
method: "POST",
payload: {
method: "sendMessage",
chat_id: String(this.sendTo),
text: message
}
});
}
function FirebaseNotifier(message) {
UrlFetchApp.fetch('https://fcm.googleapis.com/fcm/send', {
method: 'POST',
contentType: 'application/json',
headers: {
Authorization: 'key=' + this.key
},
payload: JSON.stringify({
notification: {
title: message
},
to: this.deviceToken
})
})
}
function getNotifiers(userConfig) {
const notifiers = []
if (userConfig.useTelegramNotifications) {
notifiers.push(TelegramNotifier.bind({botToken : userConfig.telegramBotToken, sendTo: userConfig.telegramSendToID}))
}
if (userConfig.useFirebaseNotifications) {
notifiers.push(FirebaseNotifier.bind({deviceToken: userConfig.firebaseDeviceToken, key: userConfig.firebaseNotifyKey}))
}
return notifiers
}