Notification provider testing now working

pull/4558/head
Simon Nilsson 9 months ago
parent 21bbf3e1da
commit cbda7c6379

@ -1,9 +1,12 @@
const NotificationProvider = require("./notification-provider");
const axios = require("axios");
const { DOWN, UP } = require("../../src/util");
const { default: axios } = require("axios");
const Crypto = require("crypto");
const qs = require("qs");
class CellsyntMobileServices extends NotificationProvider {
name = "cellsyntmobileservices";
name = "CellsyntMobileServices";
/**
* @inheritdoc
@ -12,34 +15,16 @@ class CellsyntMobileServices extends NotificationProvider {
let okMsg = "Sent Successfully.";
try {
let config = {
headers: {
"Content-Type": "application/json",
"Authorization": "Basic " + Buffer.from(notification.clicksendsmsLogin + ":" + notification.clicksendsmsPassword).toString("base64"),
"Accept": "text/json",
}
};
let data = {
/* messages: [
{
"body": msg.replace(/[^\x00-\x7F]/g, ""),
"to": notification.clicksendsmsToNumber,
"source": "uptime-kuma",
"from": notification.clicksendsmsSenderName,
}
]*/
messages: [
{
//"from": notification.clicksendsmsSenderName,
params: {
/* Your username (received when account is setup).
*/
"username": "abc123",
"username": notification.cellsyntLogin,
/* Your password to use together with the username for
authentication (received when account is setup).
*/
"password": "abc123",
"password": notification.cellsyntPassword,
/* Recipient's telephone number on international format with
leading 00 followed by country code, e.g. 00447920110000 for
@ -47,7 +32,7 @@ class CellsyntMobileServices extends NotificationProvider {
To send the same message to multiple recipients, separate
numbers with comma. Max 25000 recipients per HTTP request.
*/
"destination": "0046738387444",
"destination": notification.cellsyntDestination,
"text": msg.replace(/[^\x00-\x7F]/g, ""),
/* Character set text and other data is sent as in the HTTP
@ -58,7 +43,7 @@ class CellsyntMobileServices extends NotificationProvider {
/* Controls the originator type the message should be sent with.
Possible values: numeric, shortcode and alpha.
*/
"originatortype": "alpha",
"originatortype": notification.Originatortype,
/* Identifier which will be visible on recipient's mobile phone as
originator of the message. Allowed values and function depends
@ -83,7 +68,7 @@ class CellsyntMobileServices extends NotificationProvider {
originators
*/
//"originator": "uptime-kuma",
"originator": notification.clicksendsmsSenderName,
"originator": notification.cellsyntOriginator,
/* Type of message that should be sent. Possible values: text
(default), binary and unicode */
"type": "text",
@ -92,7 +77,7 @@ class CellsyntMobileServices extends NotificationProvider {
needed (default value is 1, see Long SMS). Maximum value is 6
(i.e. max 153 x 6 = 918 characters).
*/
"allowconcat": 1,
"allowconcat": notification.cellsyntAllowLongSMS?6:1,
/* Can be used if you want to prevent a message from being
delivered after a certain time, e.g. 9 PM the same evening if
@ -137,12 +122,26 @@ class CellsyntMobileServices extends NotificationProvider {
*/
//"pid": "",
}
]
};
let resp = await axios.post("https://se-1.cellsynt.net/sms.php", data, config);
console.log(resp);
if (resp.data.data.messages[0].status !== "SUCCESS") {
let error = "Something gone wrong. Api returned " + resp.data.data.messages[0].status + ".";
try {
if (heartbeatJSON != null) {
var d = new Date(heartbeatJSON["time"]),
dformat = [d.getMonth()+1,
d.getDate(),
d.getFullYear()].join('/')+' '+
[d.getHours(),
d.getMinutes()].join(':');
msg = dformat+" - "+msg;
data.params.text = msg.replace(/[^\x00-\x7F]/g, "");
}
let resp = await axios.post("https://se-1.cellsynt.net/sms.php", null, data);
if(typeof resp.data == undefined || resp.data == null || resp.data.includes("Error")) {
this.throwGeneralAxiosError(resp.data);
}else{
}
}catch (error) {
this.throwGeneralAxiosError(error);
}

@ -1,34 +1,60 @@
<template>
<div class="mb-3">
<label for="promosms-login" class="form-label">{{ $t("promosmsLogin") }}</label>
<input id="promosms-login" v-model="$parent.notification.promosmsLogin" type="text" class="form-control" required>
<label for="promosms-key" class="form-label">{{ $t("promosmsPassword") }}</label>
<HiddenInput id="promosms-key" v-model="$parent.notification.promosmsPassword" :required="true" autocomplete="new-password"></HiddenInput>
<label for="cellsynt-login" class="form-label">{{ $t("Username") }}</label>
<input id="cellsynt-login" v-model="$parent.notification.cellsyntLogin" type="text" class="form-control" required>
</div>
<div class="mb-3">
<label for="promosms-type-sms" class="form-label">{{ $t("SMS Type") }}</label>
<select id="promosms-type-sms" v-model="$parent.notification.promosmsSMSType" class="form-select">
<option value="0">{{ $t("promosmsTypeFlash") }}</option>
<option value="1">{{ $t("promosmsTypeEco") }}</option>
<option value="3">{{ $t("promosmsTypeFull") }}</option>
<option value="4">{{ $t("promosmsTypeSpeed") }}</option>
<label for="cellsynt-key" class="form-label">{{ $t("Password") }}</label>
<HiddenInput id="cellsynt-key" v-model="$parent.notification.cellsyntPassword" :required="true" autocomplete="new-password"></HiddenInput>
</div>
<div class="mb-3">
<label for="cellsynt-Originatortype" class="form-label">{{ $t("Originator type") }}</label>
<select id="cellsynt-Originatortype" v-model="$parent.notification.cellsyntOriginatortype" :required="true" class="form-select">
<option value="numeric" :selected="true">{{ $t("Numeric") }}</option>
<option value="shortcode">{{ $t("Shortcode") }}</option>
<option value="alpha">{{ $t("Alpha") }}</option>
</select>
<div class="form-text">
{{ $t("checkPrice", [$t("promosms")]) }}
<a href="https://promosms.com/cennik/" target="_blank">https://promosms.com/cennik/</a>
<p><b>numeric:</b><br>
Numeric value (max 15 digits) with telephone number on
international format without leading 00 (example UK number
07920 110 000 should be set as 447920110000). Receiving
mobile phone will add a leading + sign and thus see the
originator as a normal mobile phone number (+447920110000).
Therefore it is also possible to reply to the message.</p>
<p><b>shortcode:</b><br>
Numerical value (max 15 digits). Used to set a shortcode in an
operator network as originator (i.e. will be shown without leading
+ sign, e.g. 72456).</p>
<p><b>alpha:</b><br>
Alphanumeric string (max 11 characters). The following
characters are guaranteed to work: a-z, A-Z and 0-9. Other
characters may work but functionality can not be guaranteed.
Recipients can not reply to messages with alphanumeric
originators.</p>
</div>
</div>
<div class="mb-3">
<label for="promosms-phone-number" class="form-label">{{ $t("promosmsPhoneNumber") }}</label>
<input id="promosms-phone-number" v-model="$parent.notification.promosmsPhoneNumber" type="text" class="form-control" required>
<label for="cellsynt-originator" class="form-label">{{ $t("Originator") }}</label>
<input id="cellsynt-originator" v-model="$parent.notification.cellsyntOriginator" type="text" class="form-control" required>
<div class="form-text"><p>Identifier which will be visible on recipient's mobile phone as
originator of the message. Allowed values and function depends
on parameter originatortype</p></div>
</div>
<div class="mb-3">
<label for="promosms-sender-name" class="form-label">{{ $t("promosmsSMSSender") }}</label>
<input id="promosms-sender-name" v-model="$parent.notification.promosmsSenderName" type="text" minlength="3" maxlength="11" class="form-control">
<label for="cellsynt-destination" class="form-label">{{ $t("Destination") }}</label>
<input id="cellsynt-destination" v-model="$parent.notification.cellsyntDestination" type="text" class="form-control" required>
<div class="form-text"><p>Recipient's telephone number on international format with
leading 00 followed by country code, e.g. 00447920110000 for
UK number 07920 110 000 (max 17 digits in total).
To send the same message to multiple recipients, separate
numbers with comma. Max 25000 recipients per HTTP request.</p></div>
</div>
<div class="form-check form-switch">
<input id="promosms-allow-long" v-model="$parent.notification.promosmsAllowLongSMS" type="checkbox" class="form-check-input">
<label for="promosms-allow-long" class="form-label">{{ $t("promosmsAllowLongSMS") }}</label>
<input id="cellsynt-allow-long" v-model="$parent.notification.cellsyntAllowLongSMS" type="checkbox" class="form-check-input">
<label for="cellsynt-allow-long" class="form-label">{{ $t("Allow Long SMS") }}</label>
<div class="form-text">Long SMS (also known as "concatenated SMS") enables sending messages exceeding 160
characters.</div>
</div>
</template>

Loading…
Cancel
Save