@spectrum-ts/telegram 8.0.0 → 8.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +10 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UnsupportedError, definePlatform, fusor, toVCard } from "@spectrum-ts/core";
|
|
2
2
|
import z from "zod";
|
|
3
|
-
import { asAttachment, asCustom, asGroup, asMarkdown, asReaction, asText, asVoice, renderInlineTokens } from "@spectrum-ts/core/authoring";
|
|
3
|
+
import { asAttachment, asCustom, asGroup, asMarkdown, asReaction, asText, asVoice, renderInlineTokens, tracedFetch } from "@spectrum-ts/core/authoring";
|
|
4
4
|
import { createTelegramClient, editMessageText, getFile, getWebhookInfo, sendChatAction, sendMessageDraft, setMessageReaction, setWebhook } from "@photon-ai/telegram-ts";
|
|
5
5
|
import { Marked } from "marked";
|
|
6
6
|
import { timingSafeEqual } from "node:crypto";
|
|
@@ -43,6 +43,14 @@ const botIdFromToken = (botToken) => botToken.split(":")[0] ?? "";
|
|
|
43
43
|
//#region src/client.ts
|
|
44
44
|
const REQUEST_TIMEOUT_MS = 3e4;
|
|
45
45
|
const TRAILING_SLASHES = /\/+$/;
|
|
46
|
+
const BOT_TOKEN_SEGMENT = /\/file\/bot[^/]+/;
|
|
47
|
+
/**
|
|
48
|
+
* Mask the bot token embedded in a Telegram file URL path before it is recorded
|
|
49
|
+
* on a span (`/file/bot<token>/…` → `/file/bot<redacted>/…`). The real download
|
|
50
|
+
* still uses the true URL — only the span's `url.full` is masked.
|
|
51
|
+
*/
|
|
52
|
+
const redactBotToken = (url) => url.replace(BOT_TOKEN_SEGMENT, "/file/bot<redacted>");
|
|
53
|
+
const mediaFetch = tracedFetch("telegram", { redactUrl: redactBotToken });
|
|
46
54
|
/** Build a photon client bound to the bot token. Cheap: no network on construction. */
|
|
47
55
|
const telegramClient = (config) => createTelegramClient({
|
|
48
56
|
token: config.botToken,
|
|
@@ -105,8 +113,7 @@ const downloadFile = async (config, fileId) => {
|
|
|
105
113
|
throwOnError: true
|
|
106
114
|
})).result?.file_path;
|
|
107
115
|
if (!filePath) throw new Error(`Telegram getFile returned no file_path for ${fileId}`);
|
|
108
|
-
const
|
|
109
|
-
const res = await fetch(`${base}/file/bot${config.botToken}/${filePath}`, { signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS) });
|
|
116
|
+
const res = await mediaFetch(`${config.baseUrl.replace(TRAILING_SLASHES, "")}/file/bot${config.botToken}/${filePath}`, { signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS) });
|
|
110
117
|
if (!res.ok) throw new Error(`Telegram media download failed: ${res.status} ${res.statusText}`);
|
|
111
118
|
return Buffer.from(await res.arrayBuffer());
|
|
112
119
|
};
|