Skip to content

Commit

Permalink
update ntfy and telegram notifier options
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBrax committed Jan 26, 2024
1 parent 6c4ed6e commit fbe7ab4
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 12 deletions.
2 changes: 1 addition & 1 deletion server/src/Core/ClientBroker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export class ClientBroker {
NotificationProvider.NTFY
)
) {
NtfyNotify(title, body, icon, category, url);
NtfyNotify({ title, body, icon, category, url });
}

if (
Expand Down
51 changes: 45 additions & 6 deletions server/src/Core/Notifiers/Ntfy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,62 @@ import chalk from "chalk";
import { Config } from "../Config";
import { LOGLEVEL, log } from "../Log";

export default function notify(
title: string,
type Action = {
action: "view" | "http";
label: string;
url: string;
clear?: boolean;
body?: string;
};

// action=<action1>, label=<label1>, paramN=... [; action=<action2>, label=<label2>, ...]
function buildActions(actions: Action[]) {
return actions
.map((action) => {
return `action=${action.action}, label=${action.label}, ${
action.url ? `url=${action.url}, ` : ""
}${action.clear ? `clear=${action.clear}, ` : ""}${
action.body ? `body='${action.body}', ` : ""
}`;
})
.join("; ");
}

export default function notify({
title,
body = "",
icon = "",
category: NotificationCategory, // change this?
category, // change this?
url = "",
emoji = ""
) {
emoji = "",
actions = [],
}: {
title: string;
body?: string;
icon?: string;
category: NotificationCategory;
url?: string;
emoji?: string;
actions?: Action[];
}) {
const ntfyUrl = Config.getInstance().cfg<string>("notifications.ntfy.url");

if (url) {
actions.push({
action: "http",
label: "Open",
url: url,
});
}

if (ntfyUrl) {
axios
.request({
url: ntfyUrl,
headers: {
Title: title,
Actions: url ? `view, Open, ${url}` : undefined,
// Actions: url ? `view, Open, ${url}` : undefined,
Actions: buildActions(actions),
Icon: icon ?? undefined,
Tags: emoji ? `${emoji},${category}` : category,
},
Expand Down
50 changes: 45 additions & 5 deletions server/src/Core/Notifiers/Telegram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,56 @@ import chalk from "chalk";
import { Config } from "../Config";
import { LOGLEVEL, log } from "../Log";

interface TelegramSendMessagePayloadEntity {
type:
| "mention"
| "hashtag"
| "cashtag"
| "bot_command"
| "url"
| "email"
| "phone_number"
| "bold"
| "italic"
| "underline"
| "strikethrough"
| "code"
| "pre";
offset: number;
length: number;
url?: string;
user?: unknown;
language?: string;
custom_emoji_id?: string;
}

interface TelegramSendMessagePayload {
chat_id: number;
chat_id: number | string;
message_thread_id?: number;
text: string;
parse_mode?: "MarkdownV2" | "Markdown" | "HTML";
entities?: unknown;
disable_web_page_preview?: boolean;
entities?: TelegramSendMessagePayloadEntity[];
link_preview_options?: {
is_disabled?: boolean;
url?: string;
prefer_small_media?: boolean;
prefer_large_media?: boolean;
show_above_text?: boolean;
};
// disable_web_page_preview?: boolean;
disable_notification?: boolean;
protect_content?: boolean;
reply_to_message_id?: number;
allow_sending_without_reply?: boolean;
// reply_to_message_id?: number;
// allow_sending_without_reply?: boolean;
reply_parameters?: {
message_id: number;
chat_id?: number | string;
allow_sending_without_reply?: boolean;
quote?: string;
quote_parse_mode?: "MarkdownV2" | "Markdown" | "HTML";
quote_entities?: unknown;
quote_position?: number;
};
reply_markup?: unknown;
}

Expand Down

0 comments on commit fbe7ab4

Please sign in to comment.