loopzero-gateway-telegram 0.0.0-stage → 0.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,526 @@
1
+ # Changelog
2
+
3
+ ## 0.15.0
4
+
5
+ ### Minor Changes
6
+
7
+ - c0a55b8: `MessageEvent` gains an optional `addressed` flag, set by these adapters on group and thread events whether or not `requireMention` is on, and `loopzero-gateway` adds `groupActivationHook({ mode, modeFor? })`, which blocks unaddressed group messages per chat.
8
+
9
+ ## 0.14.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 4defb5a: `InboundAudio` is read on demand: `data` is replaced by `read(): Promise<Uint8Array>` and an optional `size`. The Telegram adapter downloads a voice note on the first `read()`, so a `pre_inbound` hook that blocks the message causes no download. `withMediaUnderstanding` reads the audio only when a transcriber is configured.
14
+
15
+ ## 0.13.0
16
+
17
+ ### Minor Changes
18
+
19
+ - 73a9b87: Send errors use the shared `SendErrorCode` strings. Discord and Telegram `rate_limited` is now `rate_limit`, and Slack, Discord and Telegram `no_permission` is now `permission_denied`. A rate limit carries `retryAfterMs` when the platform reports it (Slack `retry_after`, Telegram `parameters.retry_after`, discord.js `RateLimitError`), and a permission error keeps the platform's own code in `platformCode`. The `loopzero-gateway` peer range is now `>=0.25.0`.
20
+
21
+ ## 0.12.1
22
+
23
+ ### Patch Changes
24
+
25
+ - 8585427: README status lines say "0.x, pre-1.0" instead of a hard-coded version.
26
+
27
+ ## 0.12.0
28
+
29
+ ### Minor Changes
30
+
31
+ - c395723: Accept an `apiBase` option (and `TELEGRAM_API_BASE` in the channel descriptor) for the Bot API root; voice-note downloads use the same root.
32
+
33
+ ## 0.11.0
34
+
35
+ ### Minor Changes
36
+
37
+ - 4a4c25d: Ship `ChannelDescriptor`s with env bindings for `configFromEnv`: `discordChannel` and `slackChannel` are new, and `telegramChannel` and `lineChannel` gain `env` names. `create` accepts comma-separated list strings and `"true"`/`"false"` strings.
38
+
39
+ ## 0.10.0
40
+
41
+ ### Minor Changes
42
+
43
+ - 2831ca3: Report `capabilities.maxMessageChars` from the splitter limit, and `capabilities.threads` (true for Discord, Telegram and Slack).
44
+
45
+ ## 0.9.0
46
+
47
+ ### Minor Changes
48
+
49
+ - 9c832b2: Add `AdapterCapabilities` and `BasePlatformAdapter.capabilities` (edit, attachment kinds, typing, reactions, threads, max length), derived by default. Telegram reports `image` and `audio` attachments.
50
+ - 0bc525c: Add a `requireMention` option: when true, group messages reach the handler only if they mention the bot, reply to it or are slash commands, on both the polled and the `deliver()` paths. Default false.
51
+ - 56bb1d8: Declare whether a channel's sender id is authenticated with `senderIdentity`.
52
+
53
+ ## 0.8.0
54
+
55
+ ### Minor Changes
56
+
57
+ - 4ae0506: `TelegramAdapter` takes `inbound: "webhook"`: `connect()` checks the token without starting long polling, and `disconnect()` does not call `bot.stop()`. Updates arrive through `deliver()`. The default stays `"polling"`.
58
+
59
+ ### Patch Changes
60
+
61
+ - 66646fc: A chunk (or photo caption) that Telegram refuses with a legacy Markdown parse error is now resent once as plain text, so the reply arrives and later chunks are no longer dropped.
62
+
63
+ ## 0.7.1
64
+
65
+ ### Patch Changes
66
+
67
+ - b5941b6: `sendMessage` and `editMessage` no longer throw a `TypeError` when Telegram (or a proxy) answers with an error body that has no `description`. The failure now comes back as a `SendResult` with code `telegram_<error_code>`.
68
+
69
+ ## 0.7.0
70
+
71
+ ### Minor Changes
72
+
73
+ - 00af16f: `BasePlatformAdapter` gains `react(channelId, messageId, emoji)`, which adds an emoji reaction to an inbound message. The default resolves `react_unsupported`; the Discord, Slack, Telegram and Matrix adapters implement it.
74
+
75
+ ## 0.6.0
76
+
77
+ ### Minor Changes
78
+
79
+ - 458c34c: Wire channels from descriptors, and keep the channels that connect when another cannot.
80
+
81
+ `loopzero-gateway` exports `createChannels` and the types `ChannelDescriptor`,
82
+ `ChannelConfigField`, `ChannelWebhook`, `WebhookRequest`, `IngestResult`, `ChannelEntry`,
83
+ `ChannelRejection` and `CreateChannelsResult`. `createChannels(entries)` builds an adapter per
84
+ entry and returns `{ adapters, rejected }`: an entry whose required field is absent, `null` or
85
+ `""` is rejected with a `GatewayConfigurationError` coded `missing_required_config` naming the
86
+ keys, and a configuration error thrown by the descriptor's `create` is rejected the same way. Any
87
+ other error propagates. It connects nothing and makes no network call.
88
+
89
+ `GatewayRunner` accepts `connectFailure: "rollback" | "isolate"` (exported as `ConnectFailure`),
90
+ and `StartResult` is exported.
91
+ The default, `"rollback"`, is unchanged: one failed connect disconnects the adapters that did
92
+ connect and rejects `start()`. Under `"isolate"`, `start()` connects every adapter, wires inbound
93
+ only for the ones that connected, and reports the rest with a redacted reason.
94
+
95
+ `start()` now resolves a `StartResult` (`{ connected, failed }`) instead of `void`, under both
96
+ values. This is a type change: code that awaits `start()` and ignores the value is unaffected,
97
+ but a structural type declaring `start(): Promise<void>` that a `GatewayRunner` is assigned to
98
+ fails with TS2322, and a subclass overriding `start()` with that signature fails with TS2416.
99
+
100
+ `loopzero-gateway-telegram` exports `telegramChannel`, a socket channel whose config has a
101
+ required, secret `token` and an optional `allowedUsers`, and a `ConfigurationError` (a
102
+ `GatewayConfigurationError` with the `gateway-telegram` prefix). Called directly,
103
+ `telegramChannel.create` refuses a token that is not a string or is empty, and an `allowedUsers`
104
+ that is not an array of strings; through `createChannels`, an absent or empty token is rejected
105
+ first, as `missing_required_config`.
106
+
107
+ `loopzero-gateway-line` exports `lineChannel`, a webhook channel whose `webhook.verify` checks the
108
+ `x-line-signature` header against the raw body and whose `webhook.ingest` dispatches a verified
109
+ payload through `dispatchWebhookBody`, so a reply uses the cached reply token, or answers
110
+ `"malformed"` without dispatching. It answers `"no_handler"` (a member of `IngestResult`) when the
111
+ payload holds a text message for the handler and none is subscribed: before the runner started,
112
+ after it stopped, or when LINE's connect failed under `"isolate"`. Before, such a request answered
113
+ `"delivered"`, a route acknowledged it, and LINE did not redeliver the lost message.
114
+ `lineChannel.create` checks field types before the adapter's constructor.
115
+
116
+ `LineAdapter.dispatchWebhookBody` now resolves `"ok" | "no_handler"` instead of `void`. It answers
117
+ `"no_handler"`, dispatching nothing and caching no reply token, for a batch holding a text message
118
+ that passes the mention guard while no handler is subscribed; an empty or follow-only batch still
119
+ answers `"ok"`. It reads the handler once per batch, so a handler that unsubscribes while handling
120
+ one event still receives the rest of the batch. Code that ignores the value is unaffected; a
121
+ subclass overriding the method with `Promise<void>` fails with TS2416. `createWebhookServer` is
122
+ unchanged and still answers 200 before it dispatches.
123
+
124
+ Both descriptors are typed locally and import nothing `loopzero-gateway` 0.9.0 lacks, so the peer
125
+ range stays `>=0.9.0 <1.0.0`.
126
+
127
+ - 3f1788d: Send an image from a gateway handler, and refuse it wherever a platform cannot show one.
128
+
129
+ `loopzero-gateway` exports `OutboundAttachment` (`kind: "image"`, `mediaType`, `data`, optional
130
+ `filename`). `OutboundMessage` gains an optional `attachments` list, `ctx.reply(text, { attachments })`
131
+ carries it to the adapter (an empty list is left out), and `BasePlatformAdapter` declares
132
+ `supportsAttachments`, `false` by default. `DeliveryRouter.send` takes the same `attachments`
133
+ field. The runner and the router refuse an outbound carrying attachments as
134
+ `attachments_unsupported`, with no `sendMessage` call, when the adapter does not declare
135
+ `supportsAttachments`.
136
+
137
+ `loopzero-gateway-telegram` reports `supportsAttachments: true` and sends each image through
138
+ `sendPhoto`, the text as the first photo's caption up to 1024 UTF-16 units and after the photos
139
+ when longer. A non-image kind is refused as `attachments_unsupported`; a missing image, more
140
+ than 10 images or an image over 10 MiB as `invalid_attachment`; all with no request.
141
+
142
+ Every other adapter, and every adapter's `editMessage`, refuses an outbound carrying attachments
143
+ with `attachments_unsupported` and makes no platform call, instead of sending the text and
144
+ dropping the image.
145
+
146
+ The runner's auto-reply to a blocking `pre_inbound` hook no longer discards a `sendMessage` that
147
+ throws: the error reaches the `on_error` hooks with the event and is written to stderr, redacted,
148
+ as a handler error is. Dispatch still does not throw.
149
+
150
+ - 782e448: Carry voice in both directions. The inbound event gains an optional `audio` field, an
151
+ `InboundAudio` with the voice note's bytes, media type and duration in seconds, and
152
+ `OutboundAttachment` gains an `audio` member beside `image`. The Telegram adapter reads a polled
153
+ voice note through `getFile` and a download bounded at 20 MiB and 30 seconds, delivering the
154
+ message without `audio` and one stderr line when it cannot, and sends an audio attachment through
155
+ `sendVoice` with the reply text as its caption. Every other adapter refuses audio as it refuses an
156
+ image. Code that switches exhaustively on `OutboundAttachment["kind"]` gains a case.
157
+
158
+ ### Patch Changes
159
+
160
+ - 17c0713: Keep Markdown table rows whole when Discord, Slack, Teams, Telegram, WhatsApp and Mattermost split a long reply. A cut that fell inside a table row now moves back to the start of that row when the row fits in a part, so each row reaches the platform byte-identical. `chunkText` gains the opt-in `keepTableRows` option; text with no table row splits into the same chunks as before.
161
+
162
+ ## 0.5.0
163
+
164
+ ### Minor Changes
165
+
166
+ - 05e7fdd: Edit a message an adapter sent, so a reply can stream as a preview that the final text replaces.
167
+
168
+ `BasePlatformAdapter` gains `supportsEdit` (`false` by default) and
169
+ `editMessage(messageId, out)`, whose default refuses with `edit_unsupported`, makes no platform
170
+ call and never throws. A third-party subclass that already declares a member with either name and
171
+ a different type no longer compiles against this release, and under `noImplicitOverride` one
172
+ that declares it without `override` does not either.
173
+
174
+ Telegram (`editMessageText`), Discord (one REST `PATCH` of the message, without fetching the
175
+ channel), Slack (`chat.update`), Mattermost (`patchPost`), Matrix (an `m.replace` event) and Teams
176
+ (`updateActivity`, or `activities(conversationId).update` on `@microsoft/teams.api` below 2.0.14)
177
+ set `supportsEdit` to `true` and replace the text of a message they sent, honouring `format` as
178
+ `sendMessage` does (Slack's `chat.update` takes no `mrkdwn` argument, so its edit sends the text
179
+ as it is for every format), and return `{ ok: true, messageId }` with the same id. E-mail, SMS, LINE and
180
+ WhatsApp keep the default.
181
+
182
+ An edit is refused with no request as `edit_too_long` when the text would need more than one
183
+ platform message (Matrix has no length check), as `invalid_message_id` for an empty id (and on
184
+ Telegram one that is not a safe positive integer), and as `empty_text` and `not_connected` where
185
+ `sendMessage` answers those. Telegram answers its "message is not modified" refusal as a success.
186
+ On Discord an unknown channel is answered by the platform, as `discord_10003`. On Matrix a
187
+ `#alias` the adapter never resolved costs one lookup before the edit. Teams and Matrix do not
188
+ retry a refused markup as plain text on an edit, as they do on a send.
189
+
190
+ The six adapters keep `>=0.9.0` as their peer range on `loopzero-gateway` in this release. At run
191
+ time they work against any core in that range, since no adapter calls the base `editMessage`. Their
192
+ sources declare both members with `override`, so building them against a core older than this one
193
+ reports TS4113. The floor rises to this core in the next release, once it is on npm
194
+ (`docs/adr/0008-edit-capable-adapters-raise-their-core-floor-after-the-core-ships.md`). A
195
+ consumer's own typecheck reads the published declarations, which carry no `override`, and passes
196
+ on an older core.
197
+
198
+ ## 0.4.0
199
+
200
+ ### Minor Changes
201
+
202
+ - 39d06f8: Wire channels from descriptors, and keep the channels that connect when another cannot.
203
+
204
+ `loopzero-gateway` exports `createChannels` and the types `ChannelDescriptor`,
205
+ `ChannelConfigField`, `ChannelWebhook`, `WebhookRequest`, `IngestResult`, `ChannelEntry`,
206
+ `ChannelRejection` and `CreateChannelsResult`. `createChannels(entries)` builds an adapter per
207
+ entry and returns `{ adapters, rejected }`: an entry whose required field is absent, `null` or
208
+ `""` is rejected with a `GatewayConfigurationError` coded `missing_required_config` naming the
209
+ keys, and a configuration error thrown by the descriptor's `create` is rejected the same way. Any
210
+ other error propagates. It connects nothing and makes no network call.
211
+
212
+ `GatewayRunner` accepts `connectFailure: "rollback" | "isolate"` (exported as `ConnectFailure`),
213
+ and `StartResult` is exported.
214
+ The default, `"rollback"`, is unchanged: one failed connect disconnects the adapters that did
215
+ connect and rejects `start()`. Under `"isolate"`, `start()` connects every adapter, wires inbound
216
+ only for the ones that connected, and reports the rest with a redacted reason.
217
+
218
+ `start()` now resolves a `StartResult` (`{ connected, failed }`) instead of `void`, under both
219
+ values. This is a type change: code that awaits `start()` and ignores the value is unaffected,
220
+ but a structural type declaring `start(): Promise<void>` that a `GatewayRunner` is assigned to
221
+ fails with TS2322, and a subclass overriding `start()` with that signature fails with TS2416.
222
+
223
+ `loopzero-gateway-telegram` exports `telegramChannel`, a socket channel whose config has a
224
+ required, secret `token` and an optional `allowedUsers`, and a `ConfigurationError` (a
225
+ `GatewayConfigurationError` with the `gateway-telegram` prefix). Called directly,
226
+ `telegramChannel.create` refuses a token that is not a string or is empty, and an `allowedUsers`
227
+ that is not an array of strings; through `createChannels`, an absent or empty token is rejected
228
+ first, as `missing_required_config`.
229
+
230
+ `loopzero-gateway-line` exports `lineChannel`, a webhook channel whose `webhook.verify` checks the
231
+ `x-line-signature` header against the raw body and whose `webhook.ingest` dispatches a verified
232
+ payload through `dispatchWebhookBody`, so a reply uses the cached reply token, or answers
233
+ `"malformed"` without dispatching. It answers `"no_handler"` (a member of `IngestResult`) when the
234
+ payload holds a text message for the handler and none is subscribed: before the runner started,
235
+ after it stopped, or when LINE's connect failed under `"isolate"`. Before, such a request answered
236
+ `"delivered"`, a route acknowledged it, and LINE did not redeliver the lost message.
237
+ `lineChannel.create` checks field types before the adapter's constructor.
238
+
239
+ `LineAdapter.dispatchWebhookBody` now resolves `"ok" | "no_handler"` instead of `void`. It answers
240
+ `"no_handler"`, dispatching nothing and caching no reply token, for a batch holding a text message
241
+ that passes the mention guard while no handler is subscribed; an empty or follow-only batch still
242
+ answers `"ok"`. It reads the handler once per batch, so a handler that unsubscribes while handling
243
+ one event still receives the rest of the batch. Code that ignores the value is unaffected; a
244
+ subclass overriding the method with `Promise<void>` fails with TS2416. `createWebhookServer` is
245
+ unchanged and still answers 200 before it dispatches.
246
+
247
+ Both descriptors are typed locally and import nothing `loopzero-gateway` 0.9.0 lacks, so the peer
248
+ range stays `>=0.9.0 <1.0.0`.
249
+
250
+ ## 0.3.1
251
+
252
+ ### Patch Changes
253
+
254
+ - 1e215ab: The peer floor on `loopzero-gateway` is `>=0.9.0`, which is what these packages have needed since
255
+ they gained `deliver`.
256
+
257
+ `deliver` and `runHandler` arrived in the core at 0.9.0, and the previous release shipped these
258
+ adapters still declaring `>=0.6.0` — a floor `dep-check` had already proven false by building the
259
+ workspace against it: TS4113 on the override, TS2551 on `runHandler`, in all ten packages.
260
+
261
+ It could not be corrected in that release. `dep-check`'s install check packs an adapter and installs
262
+ it the way a consumer would, and until 0.9.0 was on npm no consumer could resolve a package asking
263
+ for it — the check was right about the world as it stood. The floor is raised here, against a
264
+ registry where the version it names exists.
265
+
266
+ Between the two releases a consumer installing against an older core got a build error rather than a
267
+ resolution error: the same failure, later and less clearly. That window is closed.
268
+
269
+ ## 0.3.0
270
+
271
+ ### Minor Changes
272
+
273
+ - b38172b: **The peer floor on `loopzero-gateway` rises with this release.** Every adapter now implements
274
+ `deliver` over `runHandler`, and neither exists in an older core — an adapter installed against one
275
+ does not build. `dep-check` caught that by building the whole workspace against the floor each
276
+ package claimed, which is the one thing a version range cannot tell you by reading it.
277
+
278
+ The floor is set in the version commit rather than here, because a range cannot name a version that
279
+ does not exist yet: raised in the workspace, the same gate then fails the other way round — every
280
+ adapter declaring a floor above the core installed beside it. That is the shape `fa70153` used when
281
+ these ranges were first written.
282
+
283
+ `deliver(event)` — every adapter can now be handed an event that arrived out of band (#83).
284
+
285
+ `onInbound` was the seam every adapter implemented and it had no public counterpart. Six platforms
286
+ self-deliver once connected — long polling, a gateway socket, Socket Mode, a sync loop, IMAP — so
287
+ the asymmetry stayed invisible: `GatewayRunner` worked for eight platforms and silently did nothing
288
+ for LINE and WhatsApp Cloud, whose payloads arrive on an HTTP route the application owns. Every app
289
+ wired those two by hand, beside the runner rather than through it.
290
+
291
+ ```ts
292
+ const outcome = await adapter.deliver(event); // "ok" | "no_handler" | "handler_threw"
293
+ ```
294
+
295
+ The three outcomes are distinguished because a caller acts on them differently: answering a webhook
296
+ 200 when nobody was subscribed tells the provider to stop retrying a message nothing received.
297
+
298
+ `BasePlatformAdapter.runHandler` holds the containment once, where ten copies of it used to live —
299
+ a handler is user code, its throw is named as the handler's failure rather than the platform's, and
300
+ delivery continues. Each adapter's `deliver` is one line over it.
301
+
302
+ Also: `gateway-sms`'s `createWebhookServer` now signs against the configured `publicUrl` (#90).
303
+ Twilio verifies against the URL it POSTed to, and behind a proxy that rewrites `host` — a tunnel, an
304
+ ingress, a load balancer terminating TLS — the reconstruction from headers yields the internal
305
+ address, so a correct signature fails on every delivery. `publicUrl` is required by all three
306
+ backend option shapes and documented as "used by signature verifier"; until now no source file read
307
+ it. The header reconstruction stays as the fallback for an app served directly.
308
+
309
+ ## 0.2.3
310
+
311
+ ### Patch Changes
312
+
313
+ - 7c422d9: A unit test no longer calls the real Telegram API.
314
+
315
+ `EC-I: connect() with bad token resolves to false` produced its failure by sending a bogus token to
316
+ `api.telegram.org` and waiting for the 401. That made the suite depend on the network: it failed
317
+ when the network was slow and passed when a proxy answered.
318
+
319
+ The contract worth covering is `init() rejects → connect() returns false, never throws`, and a bogus
320
+ token was only a way to produce the rejection. Producing it directly is the same assertion in
321
+ milliseconds, and covers the failures a bad token never reaches — a DNS failure, a 5xx, a socket
322
+ reset.
323
+
324
+ ## 0.2.2
325
+
326
+ ### Patch Changes
327
+
328
+ - 29e2e28: The seam between the three repositories is documented, and the reason given for one contract was corrected.
329
+
330
+ `loopzero-gateway`'s README — the npm page — now says which repository owns which half: LoopZero the
331
+ HTTP route and the signature check, these packages the translation of the payload it hands over, the
332
+ SDK one redaction helper. A `quality:integration-story` gate fails when that disappears and passes
333
+ when the prose is rewritten around the same facts.
334
+
335
+ Both adapters' published docblocks stated that a LoopZero app's `onMessage` runs AFTER the 200 is
336
+ answered, so a throw there had no status left to change. Measured against `loopzero@0.48.14`,
337
+ `handleChannelWebhook` awaits `onMessage` BEFORE building the response and catches nothing around
338
+ it: a throw means the 200 is never built, and mounted in a LoopZero route the rejection reaches that
339
+ route's error boundary and is answered 500 where the platform expected an acknowledgement. `parseInbound` returning `null`
340
+ is unchanged and still the right contract — only the stated reason was wrong, and it was reaching
341
+ users through the `.d.ts` on hover.
342
+
343
+ `loopzero-gateway-sms`'s docblocks also named the wrong seam. Its `parseInbound` is
344
+ `(options, ctx)`, and the `SignatureContext` it needs carries the raw body, the headers and the URL
345
+ — none of which LoopZero's `ChannelMessage` provides, so the signature check cannot be performed
346
+ from inside `onMessage` for any provider. SMS goes through its own `createWebhookServer`, and the
347
+ published `.d.ts` says so now instead of claiming to be the gateway half of the channel seam.
348
+
349
+ ## 0.2.1
350
+
351
+ ### Patch Changes
352
+
353
+ - Every credential field now says what the platform calls it and where it is issued.
354
+
355
+ Measured: a developer who wires one adapter and carries its field name to the next gets
356
+ `error TS2353: … 'token' does not exist in type 'SlackAdapterOptions'`. That names the wrong field
357
+ and the type, and never the right one — so the answer was always one file away.
358
+
359
+ These docblocks are on published option types, so an editor now shows the answer on hover and
360
+ completion. All 15 credential-bearing fields across the ten packages are covered, including the ones
361
+ beyond each adapter's primary token: Slack's `appToken`, LINE's `channelSecret`, Vonage's
362
+ `apiSecret` and `signatureSecret`, WhatsApp's `appSecret`.
363
+
364
+ **Nothing was renamed.** Six of the ten primary names are the platform's own key, pinned against the
365
+ SDK's own declaration — `channelAccessToken` in `@line/bot-sdk`, `clientSecret` in
366
+ `@microsoft/teams.apps`, `accessToken` in `matrix-js-sdk`, `token` in `grammy` and `discord.js`,
367
+ `authToken` in `twilio`. Where ours diverges, the docblock says so rather than implying otherwise:
368
+ `botToken` (deliberate — the adapter also takes an `appToken`), Mattermost's `accessToken` against
369
+ its client's `token`, and `password` against nodemailer's `pass`.
370
+
371
+ ## 0.2.0
372
+
373
+ ### Minor Changes
374
+
375
+ - `parseInbound` — translate a raw webhook payload without re-declaring the platform's wire format.
376
+
377
+ An app receiving a message through LoopZero's channel seam gets `payload: unknown` and, until now,
378
+ had to parse it by hand. Measured against the published packages: wiring Telegram took 35 lines, 27
379
+ of them the app re-declaring Telegram's own format — that `caption` is the fallback for `text`, that
380
+ `message_thread_id` distinguishes a forum topic. It is now 13 lines and none.
381
+
382
+ ```ts
383
+ import { parseInbound } from "loopzero-gateway-telegram";
384
+
385
+ const event = parseInbound(await request.json());
386
+ if (event !== null) console.log(event.text);
387
+ ```
388
+
389
+ **Telegram** — `parseInbound(payload)`. One mapping serves both this and the polling path, so a
390
+ webhook-delivered message and a polled one cannot produce different events.
391
+
392
+ **SMS** — `parseInbound(options, ctx)`. Takes the adapter options an app already holds, because
393
+ parsing is provider-specific and, for Twilio, country-dependent. `createBackend` runs outside the
394
+ error boundary, so an unsupported backend surfaces instead of becoming the same `null` a malformed
395
+ body produces.
396
+
397
+ Both return `null` and never throw. `onMessage` runs after LoopZero has already answered 200, so a
398
+ throw there is an unhandled rejection with no status left to change. Every field either translator
399
+ copies is narrowed at the boundary: a payload with `text: 5` yields `text: ""`, and one with a
400
+ non-finite `date`, `message_id`, `chat.id`, thread id, sender id or reply id is rejected or dropped
401
+ rather than producing an event whose declared types are lies.
402
+
403
+ `loopzero-gateway-line` and `loopzero-gateway-whatsapp` already shipped this shape and are unchanged.
404
+
405
+ ## 0.1.4
406
+
407
+ ### Patch Changes
408
+
409
+ - Drop the unused `loopzero-sdk` peer dependency, so a LoopZero app can install an adapter.
410
+
411
+ Every adapter declared `peer loopzero-sdk@^2.18.0` and imported the SDK in **zero** source files.
412
+ The framework ships `loopzero-sdk@4.x`, so `npm install loopzero-gateway-line` into a LoopZero app
413
+ failed outright with `ERESOLVE`.
414
+
415
+ The core's range was widened in `loopzero-gateway@0.7.0`, which was not enough on its own: an
416
+ adapter's own manifest still carried the pin, so installing one still failed even against the fixed
417
+ core. Measured in a real app before and after.
418
+
419
+ ## 0.1.3
420
+
421
+ ### Patch Changes
422
+
423
+ - e682180: **A message whose handler throws no longer kills the bot.** On Teams and on WhatsApp's web backend it did — not degraded delivery, an exit code. `Error: ... / Node.js v22.22.2`, and the next message never arrived.
424
+
425
+ Both dispatched with `void handler(event)`. `void` reads as "I am not waiting for this"; what it tells the runtime is "I am not handling the error", and under Node 22's default an unhandled rejection ends the process. Measured against both adapters through their own injection seams before the fix, and again after: the throw is now contained, named, and delivery continues.
426
+
427
+ **Discord and Telegram contained it but blamed the wrong thing.** The rejection escaped into the platform library's error channel, so a bug in the consumer's own handler surfaced as `[discord] client error` / `[telegram] bot error`. Anyone debugging that went looking in discord.js and grammy for a fault that was in their own code. Both now report `handler threw` and return `"handler_threw"` from the internal dispatch seam.
428
+
429
+ **WhatsApp Cloud dropped the rest of the batch, and made the platform resend it.** Meta packs several messages and their delivery receipts into one webhook, and the dispatch loop awaited each handler with nothing around it. One throw skipped every remaining message in the payload, skipped the status receipts, and rejected `handleWebhookPayload` — so the caller's route answered 500 and Meta redelivered the whole batch, replaying the messages that had already been handled. That is a duplicate-reply bug reached through a different door than the one fixed in #11. The same method also now answers `false` on a signed body that is not JSON, instead of throwing out of a method whose contract is `true`/`false`.
430
+
431
+ **Email gained a net it did not strictly need.** Its drain is written never to reject, and it does not — but both launch sites discard the promise, so that property was the only thing between a future edit and the same fatal rejection, and nothing enforced it. The catch now lives at the site that would pay for it.
432
+
433
+ **The contract is written down, and held to.** `BasePlatformAdapter.onInbound` now states it: a handler may throw, and an adapter must contain that throw, report it as the handler's failure rather than the platform's, and keep delivering. Eight of ten adapters had converged on exactly that with nothing recording it. `tests/lint/adapter-contract.test.ts` gains two invariants — every adapter names a handler throw as the handler's, and no adapter launches a user callback with a bare `void` — and both were checked against a deliberately reverted adapter to confirm they fire rather than pass vacuously.
434
+
435
+ - 8cbf136: **Every published export now carries documentation.** Forty-seven public symbols shipped with no docblock at all, so a consumer hovering `DiscordAdapter`, `SlackAdapter`, `WhatsAppCloudBackend`, `ThreadStore` or any of the error classes got an empty tooltip. Coverage across the eleven packages went from 71.2% to 100% (163/163), measured over the published declarations rather than the source, because a docblock is not documentation until it survives the build.
436
+
437
+ The text says what each symbol is for and what constrains it, not what its name already says. `TelegramAdapter` records that a bot cannot enumerate its chats nor speak into one that has not spoken first. `DiscordAdapter` records that reading message content needs a privileged intent enabled in the developer portal, without which every `event.text` arrives empty and nothing says why. `WhatsAppWebBackend` records that it is unofficial and can get a number banned. `shouldDispatchSyncEvent` records that Matrix replays history on sync, which is why a freshly started bot would otherwise answer every message it can still see.
438
+
439
+ **`gateway-slack`'s README documented a type that does not exist.** Its usage example imported `GatewayMessageEvent` from `loopzero-gateway`. That name is an internal alias inside the Discord and Telegram adapters (`MessageEvent as GatewayMessageEvent`), never an export. A reader who copied the example got code that did not compile. It now imports `MessageEvent`, which is what `onInbound` actually hands the handler.
440
+
441
+ Two docblocks that attached to nothing were reattached: `acquirePidLock` in `gateway-whatsapp` had its documentation stranded thirty lines above, over a different function, and shipped undocumented as a result.
442
+
443
+ - b8ef098: **Every package now ships the licence it declares.** All twelve manifests in this repository declare `Apache-2.0`, and the repository had no `LICENSE` file at all — not at the root, and not in any package directory except `gateway-email`. So each published tarball asserted a licence while carrying none of its terms, and §4(a) of that licence requires a copy to travel with the distribution. Worse than a missing file: with no licence text anywhere, everything outside the manifests fell back to default copyright, which grants a recipient nothing.
444
+
445
+ The text is now at the repository root and inside every publishable package, byte-identical to the canonical Apache License 2.0 with the appendix filled in (`Copyright 2026 getloopscale.com`). The one pre-existing copy, in `gateway-email`, was replaced along with the rest: it carried the same truncated paragraph 4(d) found across the ecosystem, dropping "reasonable and customary use" from the NOTICE clause — a modified body under an unmodified SPDX identifier.
446
+
447
+ **The repository moved to the official `getloopscale` organization.** Existing clones and published URLs keep working through GitHub's permanent redirect; the root manifest now declares `Apache-2.0` explicitly rather than leaving the workspace root silent.
448
+
449
+ - 5bae032: Six defects that broke real conversations, found by testing the adapters against the live platforms instead of against fakes.
450
+
451
+ **LINE — no outbound message was ever delivered.** The adapter called the v9 SDK client with positional arguments while that client takes a single request object, so LINE received an empty request and rejected every send with a 400. Upgrade if you use this adapter at all: nothing it sent reached anyone.
452
+
453
+ **Telegram — the bot froze on long replies.** Any message over 4096 characters that began with an unclosed code span (a stray backtick) put the splitter into an infinite loop, hanging the process until it ran out of memory. Long agent answers now split correctly whatever markdown they contain.
454
+
455
+ **Mattermost — long messages silently vanished.** The adapter never split anything, so any reply over 16,383 characters was rejected by the server and the user simply saw nothing. Long replies are now split into parts Mattermost accepts.
456
+
457
+ **SMS — long messages were rejected from the hundredth part onward.** The `(i/N)` prefix outgrew the space reserved for it, pushing every later part past the provider's limit.
458
+
459
+ **Matrix and LINE — `connect()` reported success with an invalid token.** Both now verify the credential with the server before returning `true`, so a wrong token fails at startup instead of silently receiving nothing forever.
460
+
461
+ **Email and Teams — the bot could go permanently deaf.** Replacing an inbound handler and then disposing of the previous one removed the new handler as well, and the gateway stopped receiving messages with nothing logged.
462
+
463
+ Also: a `pre_inbound` hook that threw put its raw error text into the user's chat, which could expose internal details such as connection strings or tokens. Users now see only which hook failed; the detail goes to the server log, redacted.
464
+
465
+ WhatsApp additionally stops opening a second session when `connect()` is called twice, and its group mention filter no longer treats unrelated digits scattered through a message as a mention of the bot.
466
+
467
+ ## 0.1.2
468
+
469
+ ### Patch Changes
470
+
471
+ - b8ef098: **Every package now ships the licence it declares.** All twelve manifests in this repository declare `Apache-2.0`, and the repository had no `LICENSE` file at all — not at the root, and not in any package directory except `gateway-email`. So each published tarball asserted a licence while carrying none of its terms, and §4(a) of that licence requires a copy to travel with the distribution. Worse than a missing file: with no licence text anywhere, everything outside the manifests fell back to default copyright, which grants a recipient nothing.
472
+
473
+ The text is now at the repository root and inside every publishable package, byte-identical to the canonical Apache License 2.0 with the appendix filled in (`Copyright 2026 getloopscale.com`). The one pre-existing copy, in `gateway-email`, was replaced along with the rest: it carried the same truncated paragraph 4(d) found across the ecosystem, dropping "reasonable and customary use" from the NOTICE clause — a modified body under an unmodified SPDX identifier.
474
+
475
+ **The repository moved to the official `getloopscale` organization.** Existing clones and published URLs keep working through GitHub's permanent redirect; the root manifest now declares `Apache-2.0` explicitly rather than leaving the workspace root silent.
476
+
477
+ - 5bae032: Six defects that broke real conversations, found by testing the adapters against the live platforms instead of against fakes.
478
+
479
+ **LINE — no outbound message was ever delivered.** The adapter called the v9 SDK client with positional arguments while that client takes a single request object, so LINE received an empty request and rejected every send with a 400. Upgrade if you use this adapter at all: nothing it sent reached anyone.
480
+
481
+ **Telegram — the bot froze on long replies.** Any message over 4096 characters that began with an unclosed code span (a stray backtick) put the splitter into an infinite loop, hanging the process until it ran out of memory. Long agent answers now split correctly whatever markdown they contain.
482
+
483
+ **Mattermost — long messages silently vanished.** The adapter never split anything, so any reply over 16,383 characters was rejected by the server and the user simply saw nothing. Long replies are now split into parts Mattermost accepts.
484
+
485
+ **SMS — long messages were rejected from the hundredth part onward.** The `(i/N)` prefix outgrew the space reserved for it, pushing every later part past the provider's limit.
486
+
487
+ **Matrix and LINE — `connect()` reported success with an invalid token.** Both now verify the credential with the server before returning `true`, so a wrong token fails at startup instead of silently receiving nothing forever.
488
+
489
+ **Email and Teams — the bot could go permanently deaf.** Replacing an inbound handler and then disposing of the previous one removed the new handler as well, and the gateway stopped receiving messages with nothing logged.
490
+
491
+ Also: a `pre_inbound` hook that threw put its raw error text into the user's chat, which could expose internal details such as connection strings or tokens. Users now see only which hook failed; the detail goes to the server log, redacted.
492
+
493
+ WhatsApp additionally stops opening a second session when `connect()` is called twice, and its group mention filter no longer treats unrelated digits scattered through a message as a mention of the bot.
494
+
495
+ ## 0.1.1
496
+
497
+ ### Patch Changes
498
+
499
+ - e926cd9: Align the gateway cluster to the hardened `loopzero-sdk` 2.18.0 Harness (ecosystem M6). Bumped the `loopzero-sdk` peer + dev dependency from `^1.9.0` to `^2.18.0` across all 11 packages. The only consumed SDK surface is `Security.redact` (in the gateway core runner) — a stable public API (ADR D68) unchanged across 1.x→2.x — so the alignment is a pin bump, not a migration. Validated: all 11 packages typecheck + build + test green against 2.18.0 (543 tests passed). No dead/unwired surfaces (`no-stubs-no-mocks-no-wired` checklist clean).
500
+
501
+ ## 2.0.0
502
+
503
+ ### Patch Changes
504
+
505
+ - Updated dependencies
506
+ - loopzero-sdk@1.3.0
507
+ - loopzero-gateway@2.0.0
508
+
509
+ ## 1.0.0
510
+
511
+ ### Patch Changes
512
+
513
+ - Updated dependencies
514
+ - loopzero-sdk@1.2.0
515
+ - loopzero-gateway@1.0.0
516
+
517
+ ## [0.1.0] — 2026-05-20
518
+
519
+ ### Added
520
+
521
+ - Initial release. `TelegramAdapter` wraps grammy in the `loopzero-gateway` `BasePlatformAdapter` contract.
522
+ - `shouldRespondInChat(ctx, policy)` helper for group-chat filtering.
523
+ - `splitForTelegram(text)` helper for auto-splitting >4096-char messages.
524
+ - EC-I: invalid token resolves `connect()` to `false` (never throws).
525
+ - EC-J: `splitForTelegram` preserves markdown pair integrity.
526
+ - EC-K: ignores messages where `ctx.from.is_bot === true`.