-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 { | ||||||
|
||||||
name = "ceredsms"; | ||||||
|
||||||
/** | ||||||
* @inheritdoc | ||||||
*/ | ||||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { | ||||||
let okMsg = "Sent Successfully."; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit, was changed for all others
Suggested change
|
||||||
|
||||||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are first checking if message exists and then using error.messsage |
||||||
this.throwGeneralAxiosError(error); | ||||||
} else { | ||||||
let error = "CeredSMS.pl API returned an unexpected response"; | ||||||
this.throwGeneralAxiosError(error); | ||||||
Comment on lines
+31
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Throwing inside the catch does not work as you think it does. |
||||||
} | ||||||
} | ||||||
|
||||||
return okMsg; | ||||||
} catch (error) { | ||||||
this.throwGeneralAxiosError(error); | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
module.exports = CeredSMS; |
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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
There was a problem hiding this comment.
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