uptime-kuma/server/notification-providers/octopush.js

65 lines
2.4 KiB
JavaScript
Raw Normal View History

2021-09-07 15:42:46 +01:00
const NotificationProvider = require("./notification-provider");
const axios = require("axios");
class Octopush extends NotificationProvider {
name = "octopush";
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
2021-10-05 20:40:59 +01:00
let okMsg = "Sent Successfully.";
2021-09-07 15:42:46 +01:00
try {
2021-10-05 18:43:04 +01:00
// Default - V2
if (notification.octopushVersion == 2 || !notification.octopushVersion) {
let config = {
headers: {
2021-10-05 18:43:04 +01:00
"api-key": notification.octopushAPIKey,
"api-login": notification.octopushLogin,
"cache-control": "no-cache"
2021-09-07 15:42:46 +01:00
}
2021-10-05 18:43:04 +01:00
};
let data = {
"recipients": [
2021-10-05 18:43:04 +01:00
{
"phone_number": notification.octopushPhoneNumber
2021-10-05 18:43:04 +01:00
}
],
//octopush not supporting non ascii char
"text": msg.replace(/[^\x00-\x7F]/g, ""),
"type": notification.octopushSMSType,
"purpose": "alert",
"sender": notification.octopushSenderName
2021-10-05 18:43:04 +01:00
};
await axios.post("https://api.octopush.com/v1/public/sms-campaign/send", data, config)
} else if (notification.octopushVersion == 1) {
let data = {
"user_login": notification.octopushDMLogin,
2021-10-05 18:43:04 +01:00
"api_key": notification.octopushDMAPIKey,
"sms_recipients": notification.octopushDMPhoneNumber,
"sms_sender": notification.octopushDMSenderName,
"sms_type": (notification.octopushDMSMSType == "sms_premium") ? "FR" : "XXX",
"transactional": "1",
//octopush not supporting non ascii char
"sms_text": msg.replace(/[^\x00-\x7F]/g, ""),
};
2021-10-05 18:43:04 +01:00
let config = {
headers: {
"cache-control": "no-cache"
},
params: data
};
await axios.post("https://www.octopush-dm.com/api/sms/json", {}, config)
} else {
throw new Error("Unknown Octopush version!");
}
2021-09-07 15:42:46 +01:00
return okMsg;
} catch (error) {
this.throwGeneralAxiosError(error);
}
}
}
module.exports = Octopush;