Skip to content

Commit

Permalink
✨ Add Misskey notifier
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary authored Oct 15, 2022
2 parents 9a0e0b6 + 1081ac1 commit 1ce3727
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion src/helpers/notifme.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
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";
import { getSecret } from "./secrets";

const channels: {
email?: Channel<EmailProvider>;
misskey?: Channel<MisskeyProvider>;
sms?: Channel<SmsProvider>;
slack?: Channel<SlackProvider>;
} = {};
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 1ce3727

Please sign in to comment.