@mulmobridge/telegram 1.0.1 → 1.0.2
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/api.d.ts +3 -3
- package/dist/api.js +1 -1
- package/dist/router.js +34 -34
- package/package.json +3 -3
package/dist/api.d.ts
CHANGED
|
@@ -46,9 +46,9 @@ export interface TelegramApiOptions {
|
|
|
46
46
|
fetchImpl?: typeof fetch;
|
|
47
47
|
}
|
|
48
48
|
export interface GetUpdatesOptions {
|
|
49
|
-
offset?: number;
|
|
50
|
-
timeoutSec?: number;
|
|
51
|
-
signal?: AbortSignal;
|
|
49
|
+
offset?: number | undefined;
|
|
50
|
+
timeoutSec?: number | undefined;
|
|
51
|
+
signal?: AbortSignal | undefined;
|
|
52
52
|
}
|
|
53
53
|
export interface TelegramApi {
|
|
54
54
|
getUpdates(opts?: GetUpdatesOptions): Promise<TelegramUpdate[]>;
|
package/dist/api.js
CHANGED
|
@@ -13,7 +13,7 @@ export function createTelegramApi(opts) {
|
|
|
13
13
|
params.set("timeout", String(gu.timeoutSec));
|
|
14
14
|
}
|
|
15
15
|
const url = `${base}/getUpdates?${params.toString()}`;
|
|
16
|
-
const res = await fetchImpl(url, { signal: gu.signal });
|
|
16
|
+
const res = await fetchImpl(url, gu.signal !== undefined ? { signal: gu.signal } : {});
|
|
17
17
|
if (!res.ok) {
|
|
18
18
|
throw new Error(`getUpdates failed: ${res.status} ${await safeText(res)}`);
|
|
19
19
|
}
|
package/dist/router.js
CHANGED
|
@@ -74,42 +74,42 @@ export function createMessageRouter(deps) {
|
|
|
74
74
|
// exclusive (photo OR document), but forwarded messages or future
|
|
75
75
|
// API changes could carry both. We collect all available attachments
|
|
76
76
|
// rather than picking one.
|
|
77
|
-
async function
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
attachments.push({ mimeType: parsed.mimeType, data: parsed.data });
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
catch (err) {
|
|
90
|
-
log.error(`[telegram] photo download failed: ${String(err)}`);
|
|
91
|
-
anyFailed = true;
|
|
92
|
-
}
|
|
77
|
+
async function downloadPhoto(msg) {
|
|
78
|
+
// Telegram lists photo sizes smallest-first, so the last entry is
|
|
79
|
+
// the highest resolution available.
|
|
80
|
+
const largest = Array.isArray(msg.photo) ? msg.photo[msg.photo.length - 1] : undefined;
|
|
81
|
+
if (!largest)
|
|
82
|
+
return null;
|
|
83
|
+
try {
|
|
84
|
+
const parsed = parseDataUrl(await api.downloadFile(largest.file_id, "image/jpeg"));
|
|
85
|
+
return parsed ? { attachment: { mimeType: parsed.mimeType, data: parsed.data } } : null;
|
|
93
86
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
anyFailed = true;
|
|
111
|
-
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
log.error(`[telegram] photo download failed: ${String(err)}`);
|
|
89
|
+
return { failed: true };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async function downloadDocument(msg) {
|
|
93
|
+
const doc = msg.document;
|
|
94
|
+
if (!doc)
|
|
95
|
+
return null;
|
|
96
|
+
const fallbackMime = doc.mime_type ?? "application/octet-stream";
|
|
97
|
+
try {
|
|
98
|
+
const parsed = parseDataUrl(await api.downloadFile(doc.file_id, fallbackMime));
|
|
99
|
+
if (!parsed)
|
|
100
|
+
return null;
|
|
101
|
+
const filename = doc.file_name !== undefined ? { filename: doc.file_name } : {};
|
|
102
|
+
return { attachment: { mimeType: parsed.mimeType, data: parsed.data, ...filename } };
|
|
112
103
|
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
log.error(`[telegram] document download failed: ${String(err)}`);
|
|
106
|
+
return { failed: true };
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async function tryDownloadAttachments(msg) {
|
|
110
|
+
const outcomes = [await downloadPhoto(msg), await downloadDocument(msg)];
|
|
111
|
+
const attachments = outcomes.flatMap((outcome) => (outcome && "attachment" in outcome ? [outcome.attachment] : []));
|
|
112
|
+
const anyFailed = outcomes.some((outcome) => outcome !== null && "failed" in outcome);
|
|
113
113
|
if (attachments.length === 0 && anyFailed) {
|
|
114
114
|
return { attachments: [], failed: true };
|
|
115
115
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mulmobridge/telegram",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Telegram bridge for MulmoBridge — connect a Telegram bot to MulmoClaude",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"author": "Receptron Team",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@mulmobridge/client": "^1.0.
|
|
33
|
+
"@mulmobridge/client": "^1.0.2",
|
|
34
34
|
"@mulmobridge/protocol": "^1.0.1",
|
|
35
35
|
"dotenv": "^17.0.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@types/node": "^26.1.
|
|
38
|
+
"@types/node": "^26.1.2",
|
|
39
39
|
"typescript": "^6.0.3"
|
|
40
40
|
},
|
|
41
41
|
"homepage": "https://github.com/receptron/mulmoclaude/tree/main/packages/bridges/telegram#readme",
|