-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New notification provider: SMS Partner API (#4769)
Co-authored-by: Nicolas Verlhiac <nicolas@novariom.com> Co-authored-by: Frank Elsinga <frank@elsinga.de>
- Loading branch information
1 parent
88b7c04
commit b1e9596
Showing
6 changed files
with
95 additions
and
0 deletions.
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,46 @@ | ||
const NotificationProvider = require("./notification-provider"); | ||
const axios = require("axios"); | ||
|
||
class SMSPartner extends NotificationProvider { | ||
name = "SMSPartner"; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { | ||
const okMsg = "Sent Successfully."; | ||
const url = "https://api.smspartner.fr/v1/send"; | ||
|
||
try { | ||
// smspartner does not support non ascii characters and only a maximum 639 characters | ||
let cleanMsg = msg.replace(/[^\x00-\x7F]/g, "").substring(0, 639); | ||
|
||
let data = { | ||
"apiKey": notification.smspartnerApikey, | ||
"sender": notification.smspartnerSenderName.substring(0, 11), | ||
"phoneNumbers": notification.smspartnerPhoneNumber, | ||
"message": cleanMsg, | ||
}; | ||
|
||
let config = { | ||
headers: { | ||
"Content-Type": "application/json", | ||
"cache-control": "no-cache", | ||
"Accept": "application/json", | ||
} | ||
}; | ||
|
||
let resp = await axios.post(url, data, config); | ||
|
||
if (resp.data.success !== true) { | ||
throw Error(`Api returned ${resp.data.response.status}.`); | ||
} | ||
|
||
return okMsg; | ||
} catch (error) { | ||
this.throwGeneralAxiosError(error); | ||
} | ||
} | ||
} | ||
|
||
module.exports = SMSPartner; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<template> | ||
<div class="mb-3"> | ||
<label for="smspartner-key" class="form-label">{{ $t("API Key") }}</label> | ||
<HiddenInput id="smspartner-key" v-model="$parent.notification.smspartnerApikey" :required="true" autocomplete="new-password"></HiddenInput> | ||
<div class="form-text"> | ||
<i18n-t keypath="smspartnerApiurl" as="div" class="form-text"> | ||
<a href="https://my.smspartner.fr/dashboard/api" target="_blank">my.smspartner.fr/dashboard/api</a> | ||
</i18n-t> | ||
</div> | ||
</div> | ||
<div class="mb-3"> | ||
<label for="smspartner-phone-number" class="form-label">{{ $t("smspartnerPhoneNumber") }}</label> | ||
<input id="smspartner-phone-number" v-model="$parent.notification.smspartnerPhoneNumber" type="text" minlength="3" maxlength="20" pattern="^[\d+,]+$" class="form-control" required> | ||
<div class="form-text"> | ||
<i18n-t keypath="smspartnerPhoneNumberHelptext" as="div" class="form-text"> | ||
<code>+336xxxxxxxx</code> | ||
<code>+496xxxxxxxx</code> | ||
<code>,</code> | ||
</i18n-t> | ||
</div> | ||
</div> | ||
<div class="mb-3"> | ||
<label for="smspartner-sender-name" class="form-label">{{ $t("smspartnerSenderName") }}</label> | ||
<input id="smspartner-sender-name" v-model="$parent.notification.smspartnerSenderName" type="text" minlength="3" maxlength="11" pattern="^[a-zA-Z0-9]*$" class="form-control" required> | ||
<div class="form-text"> | ||
{{ $t("smspartnerSenderNameInfo") }} | ||
</div> | ||
</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