Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@anthropic-ai/sdk": "^0.78.0",
"js-yaml": "^4.1.1",
"openai": "^4.80.0",
"undici": "^7.24.2",
"zod": "^3.24.0"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/models/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const NotifyChannelSchema = z.discriminatedUnion("type", [
type: z.literal("telegram"),
botToken: z.string().min(1),
chatId: z.string().min(1),
proxy: z.string().optional(),
}),
z.object({
type: z.literal("wechat-work"),
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/notify/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function dispatchNotification(
switch (channel.type) {
case "telegram":
await sendTelegram(
{ botToken: channel.botToken, chatId: channel.chatId },
{ botToken: channel.botToken, chatId: channel.chatId, proxy: channel.proxy },
fullText,
);
break;
Expand Down
20 changes: 18 additions & 2 deletions packages/core/src/notify/telegram.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
import { ProxyAgent } from "undici";

export interface TelegramConfig {
readonly botToken: string;
readonly chatId: string;
readonly proxy?: string;
}

export async function sendTelegram(
config: TelegramConfig,
message: string,
): Promise<void> {
const url = `https://api.telegram.org/bot${config.botToken}/sendMessage`;
const response = await fetch(url, {
const proxyUrl =
config.proxy ||
process.env.HTTPS_PROXY ||
process.env.https_proxy ||
process.env.HTTP_PROXY ||
process.env.http_proxy;

const fetchOptions: Record<string, unknown> = {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
chat_id: config.chatId,
text: message,
parse_mode: "Markdown",
}),
});
};

if (proxyUrl) {
fetchOptions.dispatcher = new ProxyAgent(proxyUrl);
}

const response = await fetch(url, fetchOptions as RequestInit);

if (!response.ok) {
const body = await response.text();
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.