feat: Support SMSPlanet notification provider (#5800)

Co-authored-by: Frank Elsinga <frank@elsinga.de>
This commit is contained in:
Dawid 2025-04-26 22:33:26 +02:00 committed by GitHub
parent 3b58ac3fd3
commit f6444aacd2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 100 additions and 3 deletions

View file

@ -0,0 +1,40 @@
const NotificationProvider = require("./notification-provider");
const axios = require("axios");
class SMSPlanet extends NotificationProvider {
name = "SMSPlanet";
/**
* @inheritdoc
*/
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
const okMsg = "Sent Successfully.";
const url = "https://api2.smsplanet.pl/sms";
try {
let config = {
headers: {
"Authorization": "Bearer " + notification.smsplanetApiToken,
"content-type": "multipart/form-data"
}
};
let data = {
"from": notification.smsplanetSenderName,
"to": notification.smsplanetPhoneNumbers,
"msg": msg.replace(/🔴/, "❌")
};
let response = await axios.post(url, data, config);
if (!response.data?.messageId) {
throw new Error(response.data?.errorMsg ?? "SMSPlanet server did not respond with the expected result");
}
return okMsg;
} catch (error) {
this.throwGeneralAxiosError(error);
}
}
}
module.exports = SMSPlanet;

View file

@ -72,6 +72,7 @@ const Onesender = require("./notification-providers/onesender");
const Wpush = require("./notification-providers/wpush");
const SendGrid = require("./notification-providers/send-grid");
const YZJ = require("./notification-providers/yzj");
const SMSPlanet = require("./notification-providers/sms-planet");
class Notification {
@ -160,7 +161,8 @@ class Notification {
new Cellsynt(),
new Wpush(),
new SendGrid(),
new YZJ()
new YZJ(),
new SMSPlanet(),
];
for (let item of list) {
if (! item.name) {

View file

@ -185,7 +185,8 @@ export default {
"PushPlus": "PushPlus (推送加)",
"smsc": "SMSC",
"WPush": "WPush(wpush.cn)",
"YZJ": "YZJ (云之家自定义机器人)"
"YZJ": "YZJ (云之家自定义机器人)",
"SMSPlanet": "SMSPlanet.pl"
};
// Sort by notification name

View file

@ -0,0 +1,46 @@
<template>
<div class="mb-3">
<label for="smsplanet-api-token" class="form-label">{{ $t('smsplanetApiToken') }}</label>
<HiddenInput id="smsplanet-api-token" v-model="$parent.notification.smsplanetApiToken" :required="true"></HiddenInput>
<i18n-t tag="div" keypath="smsplanetApiDocs" class="form-text">
<template #the_smsplanet_documentation>
<a
href="https://smsplanet.pl/doc/slate/index.html#introduction"
target="_blank"
>{{ $t("the smsplanet documentation") }}</a>
</template>
</i18n-t>
</div>
<div class="mb-3">
<label for="smsplanet-phone-numbers" class="form-label">{{ $t("Phone numbers") }}</label>
<textarea
id="smsplanet-phone-numbers"
v-model="$parent.notification.smsplanetPhoneNumbers"
class="form-control"
:placeholder="smsplanetPhoneNumbers"
required
></textarea>
</div>
<div class="mb-3">
<label for="smsplanet-sender-name" class="form-label">{{ $t("Sender name") }}</label>
<input id="smsplanet-sender-name" v-model="$parent.notification.smsplanetSenderName" type="text" minlength="3" maxlength="11" class="form-control">
<div class="form-text">{{ $t("smsplanetNeedToApproveName") }}</div>
</div>
</template>
<script>
import HiddenInput from "../HiddenInput.vue";
export default {
components: {
HiddenInput,
},
computed: {
smsplanetPhoneNumbers() {
return this.$t("Example:", [
"+48123456789,+48111222333",
]);
}
}
};
</script>

View file

@ -70,6 +70,7 @@ import WPush from "./WPush.vue";
import SIGNL4 from "./SIGNL4.vue";
import SendGrid from "./SendGrid.vue";
import YZJ from "./YZJ.vue";
import SMSPlanet from "./SMSPlanet.vue";
/**
* Manage all notification form.
@ -148,6 +149,7 @@ const NotificationFormList = {
"WPush": WPush,
"SendGrid": SendGrid,
"YZJ": YZJ,
"SMSPlanet": SMSPlanet,
};
export default NotificationFormList;

View file

@ -1068,5 +1068,11 @@
"Plain Text": "Plain Text",
"Message Template": "Message Template",
"Template Format": "Template Format",
"Font Twemoji by Twitter licensed under": "Font Twemoji by Twitter licensed under"
"Font Twemoji by Twitter licensed under": "Font Twemoji by Twitter licensed under",
"smsplanetApiToken": "Token for the SMSPlanet API",
"smsplanetApiDocs": "Detailed information on obtaining API tokens can be found in {the_smsplanet_documentation}.",
"the smsplanet documentation": "the smsplanet documentation",
"Phone numbers": "Phone numbers",
"Sender name": "Sender name",
"smsplanetNeedToApproveName": "Needs to be approved in the client panel"
}