loopzero-gateway-telegram 0.0.0-stage → 0.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/CHANGELOG.md +535 -0
- package/LICENSE +201 -0
- package/README.md +212 -2
- package/dist/index.cjs +1193 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +283 -0
- package/dist/index.d.ts +283 -0
- package/dist/index.js +1185 -0
- package/dist/index.js.map +1 -0
- package/package.json +77 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,535 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 31c4c2d: Send `file` attachments through `sendDocument` (any media type, up to 50 MiB, from bytes or a `Blob`), in the same order and caption rule as photos and voice notes, and read a polled message's `document` as `event.files`, downloaded on demand through `getFile` (up to 20 MB). `capabilities.attachments` is now `["image", "audio", "file"]`.
|
|
8
|
+
- 414ebff: Read a polled message's audio file (`message.audio`, a recording or music file sent as audio rather than as a voice note) as `event.audio`, the same field a voice note fills. It is downloaded only when `audio.read()` is called, through `getFile`, up to 20 MB and under the 30 s deadline voice notes use. A file with no media type is labelled `audio/mpeg`. A failed read rejects with an error naming the reason, never the download URL, which holds the bot token, and writes `[telegram] audio not read: <reason>` to stderr.
|
|
9
|
+
- 414ebff: Send `OutboundMessage.buttons` as an inline keyboard: URL buttons, and `web_app` buttons that open a Telegram Mini App in a private chat. The keyboard goes on the last part of a split text and is kept by an edit. A `web_app` button in a group, a `callback` button (the adapter does not receive `callback_query` yet) and buttons with attachments are refused as `buttons_unsupported`; a blank label, a URL that is not absolute or a `web_app` URL that is not HTTPS as `invalid_buttons`, all before any request. `capabilities.buttons` is `{ actionKinds: ["url", "web_app"] }` (#4).
|
|
10
|
+
- fd8af16: Declare `streamingPreview` (one edit a second, 4096 characters a message), so `ctx.stream()` edits a reply in place as it arrives (OC-49). The `loopzero-gateway` peer floor rises to 0.2.0.
|
|
11
|
+
|
|
12
|
+
## 0.15.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- 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.
|
|
17
|
+
|
|
18
|
+
## 0.14.0
|
|
19
|
+
|
|
20
|
+
### Minor Changes
|
|
21
|
+
|
|
22
|
+
- 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.
|
|
23
|
+
|
|
24
|
+
## 0.13.0
|
|
25
|
+
|
|
26
|
+
### Minor Changes
|
|
27
|
+
|
|
28
|
+
- 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`.
|
|
29
|
+
|
|
30
|
+
## 0.12.1
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- 8585427: README status lines say "0.x, pre-1.0" instead of a hard-coded version.
|
|
35
|
+
|
|
36
|
+
## 0.12.0
|
|
37
|
+
|
|
38
|
+
### Minor Changes
|
|
39
|
+
|
|
40
|
+
- 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.
|
|
41
|
+
|
|
42
|
+
## 0.11.0
|
|
43
|
+
|
|
44
|
+
### Minor Changes
|
|
45
|
+
|
|
46
|
+
- 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.
|
|
47
|
+
|
|
48
|
+
## 0.10.0
|
|
49
|
+
|
|
50
|
+
### Minor Changes
|
|
51
|
+
|
|
52
|
+
- 2831ca3: Report `capabilities.maxMessageChars` from the splitter limit, and `capabilities.threads` (true for Discord, Telegram and Slack).
|
|
53
|
+
|
|
54
|
+
## 0.9.0
|
|
55
|
+
|
|
56
|
+
### Minor Changes
|
|
57
|
+
|
|
58
|
+
- 9c832b2: Add `AdapterCapabilities` and `BasePlatformAdapter.capabilities` (edit, attachment kinds, typing, reactions, threads, max length), derived by default. Telegram reports `image` and `audio` attachments.
|
|
59
|
+
- 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.
|
|
60
|
+
- 56bb1d8: Declare whether a channel's sender id is authenticated with `senderIdentity`.
|
|
61
|
+
|
|
62
|
+
## 0.8.0
|
|
63
|
+
|
|
64
|
+
### Minor Changes
|
|
65
|
+
|
|
66
|
+
- 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"`.
|
|
67
|
+
|
|
68
|
+
### Patch Changes
|
|
69
|
+
|
|
70
|
+
- 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.
|
|
71
|
+
|
|
72
|
+
## 0.7.1
|
|
73
|
+
|
|
74
|
+
### Patch Changes
|
|
75
|
+
|
|
76
|
+
- 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>`.
|
|
77
|
+
|
|
78
|
+
## 0.7.0
|
|
79
|
+
|
|
80
|
+
### Minor Changes
|
|
81
|
+
|
|
82
|
+
- 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.
|
|
83
|
+
|
|
84
|
+
## 0.6.0
|
|
85
|
+
|
|
86
|
+
### Minor Changes
|
|
87
|
+
|
|
88
|
+
- 458c34c: Wire channels from descriptors, and keep the channels that connect when another cannot.
|
|
89
|
+
|
|
90
|
+
`loopzero-gateway` exports `createChannels` and the types `ChannelDescriptor`,
|
|
91
|
+
`ChannelConfigField`, `ChannelWebhook`, `WebhookRequest`, `IngestResult`, `ChannelEntry`,
|
|
92
|
+
`ChannelRejection` and `CreateChannelsResult`. `createChannels(entries)` builds an adapter per
|
|
93
|
+
entry and returns `{ adapters, rejected }`: an entry whose required field is absent, `null` or
|
|
94
|
+
`""` is rejected with a `GatewayConfigurationError` coded `missing_required_config` naming the
|
|
95
|
+
keys, and a configuration error thrown by the descriptor's `create` is rejected the same way. Any
|
|
96
|
+
other error propagates. It connects nothing and makes no network call.
|
|
97
|
+
|
|
98
|
+
`GatewayRunner` accepts `connectFailure: "rollback" | "isolate"` (exported as `ConnectFailure`),
|
|
99
|
+
and `StartResult` is exported.
|
|
100
|
+
The default, `"rollback"`, is unchanged: one failed connect disconnects the adapters that did
|
|
101
|
+
connect and rejects `start()`. Under `"isolate"`, `start()` connects every adapter, wires inbound
|
|
102
|
+
only for the ones that connected, and reports the rest with a redacted reason.
|
|
103
|
+
|
|
104
|
+
`start()` now resolves a `StartResult` (`{ connected, failed }`) instead of `void`, under both
|
|
105
|
+
values. This is a type change: code that awaits `start()` and ignores the value is unaffected,
|
|
106
|
+
but a structural type declaring `start(): Promise<void>` that a `GatewayRunner` is assigned to
|
|
107
|
+
fails with TS2322, and a subclass overriding `start()` with that signature fails with TS2416.
|
|
108
|
+
|
|
109
|
+
`loopzero-gateway-telegram` exports `telegramChannel`, a socket channel whose config has a
|
|
110
|
+
required, secret `token` and an optional `allowedUsers`, and a `ConfigurationError` (a
|
|
111
|
+
`GatewayConfigurationError` with the `gateway-telegram` prefix). Called directly,
|
|
112
|
+
`telegramChannel.create` refuses a token that is not a string or is empty, and an `allowedUsers`
|
|
113
|
+
that is not an array of strings; through `createChannels`, an absent or empty token is rejected
|
|
114
|
+
first, as `missing_required_config`.
|
|
115
|
+
|
|
116
|
+
`loopzero-gateway-line` exports `lineChannel`, a webhook channel whose `webhook.verify` checks the
|
|
117
|
+
`x-line-signature` header against the raw body and whose `webhook.ingest` dispatches a verified
|
|
118
|
+
payload through `dispatchWebhookBody`, so a reply uses the cached reply token, or answers
|
|
119
|
+
`"malformed"` without dispatching. It answers `"no_handler"` (a member of `IngestResult`) when the
|
|
120
|
+
payload holds a text message for the handler and none is subscribed: before the runner started,
|
|
121
|
+
after it stopped, or when LINE's connect failed under `"isolate"`. Before, such a request answered
|
|
122
|
+
`"delivered"`, a route acknowledged it, and LINE did not redeliver the lost message.
|
|
123
|
+
`lineChannel.create` checks field types before the adapter's constructor.
|
|
124
|
+
|
|
125
|
+
`LineAdapter.dispatchWebhookBody` now resolves `"ok" | "no_handler"` instead of `void`. It answers
|
|
126
|
+
`"no_handler"`, dispatching nothing and caching no reply token, for a batch holding a text message
|
|
127
|
+
that passes the mention guard while no handler is subscribed; an empty or follow-only batch still
|
|
128
|
+
answers `"ok"`. It reads the handler once per batch, so a handler that unsubscribes while handling
|
|
129
|
+
one event still receives the rest of the batch. Code that ignores the value is unaffected; a
|
|
130
|
+
subclass overriding the method with `Promise<void>` fails with TS2416. `createWebhookServer` is
|
|
131
|
+
unchanged and still answers 200 before it dispatches.
|
|
132
|
+
|
|
133
|
+
Both descriptors are typed locally and import nothing `loopzero-gateway` 0.9.0 lacks, so the peer
|
|
134
|
+
range stays `>=0.9.0 <1.0.0`.
|
|
135
|
+
|
|
136
|
+
- 3f1788d: Send an image from a gateway handler, and refuse it wherever a platform cannot show one.
|
|
137
|
+
|
|
138
|
+
`loopzero-gateway` exports `OutboundAttachment` (`kind: "image"`, `mediaType`, `data`, optional
|
|
139
|
+
`filename`). `OutboundMessage` gains an optional `attachments` list, `ctx.reply(text, { attachments })`
|
|
140
|
+
carries it to the adapter (an empty list is left out), and `BasePlatformAdapter` declares
|
|
141
|
+
`supportsAttachments`, `false` by default. `DeliveryRouter.send` takes the same `attachments`
|
|
142
|
+
field. The runner and the router refuse an outbound carrying attachments as
|
|
143
|
+
`attachments_unsupported`, with no `sendMessage` call, when the adapter does not declare
|
|
144
|
+
`supportsAttachments`.
|
|
145
|
+
|
|
146
|
+
`loopzero-gateway-telegram` reports `supportsAttachments: true` and sends each image through
|
|
147
|
+
`sendPhoto`, the text as the first photo's caption up to 1024 UTF-16 units and after the photos
|
|
148
|
+
when longer. A non-image kind is refused as `attachments_unsupported`; a missing image, more
|
|
149
|
+
than 10 images or an image over 10 MiB as `invalid_attachment`; all with no request.
|
|
150
|
+
|
|
151
|
+
Every other adapter, and every adapter's `editMessage`, refuses an outbound carrying attachments
|
|
152
|
+
with `attachments_unsupported` and makes no platform call, instead of sending the text and
|
|
153
|
+
dropping the image.
|
|
154
|
+
|
|
155
|
+
The runner's auto-reply to a blocking `pre_inbound` hook no longer discards a `sendMessage` that
|
|
156
|
+
throws: the error reaches the `on_error` hooks with the event and is written to stderr, redacted,
|
|
157
|
+
as a handler error is. Dispatch still does not throw.
|
|
158
|
+
|
|
159
|
+
- 782e448: Carry voice in both directions. The inbound event gains an optional `audio` field, an
|
|
160
|
+
`InboundAudio` with the voice note's bytes, media type and duration in seconds, and
|
|
161
|
+
`OutboundAttachment` gains an `audio` member beside `image`. The Telegram adapter reads a polled
|
|
162
|
+
voice note through `getFile` and a download bounded at 20 MiB and 30 seconds, delivering the
|
|
163
|
+
message without `audio` and one stderr line when it cannot, and sends an audio attachment through
|
|
164
|
+
`sendVoice` with the reply text as its caption. Every other adapter refuses audio as it refuses an
|
|
165
|
+
image. Code that switches exhaustively on `OutboundAttachment["kind"]` gains a case.
|
|
166
|
+
|
|
167
|
+
### Patch Changes
|
|
168
|
+
|
|
169
|
+
- 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.
|
|
170
|
+
|
|
171
|
+
## 0.5.0
|
|
172
|
+
|
|
173
|
+
### Minor Changes
|
|
174
|
+
|
|
175
|
+
- 05e7fdd: Edit a message an adapter sent, so a reply can stream as a preview that the final text replaces.
|
|
176
|
+
|
|
177
|
+
`BasePlatformAdapter` gains `supportsEdit` (`false` by default) and
|
|
178
|
+
`editMessage(messageId, out)`, whose default refuses with `edit_unsupported`, makes no platform
|
|
179
|
+
call and never throws. A third-party subclass that already declares a member with either name and
|
|
180
|
+
a different type no longer compiles against this release, and under `noImplicitOverride` one
|
|
181
|
+
that declares it without `override` does not either.
|
|
182
|
+
|
|
183
|
+
Telegram (`editMessageText`), Discord (one REST `PATCH` of the message, without fetching the
|
|
184
|
+
channel), Slack (`chat.update`), Mattermost (`patchPost`), Matrix (an `m.replace` event) and Teams
|
|
185
|
+
(`updateActivity`, or `activities(conversationId).update` on `@microsoft/teams.api` below 2.0.14)
|
|
186
|
+
set `supportsEdit` to `true` and replace the text of a message they sent, honouring `format` as
|
|
187
|
+
`sendMessage` does (Slack's `chat.update` takes no `mrkdwn` argument, so its edit sends the text
|
|
188
|
+
as it is for every format), and return `{ ok: true, messageId }` with the same id. E-mail, SMS, LINE and
|
|
189
|
+
WhatsApp keep the default.
|
|
190
|
+
|
|
191
|
+
An edit is refused with no request as `edit_too_long` when the text would need more than one
|
|
192
|
+
platform message (Matrix has no length check), as `invalid_message_id` for an empty id (and on
|
|
193
|
+
Telegram one that is not a safe positive integer), and as `empty_text` and `not_connected` where
|
|
194
|
+
`sendMessage` answers those. Telegram answers its "message is not modified" refusal as a success.
|
|
195
|
+
On Discord an unknown channel is answered by the platform, as `discord_10003`. On Matrix a
|
|
196
|
+
`#alias` the adapter never resolved costs one lookup before the edit. Teams and Matrix do not
|
|
197
|
+
retry a refused markup as plain text on an edit, as they do on a send.
|
|
198
|
+
|
|
199
|
+
The six adapters keep `>=0.9.0` as their peer range on `loopzero-gateway` in this release. At run
|
|
200
|
+
time they work against any core in that range, since no adapter calls the base `editMessage`. Their
|
|
201
|
+
sources declare both members with `override`, so building them against a core older than this one
|
|
202
|
+
reports TS4113. The floor rises to this core in the next release, once it is on npm
|
|
203
|
+
(`docs/adr/0008-edit-capable-adapters-raise-their-core-floor-after-the-core-ships.md`). A
|
|
204
|
+
consumer's own typecheck reads the published declarations, which carry no `override`, and passes
|
|
205
|
+
on an older core.
|
|
206
|
+
|
|
207
|
+
## 0.4.0
|
|
208
|
+
|
|
209
|
+
### Minor Changes
|
|
210
|
+
|
|
211
|
+
- 39d06f8: Wire channels from descriptors, and keep the channels that connect when another cannot.
|
|
212
|
+
|
|
213
|
+
`loopzero-gateway` exports `createChannels` and the types `ChannelDescriptor`,
|
|
214
|
+
`ChannelConfigField`, `ChannelWebhook`, `WebhookRequest`, `IngestResult`, `ChannelEntry`,
|
|
215
|
+
`ChannelRejection` and `CreateChannelsResult`. `createChannels(entries)` builds an adapter per
|
|
216
|
+
entry and returns `{ adapters, rejected }`: an entry whose required field is absent, `null` or
|
|
217
|
+
`""` is rejected with a `GatewayConfigurationError` coded `missing_required_config` naming the
|
|
218
|
+
keys, and a configuration error thrown by the descriptor's `create` is rejected the same way. Any
|
|
219
|
+
other error propagates. It connects nothing and makes no network call.
|
|
220
|
+
|
|
221
|
+
`GatewayRunner` accepts `connectFailure: "rollback" | "isolate"` (exported as `ConnectFailure`),
|
|
222
|
+
and `StartResult` is exported.
|
|
223
|
+
The default, `"rollback"`, is unchanged: one failed connect disconnects the adapters that did
|
|
224
|
+
connect and rejects `start()`. Under `"isolate"`, `start()` connects every adapter, wires inbound
|
|
225
|
+
only for the ones that connected, and reports the rest with a redacted reason.
|
|
226
|
+
|
|
227
|
+
`start()` now resolves a `StartResult` (`{ connected, failed }`) instead of `void`, under both
|
|
228
|
+
values. This is a type change: code that awaits `start()` and ignores the value is unaffected,
|
|
229
|
+
but a structural type declaring `start(): Promise<void>` that a `GatewayRunner` is assigned to
|
|
230
|
+
fails with TS2322, and a subclass overriding `start()` with that signature fails with TS2416.
|
|
231
|
+
|
|
232
|
+
`loopzero-gateway-telegram` exports `telegramChannel`, a socket channel whose config has a
|
|
233
|
+
required, secret `token` and an optional `allowedUsers`, and a `ConfigurationError` (a
|
|
234
|
+
`GatewayConfigurationError` with the `gateway-telegram` prefix). Called directly,
|
|
235
|
+
`telegramChannel.create` refuses a token that is not a string or is empty, and an `allowedUsers`
|
|
236
|
+
that is not an array of strings; through `createChannels`, an absent or empty token is rejected
|
|
237
|
+
first, as `missing_required_config`.
|
|
238
|
+
|
|
239
|
+
`loopzero-gateway-line` exports `lineChannel`, a webhook channel whose `webhook.verify` checks the
|
|
240
|
+
`x-line-signature` header against the raw body and whose `webhook.ingest` dispatches a verified
|
|
241
|
+
payload through `dispatchWebhookBody`, so a reply uses the cached reply token, or answers
|
|
242
|
+
`"malformed"` without dispatching. It answers `"no_handler"` (a member of `IngestResult`) when the
|
|
243
|
+
payload holds a text message for the handler and none is subscribed: before the runner started,
|
|
244
|
+
after it stopped, or when LINE's connect failed under `"isolate"`. Before, such a request answered
|
|
245
|
+
`"delivered"`, a route acknowledged it, and LINE did not redeliver the lost message.
|
|
246
|
+
`lineChannel.create` checks field types before the adapter's constructor.
|
|
247
|
+
|
|
248
|
+
`LineAdapter.dispatchWebhookBody` now resolves `"ok" | "no_handler"` instead of `void`. It answers
|
|
249
|
+
`"no_handler"`, dispatching nothing and caching no reply token, for a batch holding a text message
|
|
250
|
+
that passes the mention guard while no handler is subscribed; an empty or follow-only batch still
|
|
251
|
+
answers `"ok"`. It reads the handler once per batch, so a handler that unsubscribes while handling
|
|
252
|
+
one event still receives the rest of the batch. Code that ignores the value is unaffected; a
|
|
253
|
+
subclass overriding the method with `Promise<void>` fails with TS2416. `createWebhookServer` is
|
|
254
|
+
unchanged and still answers 200 before it dispatches.
|
|
255
|
+
|
|
256
|
+
Both descriptors are typed locally and import nothing `loopzero-gateway` 0.9.0 lacks, so the peer
|
|
257
|
+
range stays `>=0.9.0 <1.0.0`.
|
|
258
|
+
|
|
259
|
+
## 0.3.1
|
|
260
|
+
|
|
261
|
+
### Patch Changes
|
|
262
|
+
|
|
263
|
+
- 1e215ab: The peer floor on `loopzero-gateway` is `>=0.9.0`, which is what these packages have needed since
|
|
264
|
+
they gained `deliver`.
|
|
265
|
+
|
|
266
|
+
`deliver` and `runHandler` arrived in the core at 0.9.0, and the previous release shipped these
|
|
267
|
+
adapters still declaring `>=0.6.0` — a floor `dep-check` had already proven false by building the
|
|
268
|
+
workspace against it: TS4113 on the override, TS2551 on `runHandler`, in all ten packages.
|
|
269
|
+
|
|
270
|
+
It could not be corrected in that release. `dep-check`'s install check packs an adapter and installs
|
|
271
|
+
it the way a consumer would, and until 0.9.0 was on npm no consumer could resolve a package asking
|
|
272
|
+
for it — the check was right about the world as it stood. The floor is raised here, against a
|
|
273
|
+
registry where the version it names exists.
|
|
274
|
+
|
|
275
|
+
Between the two releases a consumer installing against an older core got a build error rather than a
|
|
276
|
+
resolution error: the same failure, later and less clearly. That window is closed.
|
|
277
|
+
|
|
278
|
+
## 0.3.0
|
|
279
|
+
|
|
280
|
+
### Minor Changes
|
|
281
|
+
|
|
282
|
+
- b38172b: **The peer floor on `loopzero-gateway` rises with this release.** Every adapter now implements
|
|
283
|
+
`deliver` over `runHandler`, and neither exists in an older core — an adapter installed against one
|
|
284
|
+
does not build. `dep-check` caught that by building the whole workspace against the floor each
|
|
285
|
+
package claimed, which is the one thing a version range cannot tell you by reading it.
|
|
286
|
+
|
|
287
|
+
The floor is set in the version commit rather than here, because a range cannot name a version that
|
|
288
|
+
does not exist yet: raised in the workspace, the same gate then fails the other way round — every
|
|
289
|
+
adapter declaring a floor above the core installed beside it. That is the shape `fa70153` used when
|
|
290
|
+
these ranges were first written.
|
|
291
|
+
|
|
292
|
+
`deliver(event)` — every adapter can now be handed an event that arrived out of band (#83).
|
|
293
|
+
|
|
294
|
+
`onInbound` was the seam every adapter implemented and it had no public counterpart. Six platforms
|
|
295
|
+
self-deliver once connected — long polling, a gateway socket, Socket Mode, a sync loop, IMAP — so
|
|
296
|
+
the asymmetry stayed invisible: `GatewayRunner` worked for eight platforms and silently did nothing
|
|
297
|
+
for LINE and WhatsApp Cloud, whose payloads arrive on an HTTP route the application owns. Every app
|
|
298
|
+
wired those two by hand, beside the runner rather than through it.
|
|
299
|
+
|
|
300
|
+
```ts
|
|
301
|
+
const outcome = await adapter.deliver(event); // "ok" | "no_handler" | "handler_threw"
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
The three outcomes are distinguished because a caller acts on them differently: answering a webhook
|
|
305
|
+
200 when nobody was subscribed tells the provider to stop retrying a message nothing received.
|
|
306
|
+
|
|
307
|
+
`BasePlatformAdapter.runHandler` holds the containment once, where ten copies of it used to live —
|
|
308
|
+
a handler is user code, its throw is named as the handler's failure rather than the platform's, and
|
|
309
|
+
delivery continues. Each adapter's `deliver` is one line over it.
|
|
310
|
+
|
|
311
|
+
Also: `gateway-sms`'s `createWebhookServer` now signs against the configured `publicUrl` (#90).
|
|
312
|
+
Twilio verifies against the URL it POSTed to, and behind a proxy that rewrites `host` — a tunnel, an
|
|
313
|
+
ingress, a load balancer terminating TLS — the reconstruction from headers yields the internal
|
|
314
|
+
address, so a correct signature fails on every delivery. `publicUrl` is required by all three
|
|
315
|
+
backend option shapes and documented as "used by signature verifier"; until now no source file read
|
|
316
|
+
it. The header reconstruction stays as the fallback for an app served directly.
|
|
317
|
+
|
|
318
|
+
## 0.2.3
|
|
319
|
+
|
|
320
|
+
### Patch Changes
|
|
321
|
+
|
|
322
|
+
- 7c422d9: A unit test no longer calls the real Telegram API.
|
|
323
|
+
|
|
324
|
+
`EC-I: connect() with bad token resolves to false` produced its failure by sending a bogus token to
|
|
325
|
+
`api.telegram.org` and waiting for the 401. That made the suite depend on the network: it failed
|
|
326
|
+
when the network was slow and passed when a proxy answered.
|
|
327
|
+
|
|
328
|
+
The contract worth covering is `init() rejects → connect() returns false, never throws`, and a bogus
|
|
329
|
+
token was only a way to produce the rejection. Producing it directly is the same assertion in
|
|
330
|
+
milliseconds, and covers the failures a bad token never reaches — a DNS failure, a 5xx, a socket
|
|
331
|
+
reset.
|
|
332
|
+
|
|
333
|
+
## 0.2.2
|
|
334
|
+
|
|
335
|
+
### Patch Changes
|
|
336
|
+
|
|
337
|
+
- 29e2e28: The seam between the three repositories is documented, and the reason given for one contract was corrected.
|
|
338
|
+
|
|
339
|
+
`loopzero-gateway`'s README — the npm page — now says which repository owns which half: LoopZero the
|
|
340
|
+
HTTP route and the signature check, these packages the translation of the payload it hands over, the
|
|
341
|
+
SDK one redaction helper. A `quality:integration-story` gate fails when that disappears and passes
|
|
342
|
+
when the prose is rewritten around the same facts.
|
|
343
|
+
|
|
344
|
+
Both adapters' published docblocks stated that a LoopZero app's `onMessage` runs AFTER the 200 is
|
|
345
|
+
answered, so a throw there had no status left to change. Measured against `loopzero@0.48.14`,
|
|
346
|
+
`handleChannelWebhook` awaits `onMessage` BEFORE building the response and catches nothing around
|
|
347
|
+
it: a throw means the 200 is never built, and mounted in a LoopZero route the rejection reaches that
|
|
348
|
+
route's error boundary and is answered 500 where the platform expected an acknowledgement. `parseInbound` returning `null`
|
|
349
|
+
is unchanged and still the right contract — only the stated reason was wrong, and it was reaching
|
|
350
|
+
users through the `.d.ts` on hover.
|
|
351
|
+
|
|
352
|
+
`loopzero-gateway-sms`'s docblocks also named the wrong seam. Its `parseInbound` is
|
|
353
|
+
`(options, ctx)`, and the `SignatureContext` it needs carries the raw body, the headers and the URL
|
|
354
|
+
— none of which LoopZero's `ChannelMessage` provides, so the signature check cannot be performed
|
|
355
|
+
from inside `onMessage` for any provider. SMS goes through its own `createWebhookServer`, and the
|
|
356
|
+
published `.d.ts` says so now instead of claiming to be the gateway half of the channel seam.
|
|
357
|
+
|
|
358
|
+
## 0.2.1
|
|
359
|
+
|
|
360
|
+
### Patch Changes
|
|
361
|
+
|
|
362
|
+
- Every credential field now says what the platform calls it and where it is issued.
|
|
363
|
+
|
|
364
|
+
Measured: a developer who wires one adapter and carries its field name to the next gets
|
|
365
|
+
`error TS2353: … 'token' does not exist in type 'SlackAdapterOptions'`. That names the wrong field
|
|
366
|
+
and the type, and never the right one — so the answer was always one file away.
|
|
367
|
+
|
|
368
|
+
These docblocks are on published option types, so an editor now shows the answer on hover and
|
|
369
|
+
completion. All 15 credential-bearing fields across the ten packages are covered, including the ones
|
|
370
|
+
beyond each adapter's primary token: Slack's `appToken`, LINE's `channelSecret`, Vonage's
|
|
371
|
+
`apiSecret` and `signatureSecret`, WhatsApp's `appSecret`.
|
|
372
|
+
|
|
373
|
+
**Nothing was renamed.** Six of the ten primary names are the platform's own key, pinned against the
|
|
374
|
+
SDK's own declaration — `channelAccessToken` in `@line/bot-sdk`, `clientSecret` in
|
|
375
|
+
`@microsoft/teams.apps`, `accessToken` in `matrix-js-sdk`, `token` in `grammy` and `discord.js`,
|
|
376
|
+
`authToken` in `twilio`. Where ours diverges, the docblock says so rather than implying otherwise:
|
|
377
|
+
`botToken` (deliberate — the adapter also takes an `appToken`), Mattermost's `accessToken` against
|
|
378
|
+
its client's `token`, and `password` against nodemailer's `pass`.
|
|
379
|
+
|
|
380
|
+
## 0.2.0
|
|
381
|
+
|
|
382
|
+
### Minor Changes
|
|
383
|
+
|
|
384
|
+
- `parseInbound` — translate a raw webhook payload without re-declaring the platform's wire format.
|
|
385
|
+
|
|
386
|
+
An app receiving a message through LoopZero's channel seam gets `payload: unknown` and, until now,
|
|
387
|
+
had to parse it by hand. Measured against the published packages: wiring Telegram took 35 lines, 27
|
|
388
|
+
of them the app re-declaring Telegram's own format — that `caption` is the fallback for `text`, that
|
|
389
|
+
`message_thread_id` distinguishes a forum topic. It is now 13 lines and none.
|
|
390
|
+
|
|
391
|
+
```ts
|
|
392
|
+
import { parseInbound } from "loopzero-gateway-telegram";
|
|
393
|
+
|
|
394
|
+
const event = parseInbound(await request.json());
|
|
395
|
+
if (event !== null) console.log(event.text);
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
**Telegram** — `parseInbound(payload)`. One mapping serves both this and the polling path, so a
|
|
399
|
+
webhook-delivered message and a polled one cannot produce different events.
|
|
400
|
+
|
|
401
|
+
**SMS** — `parseInbound(options, ctx)`. Takes the adapter options an app already holds, because
|
|
402
|
+
parsing is provider-specific and, for Twilio, country-dependent. `createBackend` runs outside the
|
|
403
|
+
error boundary, so an unsupported backend surfaces instead of becoming the same `null` a malformed
|
|
404
|
+
body produces.
|
|
405
|
+
|
|
406
|
+
Both return `null` and never throw. `onMessage` runs after LoopZero has already answered 200, so a
|
|
407
|
+
throw there is an unhandled rejection with no status left to change. Every field either translator
|
|
408
|
+
copies is narrowed at the boundary: a payload with `text: 5` yields `text: ""`, and one with a
|
|
409
|
+
non-finite `date`, `message_id`, `chat.id`, thread id, sender id or reply id is rejected or dropped
|
|
410
|
+
rather than producing an event whose declared types are lies.
|
|
411
|
+
|
|
412
|
+
`loopzero-gateway-line` and `loopzero-gateway-whatsapp` already shipped this shape and are unchanged.
|
|
413
|
+
|
|
414
|
+
## 0.1.4
|
|
415
|
+
|
|
416
|
+
### Patch Changes
|
|
417
|
+
|
|
418
|
+
- Drop the unused `loopzero-sdk` peer dependency, so a LoopZero app can install an adapter.
|
|
419
|
+
|
|
420
|
+
Every adapter declared `peer loopzero-sdk@^2.18.0` and imported the SDK in **zero** source files.
|
|
421
|
+
The framework ships `loopzero-sdk@4.x`, so `npm install loopzero-gateway-line` into a LoopZero app
|
|
422
|
+
failed outright with `ERESOLVE`.
|
|
423
|
+
|
|
424
|
+
The core's range was widened in `loopzero-gateway@0.7.0`, which was not enough on its own: an
|
|
425
|
+
adapter's own manifest still carried the pin, so installing one still failed even against the fixed
|
|
426
|
+
core. Measured in a real app before and after.
|
|
427
|
+
|
|
428
|
+
## 0.1.3
|
|
429
|
+
|
|
430
|
+
### Patch Changes
|
|
431
|
+
|
|
432
|
+
- 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.
|
|
433
|
+
|
|
434
|
+
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.
|
|
435
|
+
|
|
436
|
+
**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.
|
|
437
|
+
|
|
438
|
+
**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`.
|
|
439
|
+
|
|
440
|
+
**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.
|
|
441
|
+
|
|
442
|
+
**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.
|
|
443
|
+
|
|
444
|
+
- 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.
|
|
445
|
+
|
|
446
|
+
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.
|
|
447
|
+
|
|
448
|
+
**`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.
|
|
449
|
+
|
|
450
|
+
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.
|
|
451
|
+
|
|
452
|
+
- 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.
|
|
453
|
+
|
|
454
|
+
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.
|
|
455
|
+
|
|
456
|
+
**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.
|
|
457
|
+
|
|
458
|
+
- 5bae032: Six defects that broke real conversations, found by testing the adapters against the live platforms instead of against fakes.
|
|
459
|
+
|
|
460
|
+
**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.
|
|
461
|
+
|
|
462
|
+
**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.
|
|
463
|
+
|
|
464
|
+
**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.
|
|
465
|
+
|
|
466
|
+
**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.
|
|
467
|
+
|
|
468
|
+
**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.
|
|
469
|
+
|
|
470
|
+
**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.
|
|
471
|
+
|
|
472
|
+
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.
|
|
473
|
+
|
|
474
|
+
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.
|
|
475
|
+
|
|
476
|
+
## 0.1.2
|
|
477
|
+
|
|
478
|
+
### Patch Changes
|
|
479
|
+
|
|
480
|
+
- 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.
|
|
481
|
+
|
|
482
|
+
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.
|
|
483
|
+
|
|
484
|
+
**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.
|
|
485
|
+
|
|
486
|
+
- 5bae032: Six defects that broke real conversations, found by testing the adapters against the live platforms instead of against fakes.
|
|
487
|
+
|
|
488
|
+
**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.
|
|
489
|
+
|
|
490
|
+
**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.
|
|
491
|
+
|
|
492
|
+
**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.
|
|
493
|
+
|
|
494
|
+
**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.
|
|
495
|
+
|
|
496
|
+
**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.
|
|
497
|
+
|
|
498
|
+
**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.
|
|
499
|
+
|
|
500
|
+
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.
|
|
501
|
+
|
|
502
|
+
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.
|
|
503
|
+
|
|
504
|
+
## 0.1.1
|
|
505
|
+
|
|
506
|
+
### Patch Changes
|
|
507
|
+
|
|
508
|
+
- 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).
|
|
509
|
+
|
|
510
|
+
## 2.0.0
|
|
511
|
+
|
|
512
|
+
### Patch Changes
|
|
513
|
+
|
|
514
|
+
- Updated dependencies
|
|
515
|
+
- loopzero-sdk@1.3.0
|
|
516
|
+
- loopzero-gateway@2.0.0
|
|
517
|
+
|
|
518
|
+
## 1.0.0
|
|
519
|
+
|
|
520
|
+
### Patch Changes
|
|
521
|
+
|
|
522
|
+
- Updated dependencies
|
|
523
|
+
- loopzero-sdk@1.2.0
|
|
524
|
+
- loopzero-gateway@1.0.0
|
|
525
|
+
|
|
526
|
+
## [0.1.0] — 2026-05-20
|
|
527
|
+
|
|
528
|
+
### Added
|
|
529
|
+
|
|
530
|
+
- Initial release. `TelegramAdapter` wraps grammy in the `loopzero-gateway` `BasePlatformAdapter` contract.
|
|
531
|
+
- `shouldRespondInChat(ctx, policy)` helper for group-chat filtering.
|
|
532
|
+
- `splitForTelegram(text)` helper for auto-splitting >4096-char messages.
|
|
533
|
+
- EC-I: invalid token resolves `connect()` to `false` (never throws).
|
|
534
|
+
- EC-J: `splitForTelegram` preserves markdown pair integrity.
|
|
535
|
+
- EC-K: ignores messages where `ctx.from.is_bot === true`.
|