Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ceredsms notification provider #5368

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions server/notification-providers/ceredsms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const NotificationProvider = require("./notification-provider");
const axios = require("axios");

class CeredSMS extends NotificationProvider {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, was changed for all others

Suggested change

name = "ceredsms";

/**
* @inheritdoc
*/
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
let okMsg = "Sent Successfully.";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, was changed for all others

Suggested change
let okMsg = "Sent Successfully.";
const 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}`;
Comment on lines +29 to +30
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are first checking if message exists and then using error.messsage
Is this intentional?

this.throwGeneralAxiosError(error);
} else {
let error = "CeredSMS.pl API returned an unexpected response";
this.throwGeneralAxiosError(error);
Comment on lines +31 to +34
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing inside the catch does not work as you think it does.
Please throw a regular error here instead.

}
}

return okMsg;
} catch (error) {
this.throwGeneralAxiosError(error);
}
}
}

module.exports = CeredSMS;
4 changes: 3 additions & 1 deletion server/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const Cellsynt = require("./notification-providers/cellsynt");
const Onesender = require("./notification-providers/onesender");
const Wpush = require("./notification-providers/wpush");
const SendGrid = require("./notification-providers/send-grid");
const CeredSMS = require("./notification-providers/ceredsms");

class Notification {

Expand Down Expand Up @@ -154,7 +155,8 @@ class Notification {
new GtxMessaging(),
new Cellsynt(),
new Wpush(),
new SendGrid()
new SendGrid(),
new CeredSMS()
];
for (let item of list) {
if (! item.name) {
Expand Down
1 change: 1 addition & 0 deletions src/components/NotificationDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export default {
"ServerChan": "ServerChan (Server酱)",
"smsc": "SMSC",
"WPush": "WPush(wpush.cn)",
"ceredsms": "cered.pl",
};

// Sort by notification name
Expand Down
24 changes: 24 additions & 0 deletions src/components/notifications/CeredSMS.vue
Original file line number Diff line number Diff line change
@@ -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>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a link to the docs or where users can find this token as a helptext?

</div>
<div class="mb-3">
<label for="ceredsms-phone-number" class="form-label">{{ $t("To Phone Number") }}</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("Originator") }}</label>
<input id="ceredsms-sender-name" v-model="$parent.notification.ceredsmsSenderName" type="text" minlength="3" maxlength="11" class="form-control">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a helptext where this will be displayed. For SMS this is not quite obvious

</div>
</template>

<script>
import HiddenInput from "../HiddenInput.vue";

export default {
components: {
HiddenInput,
},
};
</script>
2 changes: 2 additions & 0 deletions src/components/notifications/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import Cellsynt from "./Cellsynt.vue";
import WPush from "./WPush.vue";
import SIGNL4 from "./SIGNL4.vue";
import SendGrid from "./SendGrid.vue";
import CeredSMS from "./CeredSMS.vue";

/**
* Manage all notification form.
Expand Down Expand Up @@ -142,6 +143,7 @@ const NotificationFormList = {
"Cellsynt": Cellsynt,
"WPush": WPush,
"SendGrid": SendGrid,
"ceredsms": CeredSMS,
};

export default NotificationFormList;
Loading