Compare commits
1 commit
main
...
graphite-b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df0d9da4a3 |
2 changed files with 9 additions and 8 deletions
|
|
@ -182,19 +182,19 @@ describe("notification shoutrrr URL builders", () => {
|
||||||
expect(
|
expect(
|
||||||
buildTelegramShoutrrrUrl({
|
buildTelegramShoutrrrUrl({
|
||||||
type: "telegram",
|
type: "telegram",
|
||||||
botToken: "bot-token",
|
botToken: "123456:ABCdef",
|
||||||
chatId: "chat-id",
|
chatId: "chat-id",
|
||||||
}),
|
}),
|
||||||
).toBe("telegram://bot-token@telegram?channels=chat-id");
|
).toBe("telegram://123456:ABCdef@telegram?channels=chat-id");
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
buildTelegramShoutrrrUrl({
|
buildTelegramShoutrrrUrl({
|
||||||
type: "telegram",
|
type: "telegram",
|
||||||
botToken: "bot-token",
|
botToken: "123456:ABCdef",
|
||||||
chatId: "chat-id",
|
chatId: "chat-id",
|
||||||
threadId: "thread-id",
|
threadId: "thread-id",
|
||||||
}),
|
}),
|
||||||
).toBe("telegram://bot-token@telegram?channels=chat-id%3Athread-id");
|
).toBe("telegram://123456:ABCdef@telegram?channels=chat-id:thread-id");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("builds generic URLs with reserved params, transport flags, and headers", () => {
|
test("builds generic URLs with reserved params, transport flags, and headers", () => {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
import type { NotificationConfig } from "~/schemas/notifications";
|
import type { NotificationConfig } from "~/schemas/notifications";
|
||||||
|
|
||||||
export const buildTelegramShoutrrrUrl = (config: Extract<NotificationConfig, { type: "telegram" }>) => {
|
export const buildTelegramShoutrrrUrl = (config: Extract<NotificationConfig, { type: "telegram" }>) => {
|
||||||
const shoutrrrUrl = new URL("telegram://telegram");
|
let shoutrrrUrl = `telegram://${config.botToken}@telegram?channels=${config.chatId}`;
|
||||||
shoutrrrUrl.username = config.botToken;
|
if (config.threadId) {
|
||||||
shoutrrrUrl.searchParams.set("channels", `${config.chatId}${config.threadId ? `:${config.threadId}` : ""}`);
|
shoutrrrUrl += `:${config.threadId}`;
|
||||||
return shoutrrrUrl.toString().replace("/?", "?");
|
}
|
||||||
|
return shoutrrrUrl;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue