diff --git a/src/helpers/notifme.ts b/src/helpers/notifme.ts index 186d36e0..57f24489 100644 --- a/src/helpers/notifme.ts +++ b/src/helpers/notifme.ts @@ -1,4 +1,4 @@ -import NotifmeSdk, { EmailProvider, SlackProvider, SmsProvider } from "notifme-sdk"; +import NotifmeSdk, { EmailProvider, MisskeyProvider, SlackProvider, SmsProvider } from "notifme-sdk"; import axios from "axios"; import type { Channel } from "notifme-sdk"; import { replaceEnvironmentVariables } from "./environment"; @@ -6,6 +6,7 @@ import { getSecret } from "./secrets"; const channels: { email?: Channel; + misskey?: Channel; sms?: Channel; slack?: Channel; } = {}; @@ -226,6 +227,50 @@ export const sendNotification = async (message: string) => { } console.log("Finished sending Discord"); } + if (getSecret("NOTIFICATION_MISSKEY") && getSecret("NOTIFICATION_MISSKEY_INSTANCEURL") && getSecret("NOTIFICATION_MISSKEY_API_KEY")) { + console.log("Sending Misskey"); + const instanceUrl = new URL(getSecret("NOTIFICATION_MISSKEY_INSTANCEURL") as string); + const baseUrl = `${instanceUrl.protocol}://${instanceUrl.hostname}/api`; + if (getSecret("NOTIFICATION_MISSKEY_CHAT") && getSecret("NOTIFICATION_MISSKEY_CHAT_USER_ID")) { + await axios.post( + `${baseUrl}/messaging/messages/create`, + { + i: getSecret("NOTIFICATION_MISSKEY_API_KEY") as string, + userId: getSecret("NOTIFICATION_MISSKEY_CHAT_USER_ID"), + text: message, + } + ); + } + if (getSecret("NOTIFICATION_MISSKEY_NOTE")) { + type MisskeyNoteVisibility = "public" | "home" | "followers" | "specified"; + let visibility: MisskeyNoteVisibility = "public"; + let visibleUserIds: string[] | undefined; + if (getSecret("NOTIFICATION_MISSKEY_NOTE_VISIBILITY")) { + try { + visibility = getSecret("NOTIFICATION_MISSKEY_NOTE_VISIBILITY") as MisskeyNoteVisibility; + } catch (e) { + console.log(`Unsupported Misskey note visibility mode: ${getSecret("NOTIFICATION_MISSKEY_NOTE_VISIBILITY")}`); + } + } + if (visibility == "specified") { + if (Array.isArray(getSecret("NOTIFICATION_MISSKEY_NOTE_VISIBLE_USER_IDS"))) { + visibleUserIds = getSecret("NOTIFICATION_MISSKEY_NOTE_VISIBLE_USER_IDS") + } else { + console.log("Error: No visible user ID list specified"); + } + } + await axios.post( + `${baseUrl}/notes/create`, + { + i: getSecret("NOTIFICATION_MISSKEY_API_KEY") as string, + visibility: visibility, + visibleUserIds: visibleUserIds, + text: message, + } + ); + } + console.log("Success Misskey"); + } if (getSecret("NOTIFICATION_TELEGRAM") && getSecret("NOTIFICATION_TELEGRAM_BOT_KEY")) { console.log("Sending Telegram"); try {