-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #963 from kffl/feat/serwersms-provider
Add SerwerSMS.pl notification provider
- Loading branch information
Showing
6 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const NotificationProvider = require("./notification-provider"); | ||
const axios = require("axios"); | ||
|
||
class SerwerSMS extends NotificationProvider { | ||
|
||
name = "serwersms"; | ||
|
||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { | ||
let okMsg = "Sent Successfully."; | ||
|
||
try { | ||
let config = { | ||
headers: { | ||
"Content-Type": "application/json", | ||
} | ||
}; | ||
let data = { | ||
"username": notification.serwersmsUsername, | ||
"password": notification.serwersmsPassword, | ||
"phone": notification.serwersmsPhoneNumber, | ||
"text": msg.replace(/[^\x00-\x7F]/g, ""), | ||
"sender": notification.serwersmsSenderName, | ||
}; | ||
|
||
let resp = await axios.post("https://api2.serwersms.pl/messages/send_sms", data, config); | ||
|
||
if (!resp.data.success) { | ||
if (resp.data.error) { | ||
let error = `SerwerSMS.pl API returned error code ${resp.data.error.code} (${resp.data.error.type}) with error message: ${resp.data.error.message}`; | ||
this.throwGeneralAxiosError(error); | ||
} else { | ||
let error = "SerwerSMS.pl API returned an unexpected response"; | ||
this.throwGeneralAxiosError(error); | ||
} | ||
} | ||
|
||
return okMsg; | ||
} catch (error) { | ||
this.throwGeneralAxiosError(error); | ||
} | ||
} | ||
} | ||
|
||
module.exports = SerwerSMS; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<template> | ||
<div class="mb-3"> | ||
<label for="serwersms-username" class="form-label">{{ $t('serwersmsAPIUser') }}</label> | ||
<input id="serwersms-username" v-model="$parent.notification.serwersmsUsername" type="text" class="form-control" required> | ||
</div> | ||
<div class="mb-3"> | ||
<label for="serwersms-key" class="form-label">{{ $t('serwersmsAPIPassword') }}</label> | ||
<HiddenInput id="serwersms-key" v-model="$parent.notification.serwersmsPassword" :required="true" autocomplete="one-time-code"></HiddenInput> | ||
</div> | ||
<div class="mb-3"> | ||
<label for="serwersms-phone-number" class="form-label">{{ $t("serwersmsPhoneNumber") }}</label> | ||
<input id="serwersms-phone-number" v-model="$parent.notification.serwersmsPhoneNumber" type="text" class="form-control" required> | ||
</div> | ||
<div class="mb-3"> | ||
<label for="serwersms-sender-name" class="form-label">{{ $t("serwersmsSenderName") }}</label> | ||
<input id="serwersms-sender-name" v-model="$parent.notification.serwersmsSenderName" type="text" minlength="3" maxlength="11" class="form-control"> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import HiddenInput from "../HiddenInput.vue"; | ||
export default { | ||
components: { | ||
HiddenInput, | ||
}, | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters