@spinabot/brigade 1.1.0 → 1.2.0
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/convex/channels.d.ts +5 -5
- package/convex/schema.d.ts +2 -2
- package/dist/agents/agent-loop.d.ts.map +1 -1
- package/dist/agents/agent-loop.js +27 -4
- package/dist/agents/agent-loop.js.map +1 -1
- package/dist/agents/channels/approval-callback-codec.d.ts +107 -0
- package/dist/agents/channels/approval-callback-codec.d.ts.map +1 -0
- package/dist/agents/channels/approval-callback-codec.js +173 -0
- package/dist/agents/channels/approval-callback-codec.js.map +1 -0
- package/dist/agents/channels/approval-router.d.ts +77 -20
- package/dist/agents/channels/approval-router.d.ts.map +1 -1
- package/dist/agents/channels/approval-router.js +163 -37
- package/dist/agents/channels/approval-router.js.map +1 -1
- package/dist/agents/channels/backoff.d.ts +55 -0
- package/dist/agents/channels/backoff.d.ts.map +1 -0
- package/dist/agents/channels/backoff.js +47 -0
- package/dist/agents/channels/backoff.js.map +1 -0
- package/dist/agents/channels/channel-secrets.d.ts +45 -0
- package/dist/agents/channels/channel-secrets.d.ts.map +1 -0
- package/dist/agents/channels/channel-secrets.js +69 -0
- package/dist/agents/channels/channel-secrets.js.map +1 -0
- package/dist/agents/channels/inbound-pipeline.d.ts.map +1 -1
- package/dist/agents/channels/inbound-pipeline.js +67 -3
- package/dist/agents/channels/inbound-pipeline.js.map +1 -1
- package/dist/agents/channels/last-sent-message.d.ts +46 -0
- package/dist/agents/channels/last-sent-message.d.ts.map +1 -0
- package/dist/agents/channels/last-sent-message.js +55 -0
- package/dist/agents/channels/last-sent-message.js.map +1 -0
- package/dist/agents/channels/manager.d.ts +52 -0
- package/dist/agents/channels/manager.d.ts.map +1 -1
- package/dist/agents/channels/manager.js +141 -31
- package/dist/agents/channels/manager.js.map +1 -1
- package/dist/agents/channels/plugin-channel-manager-facade.d.ts +13 -2
- package/dist/agents/channels/plugin-channel-manager-facade.d.ts.map +1 -1
- package/dist/agents/channels/plugin-channel-manager-facade.js +21 -0
- package/dist/agents/channels/plugin-channel-manager-facade.js.map +1 -1
- package/dist/agents/channels/sdk.d.ts +426 -0
- package/dist/agents/channels/sdk.d.ts.map +1 -0
- package/dist/agents/channels/sdk.js +274 -0
- package/dist/agents/channels/sdk.js.map +1 -0
- package/dist/agents/channels/telegram/account-config.d.ts +92 -0
- package/dist/agents/channels/telegram/account-config.d.ts.map +1 -0
- package/dist/agents/channels/telegram/account-config.js +192 -0
- package/dist/agents/channels/telegram/account-config.js.map +1 -0
- package/dist/agents/channels/telegram/adapter.d.ts +79 -0
- package/dist/agents/channels/telegram/adapter.d.ts.map +1 -0
- package/dist/agents/channels/telegram/adapter.js +475 -0
- package/dist/agents/channels/telegram/adapter.js.map +1 -0
- package/dist/agents/channels/telegram/allowed-updates.d.ts +44 -0
- package/dist/agents/channels/telegram/allowed-updates.d.ts.map +1 -0
- package/dist/agents/channels/telegram/allowed-updates.js +52 -0
- package/dist/agents/channels/telegram/allowed-updates.js.map +1 -0
- package/dist/agents/channels/telegram/approval-authorize.d.ts +41 -0
- package/dist/agents/channels/telegram/approval-authorize.d.ts.map +1 -0
- package/dist/agents/channels/telegram/approval-authorize.js +69 -0
- package/dist/agents/channels/telegram/approval-authorize.js.map +1 -0
- package/dist/agents/channels/telegram/approval-native.d.ts +68 -0
- package/dist/agents/channels/telegram/approval-native.d.ts.map +1 -0
- package/dist/agents/channels/telegram/approval-native.js +94 -0
- package/dist/agents/channels/telegram/approval-native.js.map +1 -0
- package/dist/agents/channels/telegram/command-menu.d.ts +35 -0
- package/dist/agents/channels/telegram/command-menu.d.ts.map +1 -0
- package/dist/agents/channels/telegram/command-menu.js +59 -0
- package/dist/agents/channels/telegram/command-menu.js.map +1 -0
- package/dist/agents/channels/telegram/connection.d.ts +359 -0
- package/dist/agents/channels/telegram/connection.d.ts.map +1 -0
- package/dist/agents/channels/telegram/connection.js +865 -0
- package/dist/agents/channels/telegram/connection.js.map +1 -0
- package/dist/agents/channels/telegram/format.d.ts +48 -0
- package/dist/agents/channels/telegram/format.d.ts.map +1 -0
- package/dist/agents/channels/telegram/format.js +256 -0
- package/dist/agents/channels/telegram/format.js.map +1 -0
- package/dist/agents/channels/telegram/inbound-extras.d.ts +73 -0
- package/dist/agents/channels/telegram/inbound-extras.d.ts.map +1 -0
- package/dist/agents/channels/telegram/inbound-extras.js +231 -0
- package/dist/agents/channels/telegram/inbound-extras.js.map +1 -0
- package/dist/agents/channels/telegram/index.d.ts +14 -0
- package/dist/agents/channels/telegram/index.d.ts.map +1 -0
- package/dist/agents/channels/telegram/index.js +14 -0
- package/dist/agents/channels/telegram/index.js.map +1 -0
- package/dist/agents/channels/telegram/media.d.ts +68 -0
- package/dist/agents/channels/telegram/media.d.ts.map +1 -0
- package/dist/agents/channels/telegram/media.js +143 -0
- package/dist/agents/channels/telegram/media.js.map +1 -0
- package/dist/agents/channels/telegram/module.d.ts +15 -0
- package/dist/agents/channels/telegram/module.d.ts.map +1 -0
- package/dist/agents/channels/telegram/module.js +36 -0
- package/dist/agents/channels/telegram/module.js.map +1 -0
- package/dist/agents/channels/telegram/plugin.d.ts +76 -0
- package/dist/agents/channels/telegram/plugin.d.ts.map +1 -0
- package/dist/agents/channels/telegram/plugin.js +314 -0
- package/dist/agents/channels/telegram/plugin.js.map +1 -0
- package/dist/agents/channels/telegram/probe.d.ts +54 -0
- package/dist/agents/channels/telegram/probe.d.ts.map +1 -0
- package/dist/agents/channels/telegram/probe.js +95 -0
- package/dist/agents/channels/telegram/probe.js.map +1 -0
- package/dist/agents/channels/telegram/webhook.d.ts +55 -0
- package/dist/agents/channels/telegram/webhook.d.ts.map +1 -0
- package/dist/agents/channels/telegram/webhook.js +141 -0
- package/dist/agents/channels/telegram/webhook.js.map +1 -0
- package/dist/agents/extensions/modules/index.d.ts.map +1 -1
- package/dist/agents/extensions/modules/index.js +4 -0
- package/dist/agents/extensions/modules/index.js.map +1 -1
- package/dist/agents/extensions/types.d.ts +72 -2
- package/dist/agents/extensions/types.d.ts.map +1 -1
- package/dist/agents/extensions/types.js.map +1 -1
- package/dist/agents/tools/connect-channel-tool.d.ts +86 -0
- package/dist/agents/tools/connect-channel-tool.d.ts.map +1 -0
- package/dist/agents/tools/connect-channel-tool.js +398 -0
- package/dist/agents/tools/connect-channel-tool.js.map +1 -0
- package/dist/agents/tools/message-action-tool.d.ts +67 -0
- package/dist/agents/tools/message-action-tool.d.ts.map +1 -0
- package/dist/agents/tools/message-action-tool.js +216 -0
- package/dist/agents/tools/message-action-tool.js.map +1 -0
- package/dist/agents/tools/registry.d.ts.map +1 -1
- package/dist/agents/tools/registry.js +19 -0
- package/dist/agents/tools/registry.js.map +1 -1
- package/dist/buildstamp.json +1 -1
- package/dist/cli/commands/channels.d.ts.map +1 -1
- package/dist/cli/commands/channels.js +27 -2
- package/dist/cli/commands/channels.js.map +1 -1
- package/dist/core/server.d.ts.map +1 -1
- package/dist/core/server.js +77 -27
- package/dist/core/server.js.map +1 -1
- package/dist/cron/service/state.d.ts +10 -0
- package/dist/cron/service/state.d.ts.map +1 -1
- package/dist/cron/service/state.js.map +1 -1
- package/dist/cron/service/timer.d.ts.map +1 -1
- package/dist/cron/service/timer.js +43 -14
- package/dist/cron/service/timer.js.map +1 -1
- package/dist/cron/session-reaper.d.ts +27 -0
- package/dist/cron/session-reaper.d.ts.map +1 -1
- package/dist/cron/session-reaper.js +81 -0
- package/dist/cron/session-reaper.js.map +1 -1
- package/dist/system-prompt/assembler.d.ts +14 -0
- package/dist/system-prompt/assembler.d.ts.map +1 -1
- package/dist/system-prompt/assembler.js +36 -14
- package/dist/system-prompt/assembler.js.map +1 -1
- package/package.json +16 -3
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure extractors that turn a grammY `Message` into the normalized fields
|
|
3
|
+
* Brigade's `InboundMessage` carries. No network, no side effects — every
|
|
4
|
+
* function here is deterministic over its `Message` argument so they're trivial
|
|
5
|
+
* to unit-test without a live bot.
|
|
6
|
+
*
|
|
7
|
+
* The text / mention / media-detection logic is ported nearly verbatim from
|
|
8
|
+
* the reference Telegram extension (`bot/body-helpers.ts` +
|
|
9
|
+
* `bot-handlers.media.ts`); only brand tokens and the IR-engine dependency were
|
|
10
|
+
* scrubbed. Brigade's CENTRAL inbound pipeline owns the actual ACL / mention /
|
|
11
|
+
* routing decision — these helpers only surface the raw signals it reads
|
|
12
|
+
* (`mentions`, `threadId`, `replyTo`, chat type).
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Reject control-byte payloads (a binary blob masquerading as text). Tab / LF /
|
|
16
|
+
* CR are allowed; any other C0 control char marks the run as non-text and it's
|
|
17
|
+
* dropped so the agent never ingests raw binary. Ported from the reference
|
|
18
|
+
* `isBinaryContent`.
|
|
19
|
+
*/
|
|
20
|
+
function isBinaryContent(text) {
|
|
21
|
+
for (let i = 0; i < text.length; i++) {
|
|
22
|
+
const code = text.charCodeAt(i);
|
|
23
|
+
if (code <= 0x1f && code !== 0x09 && code !== 0x0a && code !== 0x0d) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
/** Pick the message's text body (prefers `text`, falls back to media `caption`). */
|
|
30
|
+
function resolveTextContent(text, caption) {
|
|
31
|
+
const raw = typeof text === "string" ? text : typeof caption === "string" ? caption : "";
|
|
32
|
+
return isBinaryContent(raw) ? "" : raw;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The text + entities a message carries. Caption-bearing media surfaces its
|
|
36
|
+
* caption (and `caption_entities`) as the text. Empty text means no entities.
|
|
37
|
+
*/
|
|
38
|
+
export function getTelegramTextParts(msg) {
|
|
39
|
+
const text = resolveTextContent(msg.text, msg.caption);
|
|
40
|
+
const entities = text ? (msg.entities ?? msg.caption_entities ?? []) : [];
|
|
41
|
+
return { text, entities };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Rewrite Telegram `text_link` entities (hyperlinked display text) back into
|
|
45
|
+
* markdown `[label](url)` so the agent sees the destination URL. Applied
|
|
46
|
+
* right-to-left so earlier offsets stay valid as we splice. Ported from the
|
|
47
|
+
* reference `expandTextLinks`.
|
|
48
|
+
*/
|
|
49
|
+
function expandTextLinks(text, entities) {
|
|
50
|
+
if (!text || !entities?.length)
|
|
51
|
+
return text;
|
|
52
|
+
const textLinks = entities
|
|
53
|
+
.filter((e) => e.type === "text_link" && Boolean(e.url))
|
|
54
|
+
.slice()
|
|
55
|
+
.sort((a, b) => b.offset - a.offset);
|
|
56
|
+
if (textLinks.length === 0)
|
|
57
|
+
return text;
|
|
58
|
+
let result = text;
|
|
59
|
+
for (const entity of textLinks) {
|
|
60
|
+
const linkText = text.slice(entity.offset, entity.offset + entity.length);
|
|
61
|
+
const markdown = `[${linkText}](${entity.url})`;
|
|
62
|
+
result = result.slice(0, entity.offset) + markdown + result.slice(entity.offset + entity.length);
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
/** Extract the agent-facing plain text (caption-aware + text_link-expanded). */
|
|
67
|
+
export function extractTelegramText(msg) {
|
|
68
|
+
const { text, entities } = getTelegramTextParts(msg);
|
|
69
|
+
return expandTextLinks(text, entities).trim();
|
|
70
|
+
}
|
|
71
|
+
/** Telegram chat kind → Brigade chat type. private → direct; group/supergroup → group. */
|
|
72
|
+
export function telegramChatType(msg) {
|
|
73
|
+
const type = msg.chat?.type;
|
|
74
|
+
return type === "group" || type === "supergroup" ? "group" : "direct";
|
|
75
|
+
}
|
|
76
|
+
/** Forum-topic / thread id as a string, when the message belongs to one. */
|
|
77
|
+
export function telegramThreadId(msg) {
|
|
78
|
+
const id = msg.message_thread_id;
|
|
79
|
+
return typeof id === "number" ? String(id) : undefined;
|
|
80
|
+
}
|
|
81
|
+
/** Lowercase a value, treating non-strings as "". */
|
|
82
|
+
function lower(value) {
|
|
83
|
+
return typeof value === "string" ? value.toLowerCase() : "";
|
|
84
|
+
}
|
|
85
|
+
/** Word-char test for standalone @mention boundary detection. */
|
|
86
|
+
function isMentionWordChar(char) {
|
|
87
|
+
return char != null && /[a-z0-9_]/i.test(char);
|
|
88
|
+
}
|
|
89
|
+
/** True when `mention` appears in `text` not glued to another word char. */
|
|
90
|
+
function hasStandaloneMention(text, mention) {
|
|
91
|
+
let startIndex = 0;
|
|
92
|
+
while (startIndex < text.length) {
|
|
93
|
+
const idx = text.indexOf(mention, startIndex);
|
|
94
|
+
if (idx === -1)
|
|
95
|
+
return false;
|
|
96
|
+
const prev = idx > 0 ? text[idx - 1] : undefined;
|
|
97
|
+
const next = text[idx + mention.length];
|
|
98
|
+
if (!isMentionWordChar(prev) && !isMentionWordChar(next))
|
|
99
|
+
return true;
|
|
100
|
+
startIndex = idx + 1;
|
|
101
|
+
}
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Channel-native ids of accounts addressed in this message. Brigade's central
|
|
106
|
+
* group ACL treats a group message as "addressed to the bot" when the bot's
|
|
107
|
+
* own id appears in `mentions`; without this a group message never reaches the
|
|
108
|
+
* agent. So when the bot's own `@username` is mentioned (as a `mention` entity
|
|
109
|
+
* OR a standalone `@username` in the text), we surface the bot's NUMERIC id
|
|
110
|
+
* (passed in from getMe) — that's the stable handle the pipeline matches
|
|
111
|
+
* against the linked self id.
|
|
112
|
+
*
|
|
113
|
+
* Other users' `text_mention` entities (which carry a real `user.id`) are also
|
|
114
|
+
* surfaced so the pipeline can see who else was tagged. Plain `@username`
|
|
115
|
+
* mentions of OTHER users are NOT resolvable to a numeric id from the message
|
|
116
|
+
* alone (Telegram doesn't include their id), so they're dropped rather than
|
|
117
|
+
* minting a fake id.
|
|
118
|
+
*
|
|
119
|
+
* @param botUserId the bot's own numeric id (from getMe) as a string, used as
|
|
120
|
+
* the surfaced id when the bot is @-mentioned.
|
|
121
|
+
* @param botUsername the bot's own @username (without `@`), lower-cased match.
|
|
122
|
+
*/
|
|
123
|
+
export function extractTelegramMentions(msg, botUsername, botUserId) {
|
|
124
|
+
const { text, entities } = getTelegramTextParts(msg);
|
|
125
|
+
const out = [];
|
|
126
|
+
const seen = new Set();
|
|
127
|
+
const push = (id) => {
|
|
128
|
+
if (!id || seen.has(id))
|
|
129
|
+
return;
|
|
130
|
+
seen.add(id);
|
|
131
|
+
out.push(id);
|
|
132
|
+
};
|
|
133
|
+
const botHandle = botUsername ? lower(`@${botUsername}`) : "";
|
|
134
|
+
let botMentioned = false;
|
|
135
|
+
// text_mention entities carry a concrete user → surface that user's id.
|
|
136
|
+
for (const ent of entities) {
|
|
137
|
+
if (ent.type === "text_mention") {
|
|
138
|
+
const uid = ent.user?.id;
|
|
139
|
+
if (typeof uid === "number") {
|
|
140
|
+
const idStr = String(uid);
|
|
141
|
+
if (botUserId && idStr === botUserId)
|
|
142
|
+
botMentioned = true;
|
|
143
|
+
else
|
|
144
|
+
push(idStr);
|
|
145
|
+
}
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
if (ent.type === "mention" && botHandle) {
|
|
149
|
+
const slice = lower(text.slice(ent.offset, ent.offset + ent.length));
|
|
150
|
+
if (slice === botHandle)
|
|
151
|
+
botMentioned = true;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// Standalone "@botusername" anywhere in the text also counts as addressing.
|
|
155
|
+
if (botHandle && hasStandaloneMention(lower(text), botHandle))
|
|
156
|
+
botMentioned = true;
|
|
157
|
+
// A reply to one of the bot's own messages is an implicit address.
|
|
158
|
+
if (botUserId && typeof msg.reply_to_message?.from?.id === "number" && String(msg.reply_to_message.from.id) === botUserId) {
|
|
159
|
+
botMentioned = true;
|
|
160
|
+
}
|
|
161
|
+
if (botMentioned && botUserId)
|
|
162
|
+
push(botUserId);
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
165
|
+
/** Reply-context (what message this inbound quotes), when it's a reply. */
|
|
166
|
+
export function extractTelegramReplyContext(msg) {
|
|
167
|
+
const reply = msg.reply_to_message;
|
|
168
|
+
if (!reply)
|
|
169
|
+
return undefined;
|
|
170
|
+
const messageId = typeof reply.message_id === "number" ? String(reply.message_id) : undefined;
|
|
171
|
+
const from = typeof reply.from?.id === "number" ? String(reply.from.id) : undefined;
|
|
172
|
+
const quotedText = extractTelegramText(reply);
|
|
173
|
+
const body = quotedText ? quotedText.slice(0, 280) : undefined; // bound LLM context
|
|
174
|
+
if (!messageId && !from && !body)
|
|
175
|
+
return undefined;
|
|
176
|
+
return { messageId, from, body };
|
|
177
|
+
}
|
|
178
|
+
/* ───────────────────────── media detection (ported) ───────────────────────── */
|
|
179
|
+
/**
|
|
180
|
+
* Cheap presence probe — does this message carry a downloadable media envelope?
|
|
181
|
+
* Walks the same fields as the downloader but never touches the network, so the
|
|
182
|
+
* connection layer can DEFER the actual download until AFTER the central access
|
|
183
|
+
* gate admits the sender (mirrors WhatsApp's deferred-media discipline). Ported
|
|
184
|
+
* from the reference `bot-handlers.media.ts` `hasInboundMedia`.
|
|
185
|
+
*/
|
|
186
|
+
export function hasInboundMedia(msg) {
|
|
187
|
+
return (Boolean(msg.media_group_id) ||
|
|
188
|
+
(Array.isArray(msg.photo) && msg.photo.length > 0) ||
|
|
189
|
+
Boolean(msg.video ?? msg.video_note ?? msg.document ?? msg.audio ?? msg.voice ?? msg.sticker));
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* The `file_id` of the primary downloadable attachment (largest photo size /
|
|
193
|
+
* the single video / document / etc.). Ported from the reference
|
|
194
|
+
* `resolveInboundMediaFileId`. Returns undefined for a text-only message.
|
|
195
|
+
*/
|
|
196
|
+
export function resolveInboundMediaFileId(msg) {
|
|
197
|
+
return (msg.sticker?.file_id ??
|
|
198
|
+
msg.photo?.[msg.photo.length - 1]?.file_id ??
|
|
199
|
+
msg.video?.file_id ??
|
|
200
|
+
msg.video_note?.file_id ??
|
|
201
|
+
msg.document?.file_id ??
|
|
202
|
+
msg.audio?.file_id ??
|
|
203
|
+
msg.voice?.file_id);
|
|
204
|
+
}
|
|
205
|
+
/** The Brigade media-kind of the primary attachment, for the `InboundMediaAttachment.kind`. */
|
|
206
|
+
export function resolveInboundMediaKind(msg) {
|
|
207
|
+
if (msg.sticker)
|
|
208
|
+
return "sticker";
|
|
209
|
+
if (Array.isArray(msg.photo) && msg.photo.length > 0)
|
|
210
|
+
return "image";
|
|
211
|
+
if (msg.video || msg.video_note)
|
|
212
|
+
return "video";
|
|
213
|
+
if (msg.voice)
|
|
214
|
+
return "voice";
|
|
215
|
+
if (msg.audio)
|
|
216
|
+
return "audio";
|
|
217
|
+
if (msg.document)
|
|
218
|
+
return "document";
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
/** A short display name for the sender (`First Last` or `@username`). */
|
|
222
|
+
export function buildTelegramSenderName(msg) {
|
|
223
|
+
const from = msg.from;
|
|
224
|
+
if (!from)
|
|
225
|
+
return undefined;
|
|
226
|
+
const full = [from.first_name, from.last_name].filter(Boolean).join(" ").trim();
|
|
227
|
+
if (full)
|
|
228
|
+
return full;
|
|
229
|
+
return from.username ? `@${from.username}` : undefined;
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=inbound-extras.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inbound-extras.js","sourceRoot":"","sources":["../../../../src/agents/channels/telegram/inbound-extras.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AASH;;;;;GAKG;AACH,SAAS,eAAe,CAAC,IAAY;IACpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAChC,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YACrE,OAAO,IAAI,CAAC;QAC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AAE,OAAO,UAAU,CAAC;IACpC,OAAO,SAAS,CAAC;AAClB,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,uBAAuB,CAAC,GAAY;IACnD,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;IACtB,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAC;IAC5B,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IAChF,IAAI,IAAI;QAAE,OAAO,IAAI,CAAC;IACtB,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Telegram channel — public surface. */
|
|
2
|
+
export { createTelegramAdapter, deriveTopicName, TELEGRAM_CAPABILITIES, type CreateTelegramAdapterOptions, } from "./adapter.js";
|
|
3
|
+
export { listTelegramAccountIds, resolveTelegramAccount, resolveTelegramBotToken, telegramAutoLabelTopics, telegramChannelEnabled, telegramThreadIdleTtlMs, telegramWebhookConfig, TELEGRAM_BOT_TOKEN_ENV_VAR, TELEGRAM_CHANNEL_ID, TELEGRAM_DEFAULT_ACCOUNT_ID, type ResolvedTelegramAccount, type TelegramWebhookConfig, } from "./account-config.js";
|
|
4
|
+
export { resolveTelegramAllowedUpdates, type ResolveTelegramAllowedUpdatesOptions, type TelegramAllowedUpdate, } from "./allowed-updates.js";
|
|
5
|
+
export { buildTelegramApprovalKeyboard, buildTelegramApprovalText, sanitizeTelegramCallbackData, TELEGRAM_CALLBACK_DATA_MAX_BYTES, type TelegramInlineKeyboardMarkup, } from "./approval-native.js";
|
|
6
|
+
export { resolveTelegramApprover } from "./approval-authorize.js";
|
|
7
|
+
export { buildTelegramCommandMenu, normalizeTelegramCommandName, type TelegramBotCommand, } from "./command-menu.js";
|
|
8
|
+
export { connectTelegram, isTelegramGetUpdatesConflict, isTelegramUnauthorized, redactTelegramToken, telegramBackoffDelay, type ConnectTelegramArgs, type TelegramBotIdentity, type TelegramConnection, type TelegramPollSpec, type TgInboundMessage, } from "./connection.js";
|
|
9
|
+
export { markdownToTelegramHtml, telegramHtmlIsEmpty } from "./format.js";
|
|
10
|
+
export { createTelegramPlugin, type TelegramPluginDeps, type TelegramPluginHandle } from "./plugin.js";
|
|
11
|
+
export { probeTelegram, type TelegramProbeResult, type TelegramProbeIdentity } from "./probe.js";
|
|
12
|
+
export { buildTelegramWebhookRoute, hasValidTelegramWebhookSecret, safeEqualSecret, TELEGRAM_WEBHOOK_SECRET_HEADER, } from "./webhook.js";
|
|
13
|
+
export { telegramModule } from "./module.js";
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/agents/channels/telegram/index.ts"],"names":[],"mappings":"AAAA,yCAAyC;AAEzC,OAAO,EACN,qBAAqB,EACrB,eAAe,EACf,qBAAqB,EACrB,KAAK,4BAA4B,GACjC,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,0BAA0B,EAC1B,mBAAmB,EACnB,2BAA2B,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,GAC1B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,6BAA6B,EAC7B,KAAK,oCAAoC,EACzC,KAAK,qBAAqB,GAC1B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,6BAA6B,EAC7B,yBAAyB,EACzB,4BAA4B,EAC5B,gCAAgC,EAChC,KAAK,4BAA4B,GACjC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EACN,wBAAwB,EACxB,4BAA4B,EAC5B,KAAK,kBAAkB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACN,eAAe,EACf,4BAA4B,EAC5B,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACpB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,KAAK,kBAAkB,EAAE,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACvG,OAAO,EAAE,aAAa,EAAE,KAAK,mBAAmB,EAAE,KAAK,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACjG,OAAO,EACN,yBAAyB,EACzB,6BAA6B,EAC7B,eAAe,EACf,8BAA8B,GAC9B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Telegram channel — public surface. */
|
|
2
|
+
export { createTelegramAdapter, deriveTopicName, TELEGRAM_CAPABILITIES, } from "./adapter.js";
|
|
3
|
+
export { listTelegramAccountIds, resolveTelegramAccount, resolveTelegramBotToken, telegramAutoLabelTopics, telegramChannelEnabled, telegramThreadIdleTtlMs, telegramWebhookConfig, TELEGRAM_BOT_TOKEN_ENV_VAR, TELEGRAM_CHANNEL_ID, TELEGRAM_DEFAULT_ACCOUNT_ID, } from "./account-config.js";
|
|
4
|
+
export { resolveTelegramAllowedUpdates, } from "./allowed-updates.js";
|
|
5
|
+
export { buildTelegramApprovalKeyboard, buildTelegramApprovalText, sanitizeTelegramCallbackData, TELEGRAM_CALLBACK_DATA_MAX_BYTES, } from "./approval-native.js";
|
|
6
|
+
export { resolveTelegramApprover } from "./approval-authorize.js";
|
|
7
|
+
export { buildTelegramCommandMenu, normalizeTelegramCommandName, } from "./command-menu.js";
|
|
8
|
+
export { connectTelegram, isTelegramGetUpdatesConflict, isTelegramUnauthorized, redactTelegramToken, telegramBackoffDelay, } from "./connection.js";
|
|
9
|
+
export { markdownToTelegramHtml, telegramHtmlIsEmpty } from "./format.js";
|
|
10
|
+
export { createTelegramPlugin } from "./plugin.js";
|
|
11
|
+
export { probeTelegram } from "./probe.js";
|
|
12
|
+
export { buildTelegramWebhookRoute, hasValidTelegramWebhookSecret, safeEqualSecret, TELEGRAM_WEBHOOK_SECRET_HEADER, } from "./webhook.js";
|
|
13
|
+
export { telegramModule } from "./module.js";
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/agents/channels/telegram/index.ts"],"names":[],"mappings":"AAAA,yCAAyC;AAEzC,OAAO,EACN,qBAAqB,EACrB,eAAe,EACf,qBAAqB,GAErB,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,0BAA0B,EAC1B,mBAAmB,EACnB,2BAA2B,GAG3B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,6BAA6B,GAG7B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,6BAA6B,EAC7B,yBAAyB,EACzB,4BAA4B,EAC5B,gCAAgC,GAEhC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EACN,wBAAwB,EACxB,4BAA4B,GAE5B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACN,eAAe,EACf,4BAA4B,EAC5B,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,GAMpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAsD,MAAM,aAAa,CAAC;AACvG,OAAO,EAAE,aAAa,EAAwD,MAAM,YAAY,CAAC;AACjG,OAAO,EACN,yBAAyB,EACzB,6BAA6B,EAC7B,eAAe,EACf,8BAA8B,GAC9B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram media helpers — inbound download + outbound InputFile construction.
|
|
3
|
+
*
|
|
4
|
+
* INBOUND: Telegram doesn't push file bytes; it pushes a `file_id`. To get the
|
|
5
|
+
* bytes we call `getFile(file_id)` (returns a short-lived `file_path`) then
|
|
6
|
+
* download `https://api.telegram.org/file/bot<token>/<file_path>`. Bytes are
|
|
7
|
+
* saved under `~/.brigade/channels/telegram/media/<YYYY-MM-DD>/<fileUid>.<ext>`
|
|
8
|
+
* so the agent can `read` the attachment by path. In convex mode the cache
|
|
9
|
+
* relocates to the OS cache dir (never under ~/.brigade, to respect the
|
|
10
|
+
* strict-zero guard).
|
|
11
|
+
*
|
|
12
|
+
* OUTBOUND: `buildTelegramInputFile` wraps a local path / Buffer in grammY's
|
|
13
|
+
* `InputFile`, after running it through Brigade's outbound media-path guard so
|
|
14
|
+
* a prompt-injected "send ~/.ssh/id_rsa" can't exfiltrate a secret.
|
|
15
|
+
*
|
|
16
|
+
* grammY is lazy-imported (only `InputFile` is needed, and only on the outbound
|
|
17
|
+
* path) so a non-Telegram boot never pays for the dependency.
|
|
18
|
+
*/
|
|
19
|
+
import { type InboundMediaAttachment, type OutboundMedia } from "../sdk.js";
|
|
20
|
+
/**
|
|
21
|
+
* Telegram Bot API download cap is 20 MB; keep a defensive ceiling slightly
|
|
22
|
+
* under it. Anything larger is skipped (the message still reaches the agent
|
|
23
|
+
* without the attachment).
|
|
24
|
+
*/
|
|
25
|
+
declare const MAX_BYTES: number;
|
|
26
|
+
/** The grammY surface the downloader needs — kept minimal + injectable for tests. */
|
|
27
|
+
export interface TelegramBotFileApi {
|
|
28
|
+
/** Resolve a file_id to a downloadable `file_path` (grammY `bot.api.getFile`). */
|
|
29
|
+
getFile(fileId: string): Promise<{
|
|
30
|
+
file_path?: string;
|
|
31
|
+
file_unique_id?: string;
|
|
32
|
+
file_size?: number;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
export interface DownloadTelegramMediaArgs {
|
|
36
|
+
/** The grammY file API (`bot.api`). */
|
|
37
|
+
bot: TelegramBotFileApi;
|
|
38
|
+
/** The attachment's `file_id` (from `resolveInboundMediaFileId`). */
|
|
39
|
+
fileId: string;
|
|
40
|
+
/** Brigade media kind — drives the default extension + the returned `kind`. */
|
|
41
|
+
kind: InboundMediaAttachment["kind"];
|
|
42
|
+
/** The Bot API token — needed to build the file download URL. NEVER logged. */
|
|
43
|
+
token: string;
|
|
44
|
+
/** Optional caption to carry through to the attachment. */
|
|
45
|
+
caption?: string;
|
|
46
|
+
/** Optional original filename (documents). */
|
|
47
|
+
fileName?: string;
|
|
48
|
+
/** Injectable fetch (defaults to global fetch) — lets tests stub the download. */
|
|
49
|
+
fetchImpl?: typeof fetch;
|
|
50
|
+
/** Logger so a failed download logs without crashing the inbound flow. */
|
|
51
|
+
log?: (msg: string, meta?: Record<string, unknown>) => void;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Download one inbound attachment to disk and return its normalized descriptor,
|
|
55
|
+
* or `null` when the file couldn't be fetched (too big / network error / no
|
|
56
|
+
* path). Never throws — a download glitch must not break message delivery.
|
|
57
|
+
*/
|
|
58
|
+
export declare function downloadTelegramMedia(args: DownloadTelegramMediaArgs): Promise<InboundMediaAttachment | null>;
|
|
59
|
+
/**
|
|
60
|
+
* Wrap a local file path (or Buffer) in grammY's `InputFile` for an outbound
|
|
61
|
+
* send, after running the path through Brigade's outbound media-path guard.
|
|
62
|
+
* Throws a clear operator-facing error when the guard refuses the path (the
|
|
63
|
+
* `send_media` tool surfaces it). grammY is lazy-imported so this file never
|
|
64
|
+
* forces the dependency at module load.
|
|
65
|
+
*/
|
|
66
|
+
export declare function buildTelegramInputFile(media: OutboundMedia): Promise<unknown>;
|
|
67
|
+
export { MAX_BYTES as TELEGRAM_MEDIA_MAX_BYTES };
|
|
68
|
+
//# sourceMappingURL=media.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../../../../src/agents/channels/telegram/media.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAUH,OAAO,EAEN,KAAK,sBAAsB,EAC3B,KAAK,aAAa,EAClB,MAAM,WAAW,CAAC;AAInB;;;;GAIG;AACH,QAAA,MAAM,SAAS,QAAmB,CAAC;AAKnC,qFAAqF;AACrF,MAAM,WAAW,kBAAkB;IAClC,kFAAkF;IAClF,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,cAAc,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACtG;AAuCD,MAAM,WAAW,yBAAyB;IACzC,uCAAuC;IACvC,GAAG,EAAE,kBAAkB,CAAC;IACxB,qEAAqE;IACrE,MAAM,EAAE,MAAM,CAAC;IACf,+EAA+E;IAC/E,IAAI,EAAE,sBAAsB,CAAC,MAAM,CAAC,CAAC;IACrC,+EAA+E;IAC/E,KAAK,EAAE,MAAM,CAAC;IACd,2DAA2D;IAC3D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kFAAkF;IAClF,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB,0EAA0E;IAC1E,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;CAC5D;AAED;;;;GAIG;AACH,wBAAsB,qBAAqB,CAAC,IAAI,EAAE,yBAAyB,GAAG,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC,CA8CnH;AAED;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,CASnF;AAED,OAAO,EAAE,SAAS,IAAI,wBAAwB,EAAE,CAAC"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram media helpers — inbound download + outbound InputFile construction.
|
|
3
|
+
*
|
|
4
|
+
* INBOUND: Telegram doesn't push file bytes; it pushes a `file_id`. To get the
|
|
5
|
+
* bytes we call `getFile(file_id)` (returns a short-lived `file_path`) then
|
|
6
|
+
* download `https://api.telegram.org/file/bot<token>/<file_path>`. Bytes are
|
|
7
|
+
* saved under `~/.brigade/channels/telegram/media/<YYYY-MM-DD>/<fileUid>.<ext>`
|
|
8
|
+
* so the agent can `read` the attachment by path. In convex mode the cache
|
|
9
|
+
* relocates to the OS cache dir (never under ~/.brigade, to respect the
|
|
10
|
+
* strict-zero guard).
|
|
11
|
+
*
|
|
12
|
+
* OUTBOUND: `buildTelegramInputFile` wraps a local path / Buffer in grammY's
|
|
13
|
+
* `InputFile`, after running it through Brigade's outbound media-path guard so
|
|
14
|
+
* a prompt-injected "send ~/.ssh/id_rsa" can't exfiltrate a secret.
|
|
15
|
+
*
|
|
16
|
+
* grammY is lazy-imported (only `InputFile` is needed, and only on the outbound
|
|
17
|
+
* path) so a non-Telegram boot never pays for the dependency.
|
|
18
|
+
*/
|
|
19
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
20
|
+
import path from "node:path";
|
|
21
|
+
import { resolveChannelStateDir, resolveOsCacheDir } from "../../../config/paths.js";
|
|
22
|
+
import { tryGetRuntimeContext } from "../../../storage/runtime-context.js";
|
|
23
|
+
// Channel SDK barrel — the outbound-media exfil guard + the OutboundMedia type
|
|
24
|
+
// All contract types come from the channel SDK barrel so the channel is built
|
|
25
|
+
// entirely on `../sdk.js`.
|
|
26
|
+
import { validateOutboundMediaPath, } from "../sdk.js";
|
|
27
|
+
const CHANNEL_ID = "telegram";
|
|
28
|
+
/**
|
|
29
|
+
* Telegram Bot API download cap is 20 MB; keep a defensive ceiling slightly
|
|
30
|
+
* under it. Anything larger is skipped (the message still reaches the agent
|
|
31
|
+
* without the attachment).
|
|
32
|
+
*/
|
|
33
|
+
const MAX_BYTES = 20 * 1024 * 1024;
|
|
34
|
+
/** Public Telegram Bot API base (file downloads hang off `/file/bot<token>/…`). */
|
|
35
|
+
const TELEGRAM_API_BASE = "https://api.telegram.org";
|
|
36
|
+
/** YYYY-MM-DD (UTC) bucket — stable filename grouping for grep / review. */
|
|
37
|
+
function dayBucket() {
|
|
38
|
+
const d = new Date();
|
|
39
|
+
const pad = (x) => String(x).padStart(2, "0");
|
|
40
|
+
return `${d.getUTCFullYear()}-${pad(d.getUTCMonth() + 1)}-${pad(d.getUTCDate())}`;
|
|
41
|
+
}
|
|
42
|
+
/** Derive a file extension from a Telegram `file_path` (it usually has one). */
|
|
43
|
+
function extFromFilePath(filePath, kind) {
|
|
44
|
+
if (filePath) {
|
|
45
|
+
const ext = path.extname(filePath).replace(/^\./, "").toLowerCase();
|
|
46
|
+
if (ext && /^[a-z0-9]+$/.test(ext))
|
|
47
|
+
return ext;
|
|
48
|
+
}
|
|
49
|
+
// Sensible default by kind when the path carried none.
|
|
50
|
+
switch (kind) {
|
|
51
|
+
case "image":
|
|
52
|
+
return "jpg";
|
|
53
|
+
case "video":
|
|
54
|
+
return "mp4";
|
|
55
|
+
case "voice":
|
|
56
|
+
return "ogg";
|
|
57
|
+
case "audio":
|
|
58
|
+
return "mp3";
|
|
59
|
+
case "sticker":
|
|
60
|
+
return "webp";
|
|
61
|
+
default:
|
|
62
|
+
return "bin";
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** Where downloaded media lands — OS cache in convex mode, channel-state dir otherwise. */
|
|
66
|
+
function mediaBaseDir() {
|
|
67
|
+
return tryGetRuntimeContext()?.mode === "convex"
|
|
68
|
+
? path.join(resolveOsCacheDir(), "channels", CHANNEL_ID)
|
|
69
|
+
: resolveChannelStateDir(CHANNEL_ID);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Download one inbound attachment to disk and return its normalized descriptor,
|
|
73
|
+
* or `null` when the file couldn't be fetched (too big / network error / no
|
|
74
|
+
* path). Never throws — a download glitch must not break message delivery.
|
|
75
|
+
*/
|
|
76
|
+
export async function downloadTelegramMedia(args) {
|
|
77
|
+
const { bot, fileId, kind, token, log } = args;
|
|
78
|
+
const doFetch = args.fetchImpl ?? fetch;
|
|
79
|
+
try {
|
|
80
|
+
const file = await bot.getFile(fileId);
|
|
81
|
+
const filePath = file?.file_path;
|
|
82
|
+
if (!filePath) {
|
|
83
|
+
log?.("telegram media skipped — getFile returned no file_path", { kind });
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
if (typeof file.file_size === "number" && file.file_size > MAX_BYTES) {
|
|
87
|
+
log?.("telegram media skipped — exceeds size cap", { kind, bytes: file.file_size, cap: MAX_BYTES });
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
const url = `${TELEGRAM_API_BASE}/file/bot${token}/${filePath}`;
|
|
91
|
+
const res = await doFetch(url);
|
|
92
|
+
if (!res.ok) {
|
|
93
|
+
log?.("telegram media download failed", { kind, status: res.status });
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
const buf = Buffer.from(await res.arrayBuffer());
|
|
97
|
+
if (buf.length === 0)
|
|
98
|
+
return null;
|
|
99
|
+
if (buf.length > MAX_BYTES) {
|
|
100
|
+
log?.("telegram media skipped — exceeds size cap", { kind, bytes: buf.length, cap: MAX_BYTES });
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
const dir = path.join(mediaBaseDir(), "media", dayBucket());
|
|
104
|
+
mkdirSync(dir, { recursive: true });
|
|
105
|
+
// file_unique_id is stable across re-deliveries; use it as the filename so
|
|
106
|
+
// the same media resolves idempotently. Fall back to file_id.
|
|
107
|
+
const baseName = (file.file_unique_id || fileId).replace(/[^A-Za-z0-9_-]/g, "_");
|
|
108
|
+
const dest = path.join(dir, `${baseName}.${extFromFilePath(filePath, kind)}`);
|
|
109
|
+
writeFileSync(dest, buf, { mode: 0o600 });
|
|
110
|
+
return {
|
|
111
|
+
kind,
|
|
112
|
+
path: dest,
|
|
113
|
+
fileName: args.fileName,
|
|
114
|
+
caption: args.caption,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
catch (err) {
|
|
118
|
+
log?.("telegram media download failed", {
|
|
119
|
+
kind,
|
|
120
|
+
error: err instanceof Error ? err.message : String(err),
|
|
121
|
+
});
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Wrap a local file path (or Buffer) in grammY's `InputFile` for an outbound
|
|
127
|
+
* send, after running the path through Brigade's outbound media-path guard.
|
|
128
|
+
* Throws a clear operator-facing error when the guard refuses the path (the
|
|
129
|
+
* `send_media` tool surfaces it). grammY is lazy-imported so this file never
|
|
130
|
+
* forces the dependency at module load.
|
|
131
|
+
*/
|
|
132
|
+
export async function buildTelegramInputFile(media) {
|
|
133
|
+
const verdict = validateOutboundMediaPath(media.path);
|
|
134
|
+
if (!verdict.ok) {
|
|
135
|
+
throw new Error(`Telegram: ${verdict.reason ?? "refusing to attach this file"}`);
|
|
136
|
+
}
|
|
137
|
+
const { InputFile } = await import("grammy");
|
|
138
|
+
// A local filesystem path — grammY streams it from disk. A filename override
|
|
139
|
+
// (documents) is honoured when provided.
|
|
140
|
+
return new InputFile(media.path, media.fileName);
|
|
141
|
+
}
|
|
142
|
+
export { MAX_BYTES as TELEGRAM_MEDIA_MAX_BYTES };
|
|
143
|
+
//# sourceMappingURL=media.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.js","sourceRoot":"","sources":["../../../../src/agents/channels/telegram/media.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AACrF,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAC3E,+EAA+E;AAC/E,8EAA8E;AAC9E,2BAA2B;AAC3B,OAAO,EACN,yBAAyB,GAGzB,MAAM,WAAW,CAAC;AAEnB,MAAM,UAAU,GAAG,UAAU,CAAC;AAE9B;;;;GAIG;AACH,MAAM,SAAS,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAEnC,mFAAmF;AACnF,MAAM,iBAAiB,GAAG,0BAA0B,CAAC;AAQrD,4EAA4E;AAC5E,SAAS,SAAS;IACjB,MAAM,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;IACrB,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACtD,OAAO,GAAG,CAAC,CAAC,cAAc,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,EAAE,CAAC;AACnF,CAAC;AAED,gFAAgF;AAChF,SAAS,eAAe,CAAC,QAA4B,EAAE,IAAoC;IAC1F,IAAI,QAAQ,EAAE,CAAC;QACd,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO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
|
2
|
+
* Telegram extension module.
|
|
3
|
+
*
|
|
4
|
+
* Registers the Telegram channel adapter through the seam. The loader gates it
|
|
5
|
+
* by the usual extension config (`extensions.disabled` / `entries`), and the
|
|
6
|
+
* adapter itself only starts when `channels.telegram.enabled` is true AND a bot
|
|
7
|
+
* token resolves — so bundling this module is inert until the operator opts in.
|
|
8
|
+
*
|
|
9
|
+
* In WEBHOOK transport mode (`channels.telegram.mode: "webhook"`) the module
|
|
10
|
+
* ALSO registers a gateway HTTP route that receives Telegram's update POSTs and
|
|
11
|
+
* feeds them into the started adapter (after verifying the secret-token header).
|
|
12
|
+
* Polling mode (the default) registers no HTTP surface.
|
|
13
|
+
*/
|
|
14
|
+
export declare const telegramModule: import("../sdk.js").BrigadeModule;
|
|
15
|
+
//# sourceMappingURL=module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../../src/agents/channels/telegram/module.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAOH,eAAO,MAAM,cAAc,mCAmBzB,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram extension module.
|
|
3
|
+
*
|
|
4
|
+
* Registers the Telegram channel adapter through the seam. The loader gates it
|
|
5
|
+
* by the usual extension config (`extensions.disabled` / `entries`), and the
|
|
6
|
+
* adapter itself only starts when `channels.telegram.enabled` is true AND a bot
|
|
7
|
+
* token resolves — so bundling this module is inert until the operator opts in.
|
|
8
|
+
*
|
|
9
|
+
* In WEBHOOK transport mode (`channels.telegram.mode: "webhook"`) the module
|
|
10
|
+
* ALSO registers a gateway HTTP route that receives Telegram's update POSTs and
|
|
11
|
+
* feeds them into the started adapter (after verifying the secret-token header).
|
|
12
|
+
* Polling mode (the default) registers no HTTP surface.
|
|
13
|
+
*/
|
|
14
|
+
import { defineModule } from "../sdk.js";
|
|
15
|
+
import { telegramWebhookConfig } from "./account-config.js";
|
|
16
|
+
import { createTelegramAdapter } from "./adapter.js";
|
|
17
|
+
import { buildTelegramWebhookRoute } from "./webhook.js";
|
|
18
|
+
export const telegramModule = defineModule({
|
|
19
|
+
id: "telegram",
|
|
20
|
+
register(b) {
|
|
21
|
+
const adapter = createTelegramAdapter();
|
|
22
|
+
b.channel(adapter);
|
|
23
|
+
// Webhook transport: register the inbound gateway route. The route resolves
|
|
24
|
+
// the SAME started adapter to feed updates into. Gated on config so a
|
|
25
|
+
// polling (default) install exposes no inbound HTTP surface.
|
|
26
|
+
const transport = telegramWebhookConfig(b.config);
|
|
27
|
+
if (transport.mode === "webhook") {
|
|
28
|
+
b.httpRoute(buildTelegramWebhookRoute({
|
|
29
|
+
path: transport.path,
|
|
30
|
+
secretToken: transport.secretToken,
|
|
31
|
+
resolveSink: () => adapter,
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../../../src/agents/channels/telegram/module.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAwB,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAEzD,MAAM,CAAC,MAAM,cAAc,GAAG,YAAY,CAAC;IAC1C,EAAE,EAAE,UAAU;IACd,QAAQ,CAAC,CAAC;QACT,MAAM,OAAO,GAAG,qBAAqB,EAAqB,CAAC;QAC3D,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACnB,4EAA4E;QAC5E,sEAAsE;QACtE,6DAA6D;QAC7D,MAAM,SAAS,GAAG,qBAAqB,CAAC,CAAC,CAAC,MAAe,CAAC,CAAC;QAC3D,IAAI,SAAS,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAClC,CAAC,CAAC,SAAS,CACV,yBAAyB,CAAC;gBACzB,IAAI,EAAE,SAAS,CAAC,IAAI;gBACpB,WAAW,EAAE,SAAS,CAAC,WAAW;gBAClC,WAAW,EAAE,GAAG,EAAE,CAAC,OAAO;aAC1B,CAAC,CACF,CAAC;QACH,CAAC;IACF,CAAC;CACD,CAAC,CAAC"}
|