mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-06-03 12:02:33 +02:00
Refactor GovNotify to enhance API key handling and messaging.
Introduced a toggle in the UI to securely display or edit the GOV Notify API key. Updated the backend to include dynamic subject lines and timestamps in notifications to improve clarity and contextual information for recipients. Signed-off-by: Toby Liddicoat <toby@codesure.co.uk>
This commit is contained in:
parent
9615e46568
commit
200f179b5f
2 changed files with 55 additions and 7 deletions
|
@ -1,4 +1,5 @@
|
||||||
const NotificationProvider = require("./notification-provider");
|
const NotificationProvider = require("./notification-provider");
|
||||||
|
const { DOWN } = require("../../src/util");
|
||||||
const NotifyClient = require("notifications-node-client").NotifyClient;
|
const NotifyClient = require("notifications-node-client").NotifyClient;
|
||||||
|
|
||||||
class GovNotify extends NotificationProvider {
|
class GovNotify extends NotificationProvider {
|
||||||
|
@ -13,19 +14,38 @@ class GovNotify extends NotificationProvider {
|
||||||
const smsRecipients = (typeof notification.smsRecipients === "string" && notification.smsRecipients.trim())
|
const smsRecipients = (typeof notification.smsRecipients === "string" && notification.smsRecipients.trim())
|
||||||
? notification.smsRecipients.split(",").map(n => n.trim()).filter(n => n)
|
? notification.smsRecipients.split(",").map(n => n.trim()).filter(n => n)
|
||||||
: [];
|
: [];
|
||||||
const message = notification.messageTemplate || msg;
|
let message = notification.messageTemplate || msg;
|
||||||
const emailTemplateID = notification.emailTemplateId;
|
const emailTemplateID = notification.emailTemplateId;
|
||||||
const smsTemplateID = notification.smsTemplateId;
|
const smsTemplateID = notification.smsTemplateId;
|
||||||
|
|
||||||
const notifyClient = new NotifyClient(apiKey);
|
const notifyClient = new NotifyClient(apiKey);
|
||||||
|
|
||||||
|
let subject = "⚠️ Test";
|
||||||
|
|
||||||
|
if (heartbeatJSON !== null) {
|
||||||
|
subject = (heartbeatJSON["status"] === DOWN) ? "🔴 Down" : "✅ Up";
|
||||||
|
}
|
||||||
|
|
||||||
|
const date = new Date();
|
||||||
|
const day = date.getDate();
|
||||||
|
const month = date.getMonth() + 1;
|
||||||
|
const year = date.getFullYear();
|
||||||
|
const hours = date.getHours();
|
||||||
|
const minutes = date.getMinutes();
|
||||||
|
|
||||||
|
const readableDate = `GMT ${day}/${month}/${year} ${hours}:${minutes}`;
|
||||||
|
message += `\n${readableDate}`;
|
||||||
|
|
||||||
// Send Emails
|
// Send Emails
|
||||||
for (const email of emailRecipients) {
|
for (const email of emailRecipients) {
|
||||||
await notifyClient.sendEmail(
|
await notifyClient.sendEmail(
|
||||||
emailTemplateID,
|
emailTemplateID,
|
||||||
email,
|
email,
|
||||||
{
|
{
|
||||||
personalisation: { message },
|
personalisation: {
|
||||||
|
message,
|
||||||
|
subject,
|
||||||
|
},
|
||||||
reference: "Uptime-Kuma"
|
reference: "Uptime-Kuma"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,25 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">GOV Notify API Key</label>
|
<label class="form-label">GOV Notify API Key</label>
|
||||||
<input
|
<div class="input-group">
|
||||||
v-model="$parent.notification.apiKey"
|
<input
|
||||||
type="text"
|
v-if="!showApiKey"
|
||||||
class="form-control"
|
type="text"
|
||||||
/>
|
class="form-control"
|
||||||
|
value="************"
|
||||||
|
disabled
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
v-else
|
||||||
|
v-model="newApiKey"
|
||||||
|
type="text"
|
||||||
|
class="form-control"
|
||||||
|
placeholder="Enter new API key"
|
||||||
|
/>
|
||||||
|
<button class="btn btn-outline-secondary" type="button" @click="toggleApiKey">
|
||||||
|
{{ showApiKey ? "Cancel" : "Change" }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">Email Recipients (comma-separated)</label>
|
<label class="form-label">Email Recipients (comma-separated)</label>
|
||||||
|
@ -43,5 +57,19 @@
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
showApiKey: false,
|
||||||
|
newApiKey: "",
|
||||||
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
toggleApiKey() {
|
||||||
|
if (this.showApiKey) {
|
||||||
|
this.newApiKey = "";
|
||||||
|
}
|
||||||
|
this.showApiKey = !this.showApiKey;
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Add table
Reference in a new issue