mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
Merge pull request #1314 from vicke4/canary
feat: notifications to specific Telegram topics
This commit is contained in:
commit
e1b94dfe5b
@ -65,6 +65,7 @@ export const notificationSchema = z.discriminatedUnion("type", [
|
|||||||
type: z.literal("telegram"),
|
type: z.literal("telegram"),
|
||||||
botToken: z.string().min(1, { message: "Bot Token is required" }),
|
botToken: z.string().min(1, { message: "Bot Token is required" }),
|
||||||
chatId: z.string().min(1, { message: "Chat ID is required" }),
|
chatId: z.string().min(1, { message: "Chat ID is required" }),
|
||||||
|
messageThreadId: z.string().optional(),
|
||||||
})
|
})
|
||||||
.merge(notificationBaseSchema),
|
.merge(notificationBaseSchema),
|
||||||
z
|
z
|
||||||
@ -214,6 +215,7 @@ export const HandleNotifications = ({ notificationId }: Props) => {
|
|||||||
dokployRestart: notification.dokployRestart,
|
dokployRestart: notification.dokployRestart,
|
||||||
databaseBackup: notification.databaseBackup,
|
databaseBackup: notification.databaseBackup,
|
||||||
botToken: notification.telegram?.botToken,
|
botToken: notification.telegram?.botToken,
|
||||||
|
messageThreadId: notification.telegram?.messageThreadId || "",
|
||||||
chatId: notification.telegram?.chatId,
|
chatId: notification.telegram?.chatId,
|
||||||
type: notification.notificationType,
|
type: notification.notificationType,
|
||||||
name: notification.name,
|
name: notification.name,
|
||||||
@ -309,6 +311,7 @@ export const HandleNotifications = ({ notificationId }: Props) => {
|
|||||||
dokployRestart: dokployRestart,
|
dokployRestart: dokployRestart,
|
||||||
databaseBackup: databaseBackup,
|
databaseBackup: databaseBackup,
|
||||||
botToken: data.botToken,
|
botToken: data.botToken,
|
||||||
|
messageThreadId: data.messageThreadId || "",
|
||||||
chatId: data.chatId,
|
chatId: data.chatId,
|
||||||
name: data.name,
|
name: data.name,
|
||||||
dockerCleanup: dockerCleanup,
|
dockerCleanup: dockerCleanup,
|
||||||
@ -561,8 +564,26 @@ export const HandleNotifications = ({ notificationId }: Props) => {
|
|||||||
<FormControl>
|
<FormControl>
|
||||||
<Input placeholder="431231869" {...field} />
|
<Input placeholder="431231869" {...field} />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="messageThreadId"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Message Thread ID</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="11" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
|
<FormDescription>
|
||||||
|
Optional. Use it when you want to send notifications
|
||||||
|
to a specific topic in a group.
|
||||||
|
</FormDescription>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
@ -1014,6 +1035,7 @@ export const HandleNotifications = ({ notificationId }: Props) => {
|
|||||||
await testTelegramConnection({
|
await testTelegramConnection({
|
||||||
botToken: form.getValues("botToken"),
|
botToken: form.getValues("botToken"),
|
||||||
chatId: form.getValues("chatId"),
|
chatId: form.getValues("chatId"),
|
||||||
|
messageThreadId: form.getValues("messageThreadId") || "",
|
||||||
});
|
});
|
||||||
} else if (type === "discord") {
|
} else if (type === "discord") {
|
||||||
await testDiscordConnection({
|
await testDiscordConnection({
|
||||||
|
1
apps/dokploy/drizzle/0067_condemned_sugar_man.sql
Normal file
1
apps/dokploy/drizzle/0067_condemned_sugar_man.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE "telegram" ADD COLUMN "messageThreadId" text;
|
5042
apps/dokploy/drizzle/meta/0067_snapshot.json
Normal file
5042
apps/dokploy/drizzle/meta/0067_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -470,6 +470,13 @@
|
|||||||
"when": 1739426913392,
|
"when": 1739426913392,
|
||||||
"tag": "0066_yielding_echo",
|
"tag": "0066_yielding_echo",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 67,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1740892043121,
|
||||||
|
"tag": "0067_condemned_sugar_man",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -67,8 +67,8 @@ export default function Home({ IS_CLOUD }: Props) {
|
|||||||
const loginForm = useForm<LoginForm>({
|
const loginForm = useForm<LoginForm>({
|
||||||
resolver: zodResolver(LoginSchema),
|
resolver: zodResolver(LoginSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
email: "siumauricio@hotmail.com",
|
email: "",
|
||||||
password: "Password123",
|
password: "",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -78,10 +78,10 @@ const Register = ({ isCloud }: Props) => {
|
|||||||
|
|
||||||
const form = useForm<Register>({
|
const form = useForm<Register>({
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
name: "Mauricio Siu",
|
name: "",
|
||||||
email: "user5@yopmail.com",
|
email: "",
|
||||||
password: "Password123",
|
password: "",
|
||||||
confirmPassword: "Password123",
|
confirmPassword: "",
|
||||||
},
|
},
|
||||||
resolver: zodResolver(registerSchema),
|
resolver: zodResolver(registerSchema),
|
||||||
});
|
});
|
||||||
|
@ -65,6 +65,7 @@ export const telegram = pgTable("telegram", {
|
|||||||
.$defaultFn(() => nanoid()),
|
.$defaultFn(() => nanoid()),
|
||||||
botToken: text("botToken").notNull(),
|
botToken: text("botToken").notNull(),
|
||||||
chatId: text("chatId").notNull(),
|
chatId: text("chatId").notNull(),
|
||||||
|
messageThreadId: text("messageThreadId"),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const discord = pgTable("discord", {
|
export const discord = pgTable("discord", {
|
||||||
@ -169,6 +170,7 @@ export const apiCreateTelegram = notificationsSchema
|
|||||||
.extend({
|
.extend({
|
||||||
botToken: z.string().min(1),
|
botToken: z.string().min(1),
|
||||||
chatId: z.string().min(1),
|
chatId: z.string().min(1),
|
||||||
|
messageThreadId: z.string(),
|
||||||
})
|
})
|
||||||
.required();
|
.required();
|
||||||
|
|
||||||
@ -181,6 +183,7 @@ export const apiUpdateTelegram = apiCreateTelegram.partial().extend({
|
|||||||
export const apiTestTelegramConnection = apiCreateTelegram.pick({
|
export const apiTestTelegramConnection = apiCreateTelegram.pick({
|
||||||
botToken: true,
|
botToken: true,
|
||||||
chatId: true,
|
chatId: true,
|
||||||
|
messageThreadId: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const apiCreateDiscord = notificationsSchema
|
export const apiCreateDiscord = notificationsSchema
|
||||||
|
@ -122,6 +122,7 @@ export const createTelegramNotification = async (
|
|||||||
.values({
|
.values({
|
||||||
botToken: input.botToken,
|
botToken: input.botToken,
|
||||||
chatId: input.chatId,
|
chatId: input.chatId,
|
||||||
|
messageThreadId: input.messageThreadId,
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
.then((value) => value[0]);
|
.then((value) => value[0]);
|
||||||
@ -193,6 +194,7 @@ export const updateTelegramNotification = async (
|
|||||||
.set({
|
.set({
|
||||||
botToken: input.botToken,
|
botToken: input.botToken,
|
||||||
chatId: input.chatId,
|
chatId: input.chatId,
|
||||||
|
messageThreadId: input.messageThreadId,
|
||||||
})
|
})
|
||||||
.where(eq(telegram.telegramId, input.telegramId))
|
.where(eq(telegram.telegramId, input.telegramId))
|
||||||
.returning()
|
.returning()
|
||||||
|
@ -68,6 +68,7 @@ export const sendTelegramNotification = async (
|
|||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
chat_id: connection.chatId,
|
chat_id: connection.chatId,
|
||||||
|
message_thread_id: connection.messageThreadId,
|
||||||
text: messageText,
|
text: messageText,
|
||||||
parse_mode: "HTML",
|
parse_mode: "HTML",
|
||||||
disable_web_page_preview: true,
|
disable_web_page_preview: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user