Modified discord notification provider

- Added support for thread channels
- Added support for forum channels
pull/4099/head
TheDanniCraft 12 months ago
parent 67250d6302
commit f117342deb

@ -14,6 +14,9 @@ class Discord extends NotificationProvider {
try {
const discordDisplayName = notification.discordUsername || "Uptime Kuma";
var threadQuery = "";
if (notification.discordChannelType == "postToThread") threadQuery = "?thread_id=" + notification.threadId;
// If heartbeatJSON is null, assume we're testing.
if (heartbeatJSON == null) {
@ -21,7 +24,10 @@ class Discord extends NotificationProvider {
username: discordDisplayName,
content: msg,
};
await axios.post(notification.discordWebhookUrl, discordtestdata);
if (notification.discordChannelType == "createNewForumPost") discordtestdata.thread_name = notification.postName;
await axios.post(notification.discordWebhookUrl + threadQuery, discordtestdata);
return okMsg;
}
@ -47,6 +53,11 @@ class Discord extends NotificationProvider {
// If heartbeatJSON is not null, we go into the normal alerting loop.
if (heartbeatJSON["status"] === DOWN) {
const discordDisplayName = notification.discordUsername || "Uptime Kuma";
var threadQuery = "";
if (notification.discordChannelType == "postToThread") threadQuery = "?thread_id=" + notification.threadId;
let discorddowndata = {
username: discordDisplayName,
embeds: [{
@ -73,7 +84,7 @@ class Discord extends NotificationProvider {
],
}],
};
if (notification.discordChannelType == "createNewForumPost") discorddowndata.thread_name = notification.postName;
if (notification.discordPrefixMessage) {
discorddowndata.content = notification.discordPrefixMessage;
}
@ -109,11 +120,13 @@ class Discord extends NotificationProvider {
}],
};
if (notification.discordChannelType == "createNewForumPost") discordupdata.thread_name = notification.postName;
if (notification.discordPrefixMessage) {
discordupdata.content = notification.discordPrefixMessage;
}
await axios.post(notification.discordWebhookUrl, discordupdata);
await axios.post(notification.discordWebhookUrl + threadQuery, discordupdata);
return okMsg;
}
} catch (error) {

@ -16,4 +16,34 @@
<label for="discord-prefix-message" class="form-label">{{ $t("Prefix Custom Message") }}</label>
<input id="discord-prefix-message" v-model="$parent.notification.discordPrefixMessage" type="text" class="form-control" autocomplete="false" :placeholder="$t('Hello @everyone is...')">
</div>
<div class="mb-3">
<label for="discord-message-type" class="form-label">{{ $t("Select message type") }}</label>
<br>
<select id="discord-message-type" class="form-select" v-model="$parent.notification.discordChannelType">
<option value="normal">{{ $t("Normal Message") }}</option>
<option value="createNewForumPost">{{ $t("Create new forum post") }}</option>
<option value="postToThread">{{ $t("Post to existing thread") }}</option>
</select>
</div>
<div v-if="$parent.notification.discordChannelType === 'createNewForumPost'">
<div class="mb-3">
<label for="discord-target" class="form-label">{{ $t("Forum post name") }}</label>
<input id="discord-target" v-model="$parent.notification.postName" type="text" class="form-control" autocomplete="false" :placeholder="$t('Status Changed')">
</div>
</div>
<div v-if="$parent.notification.discordChannelType === 'postToThread'">
<div class="mb-3">
<label for="discord-target" class="form-label">{{ $t("Thread ID") }}</label>
<input id="discord-target" v-model="$parent.notification.threadId" type="text" class="form-control" autocomplete="false" :placeholder="$t('Thread ID (e.g. 1177566663751782411)')">
</div>
</div>
</template>
<script>
export default {
mounted(){
this.$parent.notification.discordChannelType = "normal";
}
}
</script>
Loading…
Cancel
Save