mirror of
https://github.com/ReCloudStudio/WebHooker.git
synced 2026-09-22 16:11:29 +00:00
Add a platform-aware route target system so a single route can forward to several destinations at once (e.g. a Discord channel and a Telegram group). Route.target becomes Route.targets[] with per-entry platform, channelId/threadId for Discord and chatId/topicId for Telegram; the legacy single-target format is normalized on load and accepted by the admin API. Implement the Telegram driver with HTML rendering and Bot API sendMessage (chat_id + message_thread_id for topics, retry on 429/5xx), plus /gh commands served over POST /telegram/webhook: login, logout, comment, merge and close. The comment/merge/close commands resolve the issue or PR from the replied-to notification message. OAuth binding now stores a D1 telegram_links mapping and replies with a confirmation. Sync the Telegram webhook from the scheduled trigger via setWebhook.
76 lines
1.5 KiB
TypeScript
76 lines
1.5 KiB
TypeScript
export interface Filter {
|
|
type: "event" | "repo" | "actor" | "action" | "branch" | "keyword";
|
|
match: string | string[];
|
|
exclude?: boolean;
|
|
}
|
|
|
|
export interface RouteTarget {
|
|
platform?: "discord" | "telegram";
|
|
channelId?: string;
|
|
threadId?: string;
|
|
chatId?: string;
|
|
topicId?: string;
|
|
}
|
|
|
|
export interface Route {
|
|
id: string;
|
|
name: string;
|
|
enabled: boolean;
|
|
filters: Filter[];
|
|
targets: RouteTarget[];
|
|
lang?: string;
|
|
groupId?: string;
|
|
fallback?: boolean;
|
|
}
|
|
|
|
export interface Group {
|
|
id: string;
|
|
name: string;
|
|
adminIds: string[];
|
|
owners?: string[];
|
|
emoji?: boolean;
|
|
}
|
|
|
|
export interface Me {
|
|
login: string;
|
|
userId: string;
|
|
isSuper: boolean;
|
|
groups: Group[];
|
|
}
|
|
|
|
export const FILTER_TYPES = ["event", "repo", "actor", "action", "branch", "keyword"] as const;
|
|
|
|
export const FILTER_LABELS: Record<string, string> = {
|
|
event: "Event",
|
|
repo: "Repo",
|
|
actor: "Actor",
|
|
action: "Action",
|
|
branch: "Branch",
|
|
keyword: "Keyword",
|
|
};
|
|
|
|
export function fmtMatch(match: string | string[]): string {
|
|
if (Array.isArray(match)) return match.join(", ");
|
|
return String(match ?? "");
|
|
}
|
|
|
|
export interface SendRecord {
|
|
id?: number;
|
|
ts: number;
|
|
routeId: string;
|
|
event: string;
|
|
repo?: string;
|
|
target: string;
|
|
ok: boolean;
|
|
error?: string;
|
|
status?: number;
|
|
messageId?: string;
|
|
deliveryId?: string;
|
|
platform?: string;
|
|
actor?: string;
|
|
action?: string;
|
|
durationMs?: number;
|
|
errorCode?: string;
|
|
attempts?: number;
|
|
detail?: Record<string, unknown>;
|
|
}
|