add cered.pl sms notification

This commit is contained in:
Czarek 2024-11-21 12:43:08 +01:00
parent 32dc76a085
commit 2c5f8cb14d
6 changed files with 76 additions and 3 deletions

View file

@ -0,0 +1,42 @@
const NotificationProvider = require("./notification-provider");
const axios = require("axios");
class CeredSMS extends NotificationProvider {
name = "ceredsms";
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
let okMsg = "Sent Successfully.";
try {
let config = {
headers: {
"Content-Type": "application/json",
}
};
let data = {
"key": notification.ceredsmsApiKey,
"from": notification.ceredsmsSenderName,
"phone_number": notification.ceredsmsPhoneNumber,
"message": msg.replace(/[^\x00-\x7F]/g, "")
};
let resp = await axios.post("https://sms.cered.pl/api/send", data, config);
if (!resp.data.message_id) {
if (resp.data.message) {
let error = `CeredSMS.pl API returned error message: ${resp.data.error.message}`;
this.throwGeneralAxiosError(error);
} else {
let error = "CeredSMS.pl API returned an unexpected response";
this.throwGeneralAxiosError(error);
}
}
return okMsg;
} catch (error) {
this.throwGeneralAxiosError(error);
}
}
}
module.exports = CeredSMS;

View file

@ -53,6 +53,7 @@ const GoAlert = require("./notification-providers/goalert");
const SMSManager = require("./notification-providers/smsmanager");
const ServerChan = require("./notification-providers/serverchan");
const ZohoCliq = require("./notification-providers/zoho-cliq");
const CeredSMS = require("./notification-providers/ceredsms");
class Notification {
@ -117,7 +118,8 @@ class Notification {
new Webhook(),
new WeCom(),
new GoAlert(),
new ZohoCliq()
new ZohoCliq(),
new CeredSMS()
];
for (let item of list) {
if (! item.name) {

View file

@ -167,6 +167,7 @@ export default {
"WeCom": "WeCom (企业微信群机器人)",
"ServerChan": "ServerChan (Server酱)",
"smsc": "SMSC",
"ceredsms": "sms.cered.pl",
};
// Sort by notification name

View file

@ -0,0 +1,24 @@
<template>
<div class="mb-3">
<label for="ceredsms-key" class="form-label">{{ $t('API Key') }}</label>
<HiddenInput id="ceredsms-key" v-model="$parent.notification.ceredsmsApiKey" :required="true" autocomplete="new-password"></HiddenInput>
</div>
<div class="mb-3">
<label for="ceredsms-phone-number" class="form-label">{{ $t("ceredsmsPhoneNumber") }}</label>
<input id="ceredsms-phone-number" v-model="$parent.notification.ceredsmsPhoneNumber" type="text" class="form-control" required>
</div>
<div class="mb-3">
<label for="ceredsms-sender-name" class="form-label">{{ $t("ceredsmsSenderName") }}</label>
<input id="ceredsms-sender-name" v-model="$parent.notification.ceredsmsSenderName" type="text" minlength="3" maxlength="11" class="form-control">
</div>
</template>
<script>
import HiddenInput from "../HiddenInput.vue";
export default {
components: {
HiddenInput,
},
};
</script>

View file

@ -51,6 +51,7 @@ import WeCom from "./WeCom.vue";
import GoAlert from "./GoAlert.vue";
import ZohoCliq from "./ZohoCliq.vue";
import Splunk from "./Splunk.vue";
import CeredSMS from "./CeredSMS.vue";
/**
* Manage all notification form.
@ -110,7 +111,8 @@ const NotificationFormList = {
"WeCom": WeCom,
"GoAlert": GoAlert,
"ServerChan": ServerChan,
"ZohoCliq": ZohoCliq
"ZohoCliq": ZohoCliq,
"ceredsms": CeredSMS,
};
export default NotificationFormList;

View file

@ -838,5 +838,7 @@
"noOrBadCertificate": "Brak/zły certyfikat",
"Invert Keyword": "Odwróć słowo kluczowe",
"Expected Value": "Oczekiwana wartość",
"Json Query": "Zapytanie Json"
"Json Query": "Zapytanie Json",
"ceredsmsSenderName": "Nadpis",
"ceredsmsPhoneNumber": "Numer telefonu"
}