feat: notifications to specific Telegram topics

This commit is contained in:
vicke4
2025-02-13 22:20:52 +05:30
parent 209029214e
commit e228325e37
7 changed files with 4524 additions and 1 deletions

View File

@@ -65,6 +65,7 @@ export const telegram = pgTable("telegram", {
.$defaultFn(() => nanoid()),
botToken: text("botToken").notNull(),
chatId: text("chatId").notNull(),
messageThreadId: text("messageThreadId"),
});
export const discord = pgTable("discord", {
@@ -169,6 +170,7 @@ export const apiCreateTelegram = notificationsSchema
.extend({
botToken: z.string().min(1),
chatId: z.string().min(1),
messageThreadId: z.string()
})
.required();
@@ -181,6 +183,7 @@ export const apiUpdateTelegram = apiCreateTelegram.partial().extend({
export const apiTestTelegramConnection = apiCreateTelegram.pick({
botToken: true,
chatId: true,
messageThreadId: true,
});
export const apiCreateDiscord = notificationsSchema

View File

@@ -122,6 +122,7 @@ export const createTelegramNotification = async (
.values({
botToken: input.botToken,
chatId: input.chatId,
messageThreadId: input.messageThreadId,
})
.returning()
.then((value) => value[0]);
@@ -193,6 +194,7 @@ export const updateTelegramNotification = async (
.set({
botToken: input.botToken,
chatId: input.chatId,
messageThreadId: input.messageThreadId,
})
.where(eq(telegram.telegramId, input.telegramId))
.returning()

View File

@@ -68,6 +68,7 @@ export const sendTelegramNotification = async (
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
chat_id: connection.chatId,
message_thread_id: connection.messageThreadId,
text: messageText,
parse_mode: "HTML",
disable_web_page_preview: true,