uptime-kuma/server/notification-providers/resend.js
Frank Elsinga 0f61d7ee1b
chore: enable formatting over the entire codebase in CI (#6655)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-01-09 02:10:36 +01:00

45 lines
1.4 KiB
JavaScript

const NotificationProvider = require("./notification-provider");
const axios = require("axios");
class Resend extends NotificationProvider {
name = "Resend";
/**
* @inheritdoc
*/
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
const okMsg = "Sent Successfully.";
try {
let config = {
headers: {
Authorization: `Bearer ${notification.resendApiKey}`,
"Content-Type": "application/json",
},
};
config = this.getAxiosConfigWithProxy(config);
const email = notification.resendFromEmail.trim();
const fromName = notification.resendFromName?.trim() || "Uptime Kuma";
let data = {
from: `${fromName} <${email}>`,
to: notification.resendToEmail,
subject: notification.resendSubject || "Notification from Your Uptime Kuma",
// supplied text directly instead of html
text: msg,
};
let result = await axios.post("https://api.resend.com/emails", data, config);
if (result.status === 200) {
return okMsg;
} else {
throw new Error(`Unexpected status code: ${result.status}`);
}
} catch (error) {
this.throwGeneralAxiosError(error);
}
}
}
module.exports = Resend;