parent
4228dd0a29
commit
909a0d081e
@ -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;
|
@ -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>
|
Loading…
Reference in new issue