mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-05-31 02:42:34 +02:00
Add Apiv1 http for backwards compatibility
This commit is contained in:
parent
19cbf18a99
commit
e67cce70b9
2 changed files with 186 additions and 114 deletions
|
@ -11,90 +11,131 @@ class SMSEagle extends NotificationProvider {
|
|||
const okMsg = "Sent Successfully.";
|
||||
|
||||
try {
|
||||
let config = {
|
||||
headers: {
|
||||
"access-token": notification.smseagleToken,
|
||||
"Content-Type": "application/json",
|
||||
if (notification.smseagleApiType === "smseagle-apiv1") {
|
||||
let config = {
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
}
|
||||
};
|
||||
|
||||
let sendMethod;
|
||||
let recipientType;
|
||||
|
||||
if (notification.smseagleRecipientType === "smseagle-contact") {
|
||||
recipientType = "contactname";
|
||||
sendMethod = "/send_tocontact";
|
||||
}
|
||||
};
|
||||
|
||||
let encoding = (notification.smseagleEncoding) ? "unicode" : "standard";
|
||||
let priority = (notification.smseaglePriority) ? notification.smseaglePriority : 0;
|
||||
|
||||
let postData = {
|
||||
text: msg,
|
||||
encoding: encoding,
|
||||
priority: priority
|
||||
};
|
||||
|
||||
let to = notification.smseagleRecipientTo;
|
||||
let contacts = notification.smseagleRecipientContact;
|
||||
let groups = notification.smseagleRecipientGroup;
|
||||
|
||||
if (contacts) {
|
||||
contacts = contacts.split(",");
|
||||
contacts = contacts.map(e => {
|
||||
return Number(e)
|
||||
});
|
||||
postData["contacts"] = contacts;
|
||||
}
|
||||
|
||||
if (groups) {
|
||||
groups = groups.split(",");
|
||||
groups = groups.map(e => {
|
||||
return Number(e)
|
||||
});
|
||||
postData["groups"] = groups;
|
||||
}
|
||||
|
||||
if (to) {
|
||||
to = to.split(",");
|
||||
postData["to"] = to;
|
||||
}
|
||||
|
||||
let endpoint = "/messages/sms";
|
||||
|
||||
if (notification.smseagleMsgType != "smseagle-sms") {
|
||||
|
||||
let duration;
|
||||
if (notification.smseagleDuration)
|
||||
duration = notification.smseagleDuration
|
||||
else
|
||||
duration = 10;
|
||||
|
||||
postData["duration"] = duration;
|
||||
|
||||
if (notification.smseagleMsgType == "smseagle-ring") {
|
||||
endpoint = "/calls/ring";
|
||||
} else if (notification.smseagleMsgType == "smseagle-tts") {
|
||||
endpoint = "/calls/tts";
|
||||
} else if (notification.smseagleMsgType == "smseagle-tts-advanced") {
|
||||
endpoint = "/calls/tts_advanced";
|
||||
postData["voice_id"] = notification.smseagleTtsModel;
|
||||
if (notification.smseagleRecipientType === "smseagle-group") {
|
||||
recipientType = "groupname";
|
||||
sendMethod = "/send_togroup";
|
||||
}
|
||||
}
|
||||
|
||||
let resp = await axios.post(notification.smseagleUrl + "/api/v2" + endpoint, postData, config);
|
||||
|
||||
let countAll = resp.data.length;
|
||||
let countQueued = resp.data.filter(x => x.status == "queued").length;
|
||||
|
||||
if (resp.status !== 200 || countQueued == 0) {
|
||||
let error = "";
|
||||
if (resp.data.length > 0) {
|
||||
error = `SMSEagle API returned error: ${JSON.stringify(resp.data)}`;
|
||||
} else {
|
||||
error = "SMSEagle API returned an unexpected response";
|
||||
if (notification.smseagleRecipientType === "smseagle-to") {
|
||||
recipientType = "to";
|
||||
sendMethod = "/send_sms";
|
||||
}
|
||||
throw new Error(error);
|
||||
}
|
||||
|
||||
if (countAll !== countQueued) {
|
||||
let okWithErrorsMsg = "Sent " + countQueued + "/" + countAll + " Messages Successfully.";
|
||||
return okWithErrorsMsg;
|
||||
}
|
||||
const url = new URL(notification.smseagleUrl + "/http_api" + sendMethod);
|
||||
|
||||
return okMsg;
|
||||
url.searchParams.append('access_token', notification.smseagleToken);
|
||||
url.searchParams.append(recipientType, notification.smseagleRecipient);
|
||||
url.searchParams.append('message', msg);
|
||||
url.searchParams.append('unicode', (notification.smseagleEncoding) ? "1" : "0");
|
||||
url.searchParams.append('highpriority', (notification.smseaglePriority) ? notification.smseaglePriority : "0");
|
||||
|
||||
let resp = await axios.get(url.toString(), config);
|
||||
|
||||
if (resp.data.indexOf("OK") === -1) {
|
||||
let error = `SMSEagle API returned error: ${resp.data}`;
|
||||
throw new Error(error);
|
||||
}
|
||||
|
||||
return okMsg;
|
||||
} else if (notification.smseagleApiType === "smseagle-apiv2") {
|
||||
let config = {
|
||||
headers: {
|
||||
"access-token": notification.smseagleToken,
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
};
|
||||
|
||||
let encoding = (notification.smseagleEncoding) ? "unicode" : "standard";
|
||||
let priority = (notification.smseaglePriority) ? notification.smseaglePriority : 0;
|
||||
|
||||
let postData = {
|
||||
text: msg,
|
||||
encoding: encoding,
|
||||
priority: priority
|
||||
};
|
||||
|
||||
let to = notification.smseagleRecipientTo;
|
||||
let contacts = notification.smseagleRecipientContact;
|
||||
let groups = notification.smseagleRecipientGroup;
|
||||
|
||||
if (contacts) {
|
||||
contacts = contacts.split(",");
|
||||
contacts = contacts.map(e => {
|
||||
return Number(e)
|
||||
});
|
||||
postData["contacts"] = contacts;
|
||||
}
|
||||
|
||||
if (groups) {
|
||||
groups = groups.split(",");
|
||||
groups = groups.map(e => {
|
||||
return Number(e)
|
||||
});
|
||||
postData["groups"] = groups;
|
||||
}
|
||||
|
||||
if (to) {
|
||||
to = to.split(",");
|
||||
postData["to"] = to;
|
||||
}
|
||||
|
||||
let endpoint = "/messages/sms";
|
||||
|
||||
if (notification.smseagleMsgType != "smseagle-sms") {
|
||||
|
||||
let duration;
|
||||
if (notification.smseagleDuration)
|
||||
duration = notification.smseagleDuration
|
||||
else
|
||||
duration = 10;
|
||||
|
||||
postData["duration"] = duration;
|
||||
|
||||
if (notification.smseagleMsgType == "smseagle-ring") {
|
||||
endpoint = "/calls/ring";
|
||||
} else if (notification.smseagleMsgType == "smseagle-tts") {
|
||||
endpoint = "/calls/tts";
|
||||
} else if (notification.smseagleMsgType == "smseagle-tts-advanced") {
|
||||
endpoint = "/calls/tts_advanced";
|
||||
postData["voice_id"] = notification.smseagleTtsModel;
|
||||
}
|
||||
}
|
||||
|
||||
let resp = await axios.post(notification.smseagleUrl + "/api/v2" + endpoint, postData, config);
|
||||
|
||||
let countAll = resp.data.length;
|
||||
let countQueued = resp.data.filter(x => x.status == "queued").length;
|
||||
|
||||
if (resp.status !== 200 || countQueued == 0) {
|
||||
let error = "";
|
||||
if (resp.data.length > 0) {
|
||||
error = `SMSEagle API returned error: ${JSON.stringify(resp.data)}`;
|
||||
} else {
|
||||
error = "SMSEagle API returned an unexpected response";
|
||||
}
|
||||
throw new Error(error);
|
||||
}
|
||||
|
||||
if (countAll !== countQueued) {
|
||||
let okWithErrorsMsg = "Sent " + countQueued + "/" + countAll + " Messages Successfully.";
|
||||
return okWithErrorsMsg;
|
||||
}
|
||||
|
||||
return okMsg;
|
||||
}
|
||||
} catch (error) {
|
||||
this.throwGeneralAxiosError(error);
|
||||
}
|
||||
|
|
|
@ -8,44 +8,75 @@
|
|||
<HiddenInput id="smseagle-token" v-model="$parent.notification.smseagleToken" :required="true"></HiddenInput>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="smseagle-recipient-type" class="form-label">{{ $t("smseagleRecipient") }}</label>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="smseagle-recipient" class="form-label">{{ $t("smseagleTo") }}</label>
|
||||
<input id="smseagle-recipient" v-model="$parent.notification.smseagleRecipientTo" type="text" class="form-control">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="smseagle-recipient" class="form-label">{{ $t("smseagleGroup") }}</label>
|
||||
<input id="smseagle-recipient" v-model="$parent.notification.smseagleRecipientGroup" type="text" class="form-control">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="smseagle-recipient" class="form-label">{{ $t("smseagleContact") }}</label>
|
||||
<input id="smseagle-recipient" v-model="$parent.notification.smseagleRecipientContact" type="text" class="form-control">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="smseagle-priority" class="form-label">{{ $t("smseaglePriority") }}</label>
|
||||
<input id="smseagle-priority" v-model="$parent.notification.smseaglePriority" type="number" class="form-control" min="0" max="9" step="1" placeholder="0">
|
||||
</div>
|
||||
<div class="mb-3 form-check form-switch">
|
||||
<label for="smseagle-encoding" class="form-label">{{ $t("smseagleEncoding") }}</label>
|
||||
<input id="smseagle-encoding" v-model="$parent.notification.smseagleEncoding" type="checkbox" class="form-check-input">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="smseagle-msg-type" class="form-label">{{ $t("smseagleMsgType") }} </label>
|
||||
<select id="smseagle-msg-type" v-model="$parent.notification.smseagleMsgType" class="form-select">
|
||||
<option value="smseagle-sms" selected>{{ $t("smseagleMsgSms") }} </option>
|
||||
<option value="smseagle-ring">{{ $t("smseagleMsgRing") }} </option>
|
||||
<option value="smseagle-tts">{{ $t("smseagleMsgTts") }} </option>
|
||||
<option value="smseagle-tts-advanced">{{ $t("smseagleMsgTtsAdvanced") }} </option>
|
||||
<label for="smseagle-api-type" class="form-label">{{ $t("smseagleApiType") }} </label>
|
||||
<select id="smseagle-api-type" v-model="$parent.notification.smseagleApiType" class="form-select">
|
||||
<option value="smseagle-apiv1" selected>{{ $t("smseagleApiv1") }} </option>
|
||||
<option value="smseagle-apiv2">{{ $t("smseagleApiv2") }} </option>
|
||||
</select>
|
||||
</div>
|
||||
<div v-if="$parent.notification.smseagleMsgType !== 'smseagle-sms' && $parent.notification.smseagleMsgType" class="mb-3">
|
||||
<label for="smseagle-duration" class="form-label">{{ $t("smseagleDuration") }}</label>
|
||||
<input id="smseagle-duration" v-model="$parent.notification.smseagleDuration" type="number" class="form-control" min="0" max="30" step="1" placeholder="10">
|
||||
<div v-if="$parent.notification.smseagleApiType === 'smseagle-apiv1'" class="mb-3">
|
||||
<div class="mb-3">
|
||||
<label for="smseagle-recipient-type" class="form-label">{{ $t("smseagleRecipientType") }}</label>
|
||||
<select id="smseagle-recipient-type" v-model="$parent.notification.smseagleRecipientType" class="form-select">
|
||||
<option value="smseagle-to" selected>{{ $t("smseagleTo") }}</option>
|
||||
<option value="smseagle-group">{{ $t("smseagleGroup") }}</option>
|
||||
<option value="smseagle-contact">{{ $t("smseagleContact") }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="smseagle-recipient" class="form-label">{{ $t("smseagleRecipient") }}</label>
|
||||
<input id="smseagle-recipient" v-model="$parent.notification.smseagleRecipient" type="text" class="form-control" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="smseagle-priority" class="form-label">{{ $t("smseaglePriority") }}</label>
|
||||
<input id="smseagle-priority" v-model="$parent.notification.smseaglePriority" type="number" class="form-control" min="0" max="9" step="1" placeholder="0">
|
||||
</div>
|
||||
<div class="mb-3 form-check form-switch">
|
||||
<label for="smseagle-encoding" class="form-label">{{ $t("smseagleEncoding") }}</label>
|
||||
<input id="smseagle-encoding" v-model="$parent.notification.smseagleEncoding" type="checkbox" class="form-check-input">
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="$parent.notification.smseagleMsgType === 'smseagle-tts-advanced'" class="mb-3">
|
||||
<label for="smseagle-tts-model" class="form-label">{{ $t("smseagleTtsModel") }} </label>
|
||||
<input id="smseagle-tts-model" v-model="$parent.notification.smseagleTtsModel" type="number" class="form-control" required>
|
||||
<div v-if="$parent.notification.smseagleApiType === 'smseagle-apiv2'" class="mb-3">
|
||||
<div class="mb-3">
|
||||
<label for="smseagle-recipient-type" class="form-label">{{ $t("smseagleRecipient") }}</label>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="smseagle-recipient" class="form-label">{{ $t("smseagleTo") }}</label>
|
||||
<input id="smseagle-recipient" v-model="$parent.notification.smseagleRecipientTo" type="text" class="form-control">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="smseagle-recipient" class="form-label">{{ $t("smseagleGroup") }}</label>
|
||||
<input id="smseagle-recipient" v-model="$parent.notification.smseagleRecipientGroup" type="text" class="form-control">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="smseagle-recipient" class="form-label">{{ $t("smseagleContact") }}</label>
|
||||
<input id="smseagle-recipient" v-model="$parent.notification.smseagleRecipientContact" type="text" class="form-control">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="smseagle-priority" class="form-label">{{ $t("smseaglePriority") }}</label>
|
||||
<input id="smseagle-priority" v-model="$parent.notification.smseaglePriority" type="number" class="form-control" min="0" max="9" step="1" placeholder="0">
|
||||
</div>
|
||||
<div class="mb-3 form-check form-switch">
|
||||
<label for="smseagle-encoding" class="form-label">{{ $t("smseagleEncoding") }}</label>
|
||||
<input id="smseagle-encoding" v-model="$parent.notification.smseagleEncoding" type="checkbox" class="form-check-input">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="smseagle-msg-type" class="form-label">{{ $t("smseagleMsgType") }} </label>
|
||||
<select id="smseagle-msg-type" v-model="$parent.notification.smseagleMsgType" class="form-select">
|
||||
<option value="smseagle-sms" selected>{{ $t("smseagleMsgSms") }} </option>
|
||||
<option value="smseagle-ring">{{ $t("smseagleMsgRing") }} </option>
|
||||
<option value="smseagle-tts">{{ $t("smseagleMsgTts") }} </option>
|
||||
<option value="smseagle-tts-advanced">{{ $t("smseagleMsgTtsAdvanced") }} </option>
|
||||
</select>
|
||||
</div>
|
||||
<div v-if="$parent.notification.smseagleMsgType && $parent.notification.smseagleMsgType !== 'smseagle-sms'" class="mb-3">
|
||||
<label for="smseagle-duration" class="form-label">{{ $t("smseagleDuration") }}</label>
|
||||
<input id="smseagle-duration" v-model="$parent.notification.smseagleDuration" type="number" class="form-control" min="0" max="30" step="1" placeholder="10">
|
||||
</div>
|
||||
<div v-if="$parent.notification.smseagleMsgType === 'smseagle-tts-advanced'" class="mb-3">
|
||||
<label for="smseagle-tts-model" class="form-label">{{ $t("smseagleTtsModel") }} </label>
|
||||
<input id="smseagle-tts-model" v-model="$parent.notification.smseagleTtsModel" type="number" class="form-control" required>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue