-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add support for Mattermost, OneSignal and PagerDuty
- Loading branch information
Paul Aschmann
committed
Jul 21, 2022
1 parent
2e30d70
commit d496036
Showing
5 changed files
with
214 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const provider = require("./provider"); | ||
const axios = require("axios"); | ||
|
||
class Slack extends provider { | ||
|
||
name = "mattermost"; | ||
|
||
parameters = { | ||
required: { | ||
mattermostWebhookUrl: "", | ||
text: "" | ||
}, | ||
optional: { | ||
|
||
} | ||
}; | ||
|
||
async send(notification) { | ||
try { | ||
let data = { | ||
"text": notification.required.text | ||
}; | ||
|
||
await axios.post(notification.required.mattermostWebhookUrl, data); | ||
return "Sent Successfully."; | ||
} catch (err) { | ||
return err; | ||
} | ||
} | ||
} | ||
|
||
module.exports = Slack; |
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,47 @@ | ||
const provider = require("./provider"); | ||
const axios = require("axios"); | ||
|
||
class OneSignal extends provider { | ||
|
||
name = "onesignal"; | ||
|
||
parameters = { | ||
required: { | ||
onesignalAppId: "", | ||
onesignalApiKey: "", | ||
playerId: "", | ||
text: "", | ||
subject: "" | ||
}, | ||
optional: {} | ||
}; | ||
|
||
async send(notification) { | ||
try { | ||
const serverUrl = "https://onesignal.com/api/v1/notifications"; | ||
|
||
const data = { | ||
app_id: notification.required.onesignalAppId, | ||
include_player_ids: [notification.required.playerId], | ||
email_subject: notification.required.subject, | ||
email_body: notification.required.text | ||
}; | ||
|
||
let config = { | ||
headers: { | ||
"Content-Type": "application/json", | ||
"Authorization": "Basic " + notification.required.onesignalApiKey, | ||
"Accept": "application/json", | ||
} | ||
}; | ||
|
||
await axios.post(serverUrl, JSON.stringify(data), config); | ||
|
||
return "Sent Successfully."; | ||
} catch (err) { | ||
return err; | ||
} | ||
} | ||
} | ||
|
||
module.exports = OneSignal; |
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,64 @@ | ||
const provider = require("./provider"); | ||
const axios = require("axios"); | ||
|
||
class PagerDuty extends provider { | ||
|
||
name = "pagerduty"; | ||
|
||
parameters = { | ||
required: { | ||
pagerDutyApiKey: "", | ||
pagerDutyRoutingKey: "", | ||
eventAction: "", | ||
source: "", | ||
severity: "", | ||
text: "Test" | ||
}, | ||
optional: { | ||
dedup_key: "", | ||
timestamp: "", | ||
component: "", | ||
group: "", | ||
class: "", | ||
custom_details: {} | ||
} | ||
}; | ||
|
||
async send(notification) { | ||
try { | ||
const serverUrl = "https://events.pagerduty.com/v2/enqueue"; | ||
|
||
const data = { | ||
routing_key: notification.required.pagerDutyRoutingKey, | ||
event_action: notification.required.eventAction, | ||
... (notification.optional.dedup_key && { timestamp: notification.optional.dedup_key }), | ||
payload: { | ||
summary: notification.required.text, | ||
source: notification.required.source, | ||
severity: notification.required.severity, | ||
... (notification.optional.timestamp && { timestamp: notification.optional.timestamp }), | ||
... (notification.optional.component && { component: notification.optional.component }), | ||
... (notification.optional.group && { group: notification.optional.group }), | ||
... (notification.optional.class && { class: notification.optional.class }), | ||
... (notification.optional.custom_details && { custom_details: notification.optional.custom_details }) | ||
} | ||
}; | ||
|
||
let config = { | ||
headers: { | ||
"Content-Type": "application/json", | ||
"Authorization": "Basic " + notification.required.pagerDutyApiKey, | ||
"Accept": "application/json", | ||
} | ||
}; | ||
|
||
await axios.post(serverUrl, JSON.stringify(data), config); | ||
|
||
return "Sent Successfully."; | ||
} catch (err) { | ||
return err; | ||
} | ||
} | ||
} | ||
|
||
module.exports = PagerDuty; |
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