feat: support all chat types in channel discovery and enrich bot messages

Channel Discovery:
- Remove channel/supergroup filter from getAccountChats — all chat types
  (private, groups, Saved Messages, etc.) are now discoverable as sources
- Detect and label the self-chat as "Saved Messages" via getMe
- Update channel picker dialog to accept any chat type string

Bot Rich Messages:
- Enhance package send preview with creator, file count, tags, and source
  channel info in MarkdownV2 caption
- Include tags in new_package subscription notifications
- Expand getPendingSendRequest to fetch richer package data

Performance:
- Reviewed pipeline for many-channel load — getChats pagination fix and
  per-channel getChat pre-load from prior commit address the main concerns
- Channels with no new messages skip in 2-3 API calls

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-23 18:27:48 +01:00
parent 5fd341dfc4
commit 29e95f780c
5 changed files with 54 additions and 14 deletions

View File

@@ -115,9 +115,15 @@ export async function getPendingSendRequest(requestId: string) {
select: {
id: true,
fileName: true,
fileSize: true,
fileCount: true,
creator: true,
tags: true,
archiveType: true,
destChannelId: true,
destMessageId: true,
previewData: true,
sourceChannel: { select: { title: true, telegramId: true } },
},
},
telegramLink: true,

View File

@@ -134,9 +134,22 @@ async function processSendRequest(requestId: string): Promise<void> {
throw new Error("No global destination channel configured");
}
// Send preview if available
// Send preview with rich caption if available
if (pkg.previewData) {
const caption = `📦 *${pkg.fileName}*\n\nSent from Dragon's Stash`;
const lines: string[] = [];
lines.push(`📦 *${escapeMarkdown(pkg.fileName)}*`);
if (pkg.creator) lines.push(`👤 ${escapeMarkdown(pkg.creator)}`);
if (pkg.fileCount > 0) lines.push(`📁 ${pkg.fileCount} files`);
if (pkg.tags && pkg.tags.length > 0) {
lines.push(`🏷️ ${pkg.tags.map((t: string) => escapeMarkdown(t)).join(", ")}`);
}
if (pkg.sourceChannel) {
lines.push(`📡 Source: ${escapeMarkdown(pkg.sourceChannel.title)}`);
}
lines.push("");
lines.push("_Sent from Dragon's Stash_");
const caption = lines.join("\n");
await sendPhotoMessage(targetUserId, Buffer.from(pkg.previewData), caption);
}
@@ -189,6 +202,9 @@ async function handleNewPackage(payload: string): Promise<void> {
`🔔 <b>New package matching your subscriptions:</b>`,
``,
`📦 <b>${escapeHtml(data.fileName)}</b>${creator}`,
...(data.tags && data.tags.length > 0
? [`🏷️ ${data.tags.map((t: string) => escapeHtml(t)).join(", ")}`]
: []),
``,
`Matched: ${patterns.map((p) => `"${escapeHtml(p)}"`).join(", ")}`,
``,
@@ -213,3 +229,7 @@ async function handleNewPackage(payload: string): Promise<void> {
function escapeHtml(text: string): string {
return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
}
function escapeMarkdown(text: string): string {
return text.replace(/([_*[\]()~`>#+\-=|{}.!\\])/g, "\\$1");
}