mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-03-15 04:30:29 +03: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 { DOWN } = require("../../src/util");
|
||||
const NotifyClient = require("notifications-node-client").NotifyClient;
|
||||
|
||||
class GovNotify extends NotificationProvider {
|
||||
|
@ -13,19 +14,38 @@ class GovNotify extends NotificationProvider {
|
|||
const smsRecipients = (typeof notification.smsRecipients === "string" && notification.smsRecipients.trim())
|
||||
? 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 smsTemplateID = notification.smsTemplateId;
|
||||
|
||||
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
|
||||
for (const email of emailRecipients) {
|
||||
await notifyClient.sendEmail(
|
||||
emailTemplateID,
|
||||
email,
|
||||
{
|
||||
personalisation: { message },
|
||||
personalisation: {
|
||||
message,
|
||||
subject,
|
||||
},
|
||||
reference: "Uptime-Kuma"
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,11 +1,25 @@
|
|||
<template>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">GOV Notify API Key</label>
|
||||
<input
|
||||
v-model="$parent.notification.apiKey"
|
||||
type="text"
|
||||
class="form-control"
|
||||
/>
|
||||
<div class="input-group">
|
||||
<input
|
||||
v-if="!showApiKey"
|
||||
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 class="mb-3">
|
||||
<label class="form-label">Email Recipients (comma-separated)</label>
|
||||
|
@ -43,5 +57,19 @@
|
|||
</template>
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
showApiKey: false,
|
||||
newApiKey: "",
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
toggleApiKey() {
|
||||
if (this.showApiKey) {
|
||||
this.newApiKey = "";
|
||||
}
|
||||
this.showApiKey = !this.showApiKey;
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
|
Loading…
Add table
Reference in a new issue