@spinabot/brigade 1.3.2 → 1.5.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.
Files changed (238) hide show
  1. package/README.md +74 -11
  2. package/convex/config.d.ts +2 -2
  3. package/convex/extensions.d.ts +2 -2
  4. package/convex/logs.d.ts +2 -2
  5. package/convex/memory.d.ts +7 -7
  6. package/convex/messages.d.ts +4 -4
  7. package/convex/schema.d.ts +17 -17
  8. package/convex/subagents.d.ts +12 -12
  9. package/dist/agents/agent-loop.d.ts +1 -0
  10. package/dist/agents/agent-loop.d.ts.map +1 -1
  11. package/dist/agents/agent-loop.js +1 -1
  12. package/dist/agents/agent-loop.js.map +1 -1
  13. package/dist/agents/channels/access-control/format-allow-from.d.ts +50 -0
  14. package/dist/agents/channels/access-control/format-allow-from.d.ts.map +1 -0
  15. package/dist/agents/channels/access-control/format-allow-from.js +64 -0
  16. package/dist/agents/channels/access-control/format-allow-from.js.map +1 -0
  17. package/dist/agents/channels/access-control/index.d.ts +2 -1
  18. package/dist/agents/channels/access-control/index.d.ts.map +1 -1
  19. package/dist/agents/channels/access-control/index.js +2 -1
  20. package/dist/agents/channels/access-control/index.js.map +1 -1
  21. package/dist/agents/channels/access-control/store.d.ts +15 -0
  22. package/dist/agents/channels/access-control/store.d.ts.map +1 -1
  23. package/dist/agents/channels/access-control/store.js +44 -1
  24. package/dist/agents/channels/access-control/store.js.map +1 -1
  25. package/dist/agents/channels/bundled-channel-metas.d.ts +26 -0
  26. package/dist/agents/channels/bundled-channel-metas.d.ts.map +1 -0
  27. package/dist/agents/channels/bundled-channel-metas.js +44 -0
  28. package/dist/agents/channels/bundled-channel-metas.js.map +1 -0
  29. package/dist/agents/channels/channel-messaging-registry.d.ts +130 -0
  30. package/dist/agents/channels/channel-messaging-registry.d.ts.map +1 -0
  31. package/dist/agents/channels/channel-messaging-registry.js +211 -0
  32. package/dist/agents/channels/channel-messaging-registry.js.map +1 -0
  33. package/dist/agents/channels/channel-meta-registry.d.ts +60 -0
  34. package/dist/agents/channels/channel-meta-registry.d.ts.map +1 -0
  35. package/dist/agents/channels/channel-meta-registry.js +128 -0
  36. package/dist/agents/channels/channel-meta-registry.js.map +1 -0
  37. package/dist/agents/channels/channel-security-registry.d.ts +138 -0
  38. package/dist/agents/channels/channel-security-registry.d.ts.map +1 -0
  39. package/dist/agents/channels/channel-security-registry.js +265 -0
  40. package/dist/agents/channels/channel-security-registry.js.map +1 -0
  41. package/dist/agents/channels/exposure.d.ts +44 -0
  42. package/dist/agents/channels/exposure.d.ts.map +1 -0
  43. package/dist/agents/channels/exposure.js +48 -0
  44. package/dist/agents/channels/exposure.js.map +1 -0
  45. package/dist/agents/channels/general-callback.d.ts +25 -0
  46. package/dist/agents/channels/general-callback.d.ts.map +1 -0
  47. package/dist/agents/channels/general-callback.js +31 -0
  48. package/dist/agents/channels/general-callback.js.map +1 -0
  49. package/dist/agents/channels/inbound-pipeline.d.ts +9 -0
  50. package/dist/agents/channels/inbound-pipeline.d.ts.map +1 -1
  51. package/dist/agents/channels/inbound-pipeline.js +429 -39
  52. package/dist/agents/channels/inbound-pipeline.js.map +1 -1
  53. package/dist/agents/channels/markdown-capability.d.ts +44 -0
  54. package/dist/agents/channels/markdown-capability.d.ts.map +1 -0
  55. package/dist/agents/channels/markdown-capability.js +66 -0
  56. package/dist/agents/channels/markdown-capability.js.map +1 -0
  57. package/dist/agents/channels/sdk.d.ts +170 -10
  58. package/dist/agents/channels/sdk.d.ts.map +1 -1
  59. package/dist/agents/channels/sdk.js +138 -6
  60. package/dist/agents/channels/sdk.js.map +1 -1
  61. package/dist/agents/channels/telegram/account-config.d.ts +41 -0
  62. package/dist/agents/channels/telegram/account-config.d.ts.map +1 -1
  63. package/dist/agents/channels/telegram/account-config.js +79 -0
  64. package/dist/agents/channels/telegram/account-config.js.map +1 -1
  65. package/dist/agents/channels/telegram/adapter.d.ts +6 -0
  66. package/dist/agents/channels/telegram/adapter.d.ts.map +1 -1
  67. package/dist/agents/channels/telegram/adapter.js +185 -6
  68. package/dist/agents/channels/telegram/adapter.js.map +1 -1
  69. package/dist/agents/channels/telegram/allowed-updates.d.ts +14 -5
  70. package/dist/agents/channels/telegram/allowed-updates.d.ts.map +1 -1
  71. package/dist/agents/channels/telegram/allowed-updates.js +8 -4
  72. package/dist/agents/channels/telegram/allowed-updates.js.map +1 -1
  73. package/dist/agents/channels/telegram/connection.d.ts +118 -1
  74. package/dist/agents/channels/telegram/connection.d.ts.map +1 -1
  75. package/dist/agents/channels/telegram/connection.js +380 -8
  76. package/dist/agents/channels/telegram/connection.js.map +1 -1
  77. package/dist/agents/channels/telegram/draft-stream.d.ts +98 -0
  78. package/dist/agents/channels/telegram/draft-stream.d.ts.map +1 -0
  79. package/dist/agents/channels/telegram/draft-stream.js +222 -0
  80. package/dist/agents/channels/telegram/draft-stream.js.map +1 -0
  81. package/dist/agents/channels/telegram/format.d.ts +17 -0
  82. package/dist/agents/channels/telegram/format.d.ts.map +1 -1
  83. package/dist/agents/channels/telegram/format.js +36 -0
  84. package/dist/agents/channels/telegram/format.js.map +1 -1
  85. package/dist/agents/channels/telegram/inbound-extras.d.ts +27 -2
  86. package/dist/agents/channels/telegram/inbound-extras.d.ts.map +1 -1
  87. package/dist/agents/channels/telegram/inbound-extras.js +134 -7
  88. package/dist/agents/channels/telegram/inbound-extras.js.map +1 -1
  89. package/dist/agents/channels/telegram/inline-keyboard.d.ts +36 -0
  90. package/dist/agents/channels/telegram/inline-keyboard.d.ts.map +1 -0
  91. package/dist/agents/channels/telegram/inline-keyboard.js +62 -0
  92. package/dist/agents/channels/telegram/inline-keyboard.js.map +1 -0
  93. package/dist/agents/channels/telegram/media.d.ts +8 -0
  94. package/dist/agents/channels/telegram/media.d.ts.map +1 -1
  95. package/dist/agents/channels/telegram/media.js +30 -2
  96. package/dist/agents/channels/telegram/media.js.map +1 -1
  97. package/dist/agents/channels/telegram/plugin.d.ts.map +1 -1
  98. package/dist/agents/channels/telegram/plugin.js +7 -11
  99. package/dist/agents/channels/telegram/plugin.js.map +1 -1
  100. package/dist/agents/channels/telegram/reasoning-lane.d.ts +41 -0
  101. package/dist/agents/channels/telegram/reasoning-lane.d.ts.map +1 -0
  102. package/dist/agents/channels/telegram/reasoning-lane.js +67 -0
  103. package/dist/agents/channels/telegram/reasoning-lane.js.map +1 -0
  104. package/dist/agents/channels/telegram/socks-dispatcher.d.ts +32 -0
  105. package/dist/agents/channels/telegram/socks-dispatcher.d.ts.map +1 -0
  106. package/dist/agents/channels/telegram/socks-dispatcher.js +97 -0
  107. package/dist/agents/channels/telegram/socks-dispatcher.js.map +1 -0
  108. package/dist/agents/channels/types.adapters.d.ts +137 -4
  109. package/dist/agents/channels/types.adapters.d.ts.map +1 -1
  110. package/dist/agents/channels/types.adapters.js +2 -2
  111. package/dist/agents/channels/types.core.d.ts +26 -2
  112. package/dist/agents/channels/types.core.d.ts.map +1 -1
  113. package/dist/agents/channels/types.plugin.d.ts +25 -7
  114. package/dist/agents/channels/types.plugin.d.ts.map +1 -1
  115. package/dist/agents/channels/types.plugin.js +6 -5
  116. package/dist/agents/channels/types.plugin.js.map +1 -1
  117. package/dist/agents/channels/whatsapp/adapter.d.ts +8 -0
  118. package/dist/agents/channels/whatsapp/adapter.d.ts.map +1 -1
  119. package/dist/agents/channels/whatsapp/adapter.js +7 -4
  120. package/dist/agents/channels/whatsapp/adapter.js.map +1 -1
  121. package/dist/agents/channels/whatsapp/connection.d.ts +24 -2
  122. package/dist/agents/channels/whatsapp/connection.d.ts.map +1 -1
  123. package/dist/agents/channels/whatsapp/connection.js +26 -5
  124. package/dist/agents/channels/whatsapp/connection.js.map +1 -1
  125. package/dist/agents/channels/whatsapp/plugin.d.ts.map +1 -1
  126. package/dist/agents/channels/whatsapp/plugin.js +6 -10
  127. package/dist/agents/channels/whatsapp/plugin.js.map +1 -1
  128. package/dist/agents/extensions/activation-planner.d.ts +125 -0
  129. package/dist/agents/extensions/activation-planner.d.ts.map +1 -0
  130. package/dist/agents/extensions/activation-planner.js +221 -0
  131. package/dist/agents/extensions/activation-planner.js.map +1 -0
  132. package/dist/agents/extensions/diagnose.d.ts +84 -0
  133. package/dist/agents/extensions/diagnose.d.ts.map +1 -0
  134. package/dist/agents/extensions/diagnose.js +123 -0
  135. package/dist/agents/extensions/diagnose.js.map +1 -0
  136. package/dist/agents/extensions/discovery.d.ts +85 -7
  137. package/dist/agents/extensions/discovery.d.ts.map +1 -1
  138. package/dist/agents/extensions/discovery.js +200 -15
  139. package/dist/agents/extensions/discovery.js.map +1 -1
  140. package/dist/agents/extensions/index.d.ts +3 -2
  141. package/dist/agents/extensions/index.d.ts.map +1 -1
  142. package/dist/agents/extensions/index.js +3 -2
  143. package/dist/agents/extensions/index.js.map +1 -1
  144. package/dist/agents/extensions/install-scan.d.ts +63 -0
  145. package/dist/agents/extensions/install-scan.d.ts.map +1 -0
  146. package/dist/agents/extensions/install-scan.js +201 -0
  147. package/dist/agents/extensions/install-scan.js.map +1 -0
  148. package/dist/agents/extensions/install.d.ts +135 -0
  149. package/dist/agents/extensions/install.d.ts.map +1 -0
  150. package/dist/agents/extensions/install.js +414 -0
  151. package/dist/agents/extensions/install.js.map +1 -0
  152. package/dist/agents/extensions/loader.d.ts +13 -2
  153. package/dist/agents/extensions/loader.d.ts.map +1 -1
  154. package/dist/agents/extensions/loader.js +126 -13
  155. package/dist/agents/extensions/loader.js.map +1 -1
  156. package/dist/agents/extensions/registry.d.ts +109 -0
  157. package/dist/agents/extensions/registry.d.ts.map +1 -1
  158. package/dist/agents/extensions/registry.js +172 -0
  159. package/dist/agents/extensions/registry.js.map +1 -1
  160. package/dist/agents/extensions/sdk-alias.d.ts +45 -0
  161. package/dist/agents/extensions/sdk-alias.d.ts.map +1 -0
  162. package/dist/agents/extensions/sdk-alias.js +94 -0
  163. package/dist/agents/extensions/sdk-alias.js.map +1 -0
  164. package/dist/agents/extensions/types.d.ts +166 -1
  165. package/dist/agents/extensions/types.d.ts.map +1 -1
  166. package/dist/agents/extensions/types.js.map +1 -1
  167. package/dist/agents/tools/composio-tool.d.ts +9 -1
  168. package/dist/agents/tools/composio-tool.d.ts.map +1 -1
  169. package/dist/agents/tools/composio-tool.js +68 -4
  170. package/dist/agents/tools/composio-tool.js.map +1 -1
  171. package/dist/agents/tools/message-action-tool.d.ts +6 -1
  172. package/dist/agents/tools/message-action-tool.d.ts.map +1 -1
  173. package/dist/agents/tools/message-action-tool.js +52 -2
  174. package/dist/agents/tools/message-action-tool.js.map +1 -1
  175. package/dist/agents/tools/send-message-tool.d.ts +1 -0
  176. package/dist/agents/tools/send-message-tool.d.ts.map +1 -1
  177. package/dist/agents/tools/send-message-tool.js +56 -1
  178. package/dist/agents/tools/send-message-tool.js.map +1 -1
  179. package/dist/buildstamp.json +1 -1
  180. package/dist/channel-sdk.d.ts +28 -0
  181. package/dist/channel-sdk.d.ts.map +1 -0
  182. package/dist/channel-sdk.js +28 -0
  183. package/dist/channel-sdk.js.map +1 -0
  184. package/dist/cli/commands/channels.d.ts.map +1 -1
  185. package/dist/cli/commands/channels.js +8 -8
  186. package/dist/cli/commands/channels.js.map +1 -1
  187. package/dist/cli/commands/connect.d.ts +8 -11
  188. package/dist/cli/commands/connect.d.ts.map +1 -1
  189. package/dist/cli/commands/connect.js +157 -17
  190. package/dist/cli/commands/connect.js.map +1 -1
  191. package/dist/cli/commands/convex-cmd.d.ts +2 -1
  192. package/dist/cli/commands/convex-cmd.d.ts.map +1 -1
  193. package/dist/cli/commands/convex-cmd.js +79 -6
  194. package/dist/cli/commands/convex-cmd.js.map +1 -1
  195. package/dist/cli/commands/doctor.d.ts.map +1 -1
  196. package/dist/cli/commands/doctor.js +64 -0
  197. package/dist/cli/commands/doctor.js.map +1 -1
  198. package/dist/cli/commands/extensions.d.ts +46 -0
  199. package/dist/cli/commands/extensions.d.ts.map +1 -0
  200. package/dist/cli/commands/extensions.js +578 -0
  201. package/dist/cli/commands/extensions.js.map +1 -0
  202. package/dist/cli/commands/pairing.d.ts.map +1 -1
  203. package/dist/cli/commands/pairing.js +16 -2
  204. package/dist/cli/commands/pairing.js.map +1 -1
  205. package/dist/cli/commands/update.d.ts +17 -0
  206. package/dist/cli/commands/update.d.ts.map +1 -0
  207. package/dist/cli/commands/update.js +104 -0
  208. package/dist/cli/commands/update.js.map +1 -0
  209. package/dist/cli/program/build-program.d.ts.map +1 -1
  210. package/dist/cli/program/build-program.js +114 -1
  211. package/dist/cli/program/build-program.js.map +1 -1
  212. package/dist/config/paths.d.ts +1 -0
  213. package/dist/config/paths.d.ts.map +1 -1
  214. package/dist/config/paths.js +9 -0
  215. package/dist/config/paths.js.map +1 -1
  216. package/dist/core/server.d.ts.map +1 -1
  217. package/dist/core/server.js +134 -2
  218. package/dist/core/server.js.map +1 -1
  219. package/dist/protocol.d.ts +25 -0
  220. package/dist/protocol.d.ts.map +1 -1
  221. package/dist/protocol.js.map +1 -1
  222. package/dist/system-prompt/assembler.d.ts.map +1 -1
  223. package/dist/system-prompt/assembler.js +17 -0
  224. package/dist/system-prompt/assembler.js.map +1 -1
  225. package/dist/system-prompt/identity-defaults.d.ts +28 -0
  226. package/dist/system-prompt/identity-defaults.d.ts.map +1 -1
  227. package/dist/system-prompt/identity-defaults.js +47 -0
  228. package/dist/system-prompt/identity-defaults.js.map +1 -1
  229. package/dist/ui/editor.d.ts.map +1 -1
  230. package/dist/ui/editor.js +1 -0
  231. package/dist/ui/editor.js.map +1 -1
  232. package/dist/version.d.ts +4 -3
  233. package/dist/version.d.ts.map +1 -1
  234. package/dist/version.js +27 -5
  235. package/dist/version.js.map +1 -1
  236. package/package.json +21 -4
  237. package/scripts/build-done.mjs +11 -2
  238. package/scripts/convex-dev.mjs +28 -2
@@ -1 +1 @@
1
- {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../../../src/agents/channels/telegram/connection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAGN,KAAK,sBAAsB,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C;IAC1C,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAmBD,sEAAsE;AACtE,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAG5D;AAED,0EAA0E;AAC1E,wBAAgB,4BAA4B,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAGlE;AAED,mEAAmE;AACnE,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAOvE;AAID,wBAAsB,eAAe,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAyjC5F"}
@@ -33,9 +33,12 @@
33
33
  * subscribed — Brigade's approvals are central TEXT replies handled in
34
34
  * `inbound-pipeline.ts`, so `allowed_updates` only needs message updates.
35
35
  */
36
- import { createDedupeCache, nextBackoffDelay, } from "../sdk.js";
36
+ import { chunkText, createDedupeCache, nextBackoffDelay, } from "../sdk.js";
37
+ import { maskProxyUrl } from "./account-config.js";
38
+ import { splitTelegramCaption, TELEGRAM_CAPTION_LIMIT } from "./format.js";
37
39
  import { resolveTelegramAllowedUpdates } from "./allowed-updates.js";
38
- import { buildTelegramSenderName, extractTelegramMentions, extractTelegramReplyContext, extractTelegramText, hasInboundMedia, resolveInboundMediaFileId, resolveInboundMediaKind, telegramChatType, telegramThreadId, } from "./inbound-extras.js";
40
+ import { buildSocksDispatcher, isSocksProxyScheme } from "./socks-dispatcher.js";
41
+ import { buildTelegramSenderName, extractTelegramForwardContext, extractTelegramMentions, extractTelegramReplyContext, extractTelegramText, hasInboundMedia, resolveInboundMediaFileId, resolveInboundMediaKind, telegramChatType, telegramThreadId, } from "./inbound-extras.js";
39
42
  import { downloadTelegramMedia } from "./media.js";
40
43
  // All contract types — `OutboundMedia`, `InboundMediaAttachment`,
41
44
  // `InboundReplyContext` — now come from the channel SDK barrel (imported above),
@@ -64,6 +67,8 @@ export function telegramBackoffDelay(attempt) {
64
67
  jitter: RECONNECT_JITTER,
65
68
  });
66
69
  }
70
+ /** Telegram's hard limit on a single text message body (UTF-16 code units). */
71
+ const TELEGRAM_MESSAGE_LIMIT = 4096;
67
72
  /* ───────────────────────── error classification ───────────────────────── */
68
73
  /** Pull a Telegram `error_code` off any thrown shape (grammY GrammyError or raw). */
69
74
  function errorCode(err) {
@@ -120,6 +125,52 @@ export async function connectTelegram(args) {
120
125
  }
121
126
  args.log(redactedMsg, redactedMeta);
122
127
  };
128
+ // ── resolve proxy (optional) ──
129
+ // A configured proxy reroutes EVERY Telegram API call (getMe / getUpdates /
130
+ // sends) through an http(s) proxy — the fix for networks where
131
+ // `api.telegram.org` is blocked. We attach an `undici` ProxyAgent as grammY's
132
+ // fetch dispatcher; grammY uses Node's global `fetch` (undici) under the hood,
133
+ // so `client.baseFetchConfig.dispatcher` is the clean, dep-free seam. No proxy
134
+ // → the dispatcher stays undefined and the Bot is built exactly as before.
135
+ const proxyUrl = (args.proxyUrl ?? "").trim();
136
+ let proxyDispatcher;
137
+ if (proxyUrl) {
138
+ const scheme = /^([a-z][a-z0-9+.-]*):\/\//i.exec(proxyUrl)?.[1]?.toLowerCase();
139
+ if (isSocksProxyScheme(scheme)) {
140
+ // undici's ProxyAgent only speaks HTTP CONNECT — it cannot tunnel SOCKS.
141
+ // Build a plain undici `Agent` whose `connect` hook opens the socket
142
+ // through the SOCKS proxy (via the `socks` package) and upgrades it to
143
+ // TLS for the https `api.telegram.org` origin. grammY honours the
144
+ // resulting dispatcher exactly like the HTTP(S) ProxyAgent.
145
+ try {
146
+ proxyDispatcher = await buildSocksDispatcher(proxyUrl);
147
+ safeLog("telegram routing through SOCKS proxy", { account: accountId, proxy: maskProxyUrl(proxyUrl) });
148
+ }
149
+ catch (err) {
150
+ // A malformed proxy URL / missing module must not wedge the channel.
151
+ safeLog("telegram SOCKS proxy setup failed — connecting directly", {
152
+ account: accountId,
153
+ proxy: maskProxyUrl(proxyUrl),
154
+ error: err instanceof Error ? err.message : String(err),
155
+ });
156
+ }
157
+ }
158
+ else {
159
+ try {
160
+ const { ProxyAgent } = await import("undici");
161
+ proxyDispatcher = new ProxyAgent(proxyUrl);
162
+ safeLog("telegram routing through proxy", { account: accountId, proxy: maskProxyUrl(proxyUrl) });
163
+ }
164
+ catch (err) {
165
+ // A malformed proxy URL must not wedge the channel — log + go direct.
166
+ safeLog("telegram proxy setup failed — connecting directly", {
167
+ account: accountId,
168
+ proxy: maskProxyUrl(proxyUrl),
169
+ error: err instanceof Error ? err.message : String(err),
170
+ });
171
+ }
172
+ }
173
+ }
123
174
  // ── lazy-load grammY + runner + throttler (production path only) ──
124
175
  let buildBot;
125
176
  let buildRunner;
@@ -132,10 +183,36 @@ export async function connectTelegram(args) {
132
183
  const { run } = await import("@grammyjs/runner");
133
184
  const { apiThrottler } = await import("@grammyjs/transformer-throttler");
134
185
  buildBot = (token) => {
135
- const bot = new grammy.Bot(token);
186
+ // When a proxy dispatcher is present, hand it to grammY's fetch config so
187
+ // every API call tunnels through the proxy; otherwise build the Bot with
188
+ // no client options (byte-identical to the pre-proxy path). grammY uses
189
+ // Node's global `fetch` (undici), which honours `dispatcher` at runtime —
190
+ // the property just isn't in grammY's `baseFetchConfig` type, hence the cast.
191
+ const clientOpts = proxyDispatcher
192
+ ? { client: { baseFetchConfig: { dispatcher: proxyDispatcher } } }
193
+ : undefined;
194
+ const bot = (clientOpts
195
+ ? new grammy.Bot(token, clientOpts)
196
+ : new grammy.Bot(token));
136
197
  // Rate-limit the outbound API so a chatty agent never trips Telegram's
137
198
  // flood limits — installed on the api config as a transformer.
138
199
  bot.api.config?.use(apiThrottler());
200
+ // Honor Telegram's 429 `retry_after`: a rate-limited call sleeps the
201
+ // server-asked delay (capped at 30s) and retries instead of surfacing as
202
+ // a send failure. apiThrottler prevents most 429s proactively; this
203
+ // catches the residual ones. Bounded to 2 extra attempts so a persistent
204
+ // limit still surfaces to the caller rather than blocking forever.
205
+ bot.api.config?.use((async (prev, method, payload, signal) => {
206
+ let res = (await prev(method, payload, signal));
207
+ for (let attempt = 0; attempt < 2 && res?.ok === false && res.error_code === 429; attempt++) {
208
+ const retryAfter = res.parameters?.retry_after;
209
+ if (typeof retryAfter !== "number")
210
+ break;
211
+ await new Promise((r) => setTimeout(r, Math.min(retryAfter, 30) * 1_000));
212
+ res = (await prev(method, payload, signal));
213
+ }
214
+ return res;
215
+ }));
139
216
  return bot;
140
217
  };
141
218
  buildRunner = (bot) => run(bot, {
@@ -169,13 +246,14 @@ export async function connectTelegram(args) {
169
246
  // restart must not double-run the agent. Per-connection lifetime.
170
247
  const updateDedupe = createDedupeCache({ maxEntries: 10_000, ttlMs: 60 * 60 * 1_000 });
171
248
  /** Normalize one grammY message into the deferred-media inbound shape. */
172
- const normalize = (message) => {
249
+ const normalize = (message, opts) => {
173
250
  const chatId = String(message.chat.id);
174
251
  const text = extractTelegramText(message);
175
252
  const chatType = telegramChatType(message);
176
253
  const threadId = telegramThreadId(message);
177
254
  const mentions = extractTelegramMentions(message, selfUsername ?? undefined, selfId ?? undefined);
178
255
  const replyTo = extractTelegramReplyContext(message);
256
+ const forwarded = extractTelegramForwardContext(message);
179
257
  const fromName = buildTelegramSenderName(message);
180
258
  const fromId = typeof message.from?.id === "number" ? String(message.from.id) : chatId;
181
259
  const tsSec = typeof message.date === "number" ? message.date : 0;
@@ -213,10 +291,76 @@ export async function connectTelegram(args) {
213
291
  threadId,
214
292
  mentions: mentions.length > 0 ? mentions : undefined,
215
293
  replyTo,
294
+ ...(forwarded ? { forwarded } : {}),
295
+ ...(opts?.edited ? { edited: true } : {}),
216
296
  resolveMedia,
217
297
  raw: message,
218
298
  };
219
299
  };
300
+ /* ── album / media-group coalescing ── */
301
+ // Telegram delivers an album as N separate `message` updates that share a
302
+ // `media_group_id` and arrive within milliseconds (the caption rides on ONE
303
+ // item). Buffer them briefly and emit a SINGLE inbound carrying every
304
+ // attachment — so an album is one agent turn instead of N, and the items past
305
+ // the captioned one aren't surfaced as empty text messages.
306
+ const ALBUM_DEBOUNCE_MS = 250;
307
+ const albumBuffers = new Map();
308
+ const flushAlbum = (key) => {
309
+ const buf = albumBuffers.get(key);
310
+ if (!buf)
311
+ return;
312
+ albumBuffers.delete(key);
313
+ clearTimeout(buf.timer);
314
+ if (closed || buf.messages.length === 0)
315
+ return;
316
+ try {
317
+ // Lead = the item carrying the caption (Telegram puts it on one), else the first.
318
+ const lead = buf.messages.find((m) => typeof m.caption === "string" && m.caption.length > 0) ?? buf.messages[0];
319
+ if (!lead)
320
+ return;
321
+ const groupMessages = buf.messages;
322
+ const inbound = normalize(lead);
323
+ // Replace the single-attachment thunk with one that downloads EVERY item.
324
+ inbound.resolveMedia = async () => {
325
+ if (!bot)
326
+ return [];
327
+ const out = [];
328
+ for (const m of groupMessages) {
329
+ const fileId = resolveInboundMediaFileId(m);
330
+ const kind = resolveInboundMediaKind(m);
331
+ if (!fileId || !kind)
332
+ continue;
333
+ const att = await downloadTelegramMedia({
334
+ bot: bot.api,
335
+ fileId,
336
+ kind,
337
+ token: args.token,
338
+ caption: typeof m.caption === "string" ? m.caption : undefined,
339
+ fileName: m.document?.file_name ?? m.audio?.file_name ?? m.video?.file_name,
340
+ log: safeLog,
341
+ });
342
+ if (att)
343
+ out.push(att);
344
+ }
345
+ return out;
346
+ };
347
+ args.onMessage(inbound);
348
+ }
349
+ catch (err) {
350
+ safeLog("telegram album flush error", { error: err instanceof Error ? err.message : String(err) });
351
+ }
352
+ };
353
+ const bufferAlbumItem = (key, message) => {
354
+ const existing = albumBuffers.get(key);
355
+ if (existing) {
356
+ existing.messages.push(message);
357
+ clearTimeout(existing.timer);
358
+ existing.timer = setTimeout(() => flushAlbum(key), ALBUM_DEBOUNCE_MS);
359
+ }
360
+ else {
361
+ albumBuffers.set(key, { messages: [message], timer: setTimeout(() => flushAlbum(key), ALBUM_DEBOUNCE_MS) });
362
+ }
363
+ };
220
364
  const onUpdate = (ctx) => {
221
365
  try {
222
366
  const updateId = ctx.update?.update_id;
@@ -229,12 +373,136 @@ export async function connectTelegram(args) {
229
373
  // via getUpdates, but a linked-account self-message would carry our id).
230
374
  if (typeof message.from?.id === "number" && selfId && String(message.from.id) === selfId)
231
375
  return;
376
+ // Group → supergroup migration: the old chat is now dead and future
377
+ // messages arrive from the new supergroup id. Log it so the operator can
378
+ // rebind; the service message itself carries no content to dispatch.
379
+ const migrateTo = message.migrate_to_chat_id;
380
+ if (typeof migrateTo === "number") {
381
+ safeLog("telegram group migrated to a supergroup — rebind to keep receiving messages", {
382
+ from: String(message.chat.id),
383
+ to: String(migrateTo),
384
+ });
385
+ return;
386
+ }
387
+ // Album item → buffer + coalesce (see flushAlbum) instead of dispatching
388
+ // each photo/video of the group as its own turn.
389
+ const groupId = typeof message.media_group_id === "string" ? message.media_group_id : undefined;
390
+ if (groupId) {
391
+ bufferAlbumItem(`${message.chat.id}:${groupId}`, message);
392
+ return;
393
+ }
232
394
  args.onMessage(normalize(message));
233
395
  }
234
396
  catch (err) {
235
397
  safeLog("telegram inbound handler error", { error: err instanceof Error ? err.message : String(err) });
236
398
  }
237
399
  };
400
+ /**
401
+ * Handle an `edited_message` update. Telegram redelivers the WHOLE message
402
+ * with its new text under `edited_message`; we route it through the SAME
403
+ * `onMessage` path the original used, flagged `edited: true` (and carrying the
404
+ * edited message's own id) so the agent can see the correction. Deduped on the
405
+ * update_id like every other update.
406
+ */
407
+ const onEdited = (ctx) => {
408
+ try {
409
+ const updateId = ctx.update?.update_id;
410
+ if (typeof updateId === "number" && !updateDedupe.claim(String(updateId)))
411
+ return;
412
+ const message = ctx.editedMessage ?? ctx.update.edited_message;
413
+ if (!message)
414
+ return;
415
+ if (typeof message.from?.id === "number" && selfId && String(message.from.id) === selfId)
416
+ return;
417
+ args.onMessage(normalize(message, { edited: true }));
418
+ }
419
+ catch (err) {
420
+ safeLog("telegram edited handler error", { error: err instanceof Error ? err.message : String(err) });
421
+ }
422
+ };
423
+ /**
424
+ * Handle a `channel_post` update — a post in a Telegram channel the bot is an
425
+ * admin of. A channel post has no `from` user; we route it through `onMessage`
426
+ * treating the chat as a group (channels behave like broadcast groups) so the
427
+ * access gate + routing handle it uniformly. Bot-authored echoes are skipped.
428
+ */
429
+ const onChannelPost = (ctx) => {
430
+ try {
431
+ const updateId = ctx.update?.update_id;
432
+ if (typeof updateId === "number" && !updateDedupe.claim(String(updateId)))
433
+ return;
434
+ const post = ctx.channelPost ?? ctx.update.channel_post;
435
+ if (!post)
436
+ return;
437
+ // Channel posts carry `sender_chat` (the channel) rather than a `from`
438
+ // user. Normalize the post directly; `telegramChatType` maps the channel
439
+ // chat to "group" already via the supergroup branch only when the type is
440
+ // group/supergroup, so force the group kind on the normalized inbound.
441
+ const normalized = normalize(post);
442
+ normalized.chatType = "group";
443
+ args.onMessage(normalized);
444
+ }
445
+ catch (err) {
446
+ safeLog("telegram channel_post handler error", { error: err instanceof Error ? err.message : String(err) });
447
+ }
448
+ };
449
+ /**
450
+ * Normalize a `message_reaction` update into the inbound shape. Surfaces only
451
+ * the NEWLY-ADDED emoji(s) (diffing `old_reaction` → `new_reaction`), the
452
+ * actor, and the target message id. Reactions carry no `text`; the adapter
453
+ * synthesises a short note so the pipeline can route it. Returns null when the
454
+ * update removed reactions (nothing added) or was authored by a bot.
455
+ */
456
+ const normalizeReaction = (r) => {
457
+ if (r.user?.is_bot)
458
+ return null;
459
+ const chatId = String(r.chat.id);
460
+ const oldEmojis = new Set((r.old_reaction ?? []).filter((x) => x.type === "emoji" && x.emoji).map((x) => x.emoji));
461
+ const added = (r.new_reaction ?? [])
462
+ .filter((x) => x.type === "emoji" && x.emoji)
463
+ .map((x) => x.emoji)
464
+ .filter((e) => !oldEmojis.has(e));
465
+ if (added.length === 0)
466
+ return null; // a reaction REMOVAL — nothing to route
467
+ const fromId = typeof r.user?.id === "number" ? String(r.user.id) : chatId;
468
+ const fromName = r.user
469
+ ? [r.user.first_name, r.user.last_name].filter(Boolean).join(" ").trim() ||
470
+ (r.user.username ? `@${r.user.username}` : undefined)
471
+ : undefined;
472
+ const chatType = r.chat.type === "group" || r.chat.type === "supergroup" ? "group" : "direct";
473
+ return {
474
+ conversationId: chatId,
475
+ from: fromId,
476
+ ...(fromName ? { fromName } : {}),
477
+ text: "",
478
+ chatType,
479
+ reaction: { emojis: added, targetMessageId: String(r.message_id) },
480
+ raw: r,
481
+ };
482
+ };
483
+ /**
484
+ * Handle a `message_reaction` update. The connection normalizes it (newly-
485
+ * added emoji(s) + actor + target) and routes it through `onReaction` (the
486
+ * adapter feeds it into the SAME inbound pipeline as a synthesised note).
487
+ * No-op when the channel didn't wire `onReaction`.
488
+ */
489
+ const onReaction = (ctx) => {
490
+ try {
491
+ const updateId = ctx.update?.update_id;
492
+ if (typeof updateId === "number" && !updateDedupe.claim(String(updateId)))
493
+ return;
494
+ const r = ctx.messageReaction ?? ctx.update.message_reaction;
495
+ if (!r)
496
+ return;
497
+ const normalized = normalizeReaction(r);
498
+ if (!normalized)
499
+ return;
500
+ args.onReaction?.(normalized);
501
+ }
502
+ catch (err) {
503
+ safeLog("telegram reaction handler error", { error: err instanceof Error ? err.message : String(err) });
504
+ }
505
+ };
238
506
  /**
239
507
  * Normalize a `callback_query` (inline-button press) into the inbound shape
240
508
  * the central pipeline routes to the approval-callback path. The button's
@@ -301,6 +569,13 @@ export async function connectTelegram(args) {
301
569
  // per-update `answerCallbackQuery` helper on the ctx; the handler acks via
302
570
  // it then routes the normalized callback inbound.
303
571
  b.on("callback_query", (ctx) => void onCallbackQuery(ctx));
572
+ // Parity updates — edited messages, channel posts, and inbound reactions.
573
+ // All route through the same inbound surfaces (edits + posts → onMessage,
574
+ // reactions → onReaction). grammY only delivers these when they're in the
575
+ // requested `allowed_updates` list (see allowed-updates.ts).
576
+ b.on("edited_message", onEdited);
577
+ b.on("channel_post", onChannelPost);
578
+ b.on("message_reaction", onReaction);
304
579
  bot = b;
305
580
  // getMe first — both proves the token (401 surfaces here) and caches the
306
581
  // bot id + username the group ACL needs (+ the full identity for the probe).
@@ -345,6 +620,21 @@ export async function connectTelegram(args) {
345
620
  onUpdate({ update, message });
346
621
  return;
347
622
  }
623
+ const editedMessage = update.edited_message;
624
+ if (editedMessage) {
625
+ onEdited({ update, editedMessage });
626
+ return;
627
+ }
628
+ const channelPost = update.channel_post;
629
+ if (channelPost) {
630
+ onChannelPost({ update, channelPost });
631
+ return;
632
+ }
633
+ const messageReaction = update.message_reaction;
634
+ if (messageReaction) {
635
+ onReaction({ update, messageReaction });
636
+ return;
637
+ }
348
638
  const callbackQuery = update.callback_query;
349
639
  if (callbackQuery) {
350
640
  void onCallbackQuery({
@@ -580,6 +870,18 @@ export async function connectTelegram(args) {
580
870
  params.parse_mode = "HTML";
581
871
  if (opts?.threadId)
582
872
  params.message_thread_id = Number(opts.threadId);
873
+ if (opts?.silent)
874
+ params.disable_notification = true;
875
+ if (opts?.linkPreview === false)
876
+ params.link_preview_options = { is_disabled: true };
877
+ // Native reply: quote the target message. `allow_sending_without_reply`
878
+ // keeps the send succeeding even if the quoted message was deleted.
879
+ if (opts?.replyToMessageId) {
880
+ const replyId = Number(opts.replyToMessageId);
881
+ if (Number.isFinite(replyId)) {
882
+ params.reply_parameters = { message_id: replyId, allow_sending_without_reply: true };
883
+ }
884
+ }
583
885
  try {
584
886
  const res = await b.api.sendMessage(chatId, text, params);
585
887
  return { messageId: res.message_id };
@@ -621,10 +923,34 @@ export async function connectTelegram(args) {
621
923
  const params = {};
622
924
  if (opts?.threadId)
623
925
  params.message_thread_id = Number(opts.threadId);
624
- if (media.caption)
625
- params.caption = media.caption;
926
+ if (opts?.silent)
927
+ params.disable_notification = true;
928
+ // Telegram caps a media caption at 1024 chars; a longer one 400s the whole
929
+ // send. Split it — the head rides as the caption, the remainder is delivered
930
+ // as a follow-up text message (chunked at 4096) once the media lands, so a
931
+ // long caption is preserved instead of failing or being silently dropped.
932
+ let captionOverflow = "";
933
+ if (media.caption) {
934
+ if (media.caption.length > TELEGRAM_CAPTION_LIMIT) {
935
+ const split = splitTelegramCaption(media.caption);
936
+ params.caption = split.head;
937
+ captionOverflow = split.rest;
938
+ }
939
+ else {
940
+ params.caption = media.caption;
941
+ }
942
+ }
626
943
  const api = b.api;
944
+ // A GIF (image/gif) plays inline via sendAnimation; the kind inference maps
945
+ // .gif → "image", which would otherwise send a STATIC first frame via
946
+ // sendPhoto. Detect it here so the animation actually animates (falls back
947
+ // to the normal switch when the bot build lacks sendAnimation).
948
+ const isAnimation = media.mimeType === "image/gif" || /\.gif$/i.test(media.path);
627
949
  const send = async (p) => {
950
+ if (isAnimation && api.sendAnimation) {
951
+ await api.sendAnimation(chatId, input, p);
952
+ return;
953
+ }
628
954
  switch (media.kind) {
629
955
  case "image":
630
956
  await api.sendPhoto?.(chatId, input, p);
@@ -652,9 +978,32 @@ export async function connectTelegram(args) {
652
978
  if (opts?.threadId && /message thread not found/i.test(errorText(err))) {
653
979
  const { message_thread_id: _omit, ...rest } = params;
654
980
  await send(rest);
655
- return;
656
981
  }
657
- throw err;
982
+ else {
983
+ throw err;
984
+ }
985
+ }
986
+ // Flush any caption overflow as plain follow-up text once the media is sent.
987
+ if (captionOverflow) {
988
+ const followParams = {};
989
+ if (opts?.threadId)
990
+ followParams.message_thread_id = Number(opts.threadId);
991
+ if (opts?.silent)
992
+ followParams.disable_notification = true;
993
+ for (const chunk of chunkText(captionOverflow, { limit: TELEGRAM_MESSAGE_LIMIT })) {
994
+ try {
995
+ await b.api.sendMessage(chatId, chunk, followParams);
996
+ }
997
+ catch (err) {
998
+ if (followParams.message_thread_id && /message thread not found/i.test(errorText(err))) {
999
+ const { message_thread_id: _omit, ...rest } = followParams;
1000
+ await b.api.sendMessage(chatId, chunk, rest);
1001
+ }
1002
+ else {
1003
+ throw err;
1004
+ }
1005
+ }
1006
+ }
658
1007
  }
659
1008
  };
660
1009
  const react = async (chatId, messageId, emoji) => {
@@ -759,6 +1108,24 @@ export async function connectTelegram(args) {
759
1108
  });
760
1109
  }
761
1110
  };
1111
+ const createForumTopic = async (chatId, name, opts) => {
1112
+ const b = requireLive();
1113
+ if (!b.api.createForumTopic)
1114
+ throw new Error("Telegram: this bot build cannot create forum topics.");
1115
+ const trimmed = (name ?? "").trim();
1116
+ if (!trimmed)
1117
+ throw new Error("Telegram: a forum topic name is required.");
1118
+ // Telegram caps a forum topic name at 128 chars.
1119
+ if (trimmed.length > 128)
1120
+ throw new Error("Telegram: forum topic name must be 128 characters or fewer.");
1121
+ const extra = {};
1122
+ if (typeof opts?.iconColor === "number")
1123
+ extra.icon_color = opts.iconColor;
1124
+ if (opts?.iconCustomEmojiId?.trim())
1125
+ extra.icon_custom_emoji_id = opts.iconCustomEmojiId.trim();
1126
+ const res = await b.api.createForumTopic(chatId, trimmed, Object.keys(extra).length > 0 ? extra : undefined);
1127
+ return { threadId: String(res.message_thread_id), name: res.name ?? trimmed };
1128
+ };
762
1129
  const answerCallback = async (callbackId, text) => {
763
1130
  const b = bot;
764
1131
  if (!b || tokenInvalid || !b.api.answerCallbackQuery)
@@ -822,6 +1189,10 @@ export async function connectTelegram(args) {
822
1189
  const close = async () => {
823
1190
  closed = true;
824
1191
  connected = false;
1192
+ // Drop any pending album debounce timers so none fire after close.
1193
+ for (const buf of albumBuffers.values())
1194
+ clearTimeout(buf.timer);
1195
+ albumBuffers.clear();
825
1196
  await teardownRunner();
826
1197
  // Wait for the supervise loop to unwind, but never hang on it — teardown
827
1198
  // resolves the active runner's task() so the loop sees `closed` and
@@ -852,6 +1223,7 @@ export async function connectTelegram(args) {
852
1223
  pinMessage,
853
1224
  unpinMessage,
854
1225
  editForumTopic,
1226
+ createForumTopic,
855
1227
  answerCallback,
856
1228
  getIdentity,
857
1229
  setCommandMenu,