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 HostedSMS.pl notification provider #3176

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fixed CRLF -> LF
streamthing authored May 20, 2023
commit 43947882e03dff3fc431f31fdab78bcb5c5a4b4a
106 changes: 53 additions & 53 deletions server/notification-providers/hostedsms.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
const NotificationProvider = require("./notification-provider");
const axios = require("axios");
const { getMonitorRelativeURL, UP, DOWN } = require("../../src/util");
class HostedSMS extends NotificationProvider {
name = "hostedsms";
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
let okMsg = "Sent Successfully.";
try {
let config = {
headers: {
"Content-Type": "application/json",
}
};
let textMsg = "";
if (heartbeatJSON && heartbeatJSON.status === UP) {
textMsg = `✅ [${monitorJSON.name}] is back online`;
} else if (heartbeatJSON && heartbeatJSON.status === DOWN) {
textMsg = `🔴 [${monitorJSON.name}] went down`;
}
let data = {
"UserEmail": notification.hostedsmsUsername,
"Password": notification.hostedsmsPassword,
"Phone": notification.hostedsmsPhoneNumber,
"Message": textMsg,
"Sender": notification.hostedsmsSenderName,
};
let resp = await axios.post("https://api.hostedsms.pl/SimpleApi", data, config);
if (!resp.data.MessageId) {
if (resp.data.ErrorMessage) {
let error = `HostedSMS.pl API returned error message: ${resp.data.ErrorMessage}`;
this.throwGeneralAxiosError(error);
} else {
let error = "HostedSMS.pl API returned an unexpected response";
this.throwGeneralAxiosError(error);
}
}
return okMsg;
} catch (error) {
this.throwGeneralAxiosError(error);
}
}
}
module.exports = HostedSMS;
const NotificationProvider = require("./notification-provider");
const axios = require("axios");
const { getMonitorRelativeURL, UP, DOWN } = require("../../src/util");
streamthing marked this conversation as resolved.
Show resolved Hide resolved

class HostedSMS extends NotificationProvider {

name = "hostedsms";

async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
Copy link
Owner

Choose a reason for hiding this comment

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

It seems that msg is never used.

When monitorJSON and heartbeantJSON are null, msg is used for other general messages such as testing or certificate alert.

let okMsg = "Sent Successfully.";

Comment on lines +10 to +11
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
let okMsg = "Sent Successfully.";
const okMsg = "Sent Successfully.";
const url = "https://api.hostedsms.pl/SimpleApi";

try {
let config = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
let config = {
const config = {

headers: {
"Content-Type": "application/json",
}
};

let textMsg = "";
if (heartbeatJSON && heartbeatJSON.status === UP) {
textMsg = `✅ [${monitorJSON.name}] is back online`;
} else if (heartbeatJSON && heartbeatJSON.status === DOWN) {
textMsg = `🔴 [${monitorJSON.name}] went down`;
}
streamthing marked this conversation as resolved.
Show resolved Hide resolved

let data = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
let data = {
const data = {

"UserEmail": notification.hostedsmsUsername,
"Password": notification.hostedsmsPassword,
"Phone": notification.hostedsmsPhoneNumber,
"Message": textMsg,
"Sender": notification.hostedsmsSenderName,
};

let resp = await axios.post("https://api.hostedsms.pl/SimpleApi", data, config);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
let resp = await axios.post("https://api.hostedsms.pl/SimpleApi", data, config);
let resp = await axios.post(url, data, config);


if (!resp.data.MessageId) {
if (resp.data.ErrorMessage) {
let error = `HostedSMS.pl API returned error message: ${resp.data.ErrorMessage}`;
this.throwGeneralAxiosError(error);
} else {
let error = "HostedSMS.pl API returned an unexpected response";
this.throwGeneralAxiosError(error);
}
streamthing marked this conversation as resolved.
Show resolved Hide resolved
}

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

module.exports = HostedSMS;
56 changes: 28 additions & 28 deletions src/components/notifications/HostedSMS.vue
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
<template>
<div class="mb-3">
<label for="hostedsms-username" class="form-label">{{ $t('hostedsmsAPIUser') }}</label>
<input id="hostedsms-username" v-model="$parent.notification.hostedsmsUsername" type="text" class="form-control" required>
</div>
<div class="mb-3">
<label for="hostedsms-key" class="form-label">{{ $t('hostedsmsAPIPassword') }}</label>
<HiddenInput id="hostedsms-key" v-model="$parent.notification.hostedsmsPassword" :required="true" autocomplete="new-password"></HiddenInput>
</div>
<div class="mb-3">
<label for="hostedsms-phone-number" class="form-label">{{ $t("hostedsmsPhoneNumber") }}</label>
<input id="hostedsms-phone-number" v-model="$parent.notification.hostedsmsPhoneNumber" type="text" class="form-control" required>
</div>
<div class="mb-3">
<label for="hostedsms-sender-name" class="form-label">{{ $t("hostedsmsSenderName") }}</label>
<input id="hostedsms-sender-name" v-model="$parent.notification.hostedsmsSenderName" type="text" minlength="3" maxlength="11" class="form-control">
</div>
</template>
<script>
import HiddenInput from "../HiddenInput.vue";
export default {
components: {
HiddenInput,
},
};
</script>
<template>
<div class="mb-3">
<label for="hostedsms-username" class="form-label">{{ $t('hostedsmsAPIUser') }}</label>
<input id="hostedsms-username" v-model="$parent.notification.hostedsmsUsername" type="text" class="form-control" required>
</div>
<div class="mb-3">
<label for="hostedsms-key" class="form-label">{{ $t('hostedsmsAPIPassword') }}</label>
<HiddenInput id="hostedsms-key" v-model="$parent.notification.hostedsmsPassword" :required="true" autocomplete="new-password"></HiddenInput>
streamthing marked this conversation as resolved.
Show resolved Hide resolved
</div>
<div class="mb-3">
<label for="hostedsms-phone-number" class="form-label">{{ $t("hostedsmsPhoneNumber") }}</label>
<input id="hostedsms-phone-number" v-model="$parent.notification.hostedsmsPhoneNumber" type="text" class="form-control" required>
streamthing marked this conversation as resolved.
Show resolved Hide resolved
</div>
<div class="mb-3">
<label for="hostedsms-sender-name" class="form-label">{{ $t("hostedsmsSenderName") }}</label>
<input id="hostedsms-sender-name" v-model="$parent.notification.hostedsmsSenderName" type="text" minlength="3" maxlength="11" class="form-control">
streamthing marked this conversation as resolved.
Show resolved Hide resolved
</div>
</template>

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

export default {
components: {
HiddenInput,
},
};
</script>