@ours.network/tg-connector 0.5.1-nightly.1 → 0.5.1-nightly.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +40 -11
  2. package/dist/connector.js +1122 -124
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -53,8 +53,9 @@ customers; escalate refunds to a human").
53
53
  **message envelope** (sender + chat metadata, reply/forward context, and any
54
54
  attached file via the core 3.1 file channel — see
55
55
  [Message envelope](#message-envelope) and [File transfer](#file-transfer-core-31));
56
- - every message the agent sends back is delivered to that same chat/topic, and
57
- a file the agent sends is delivered with `sendDocument`.
56
+ - every message the agent sends back is delivered to that same chat/topic with
57
+ Markdown formatting and exact reply threading when `reply_to.wire_id` is
58
+ available; a file the agent sends is delivered with `sendDocument`.
58
59
  5. Re-run `add_new_connection` with the **same `--bot`** and a different
59
60
  `--chat-id`/`--thread-id` to add more routes on the one bot. Point two routes at
60
61
  the same agent and it sees two distinct contacts (distinct bios) — one per chat.
@@ -69,8 +70,9 @@ its native voice-transcription path even when no companion text is sent.
69
70
 
70
71
  Messages are end-to-end encrypted between the connector's route identity and the agent (ADAPT
71
72
  encrypted channels). The connector never persists message bodies to disk — only the
72
- bot registry (`bot name`, `token`, `@username`) and route metadata (`bot name`,
73
- `chat id`, `thread id`, `bio`, `peer cid`, and stable daemon lease). Those
73
+ bot registry (`bot name`, `token`, `@username`), route metadata (`bot name`,
74
+ `chat id`, `thread id`, `bio`, `peer cid`, and stable daemon lease), and a bounded
75
+ 30-day wire-id ↔ Telegram-message-id map with per-route receipt settings. Those
74
76
  persisted route names are also the connector's simple list of identities it
75
77
  created. The list is organizational bookkeeping, not an authorization or
76
78
  provenance boundary; identity keys and packet state stay in the shared daemon.
@@ -165,19 +167,46 @@ distinct from `send_message`, so files and text are always separate messages.
165
167
  read files from the file channel and correlate by `attachment.wire_id`** — an
166
168
  agent that still expects inline base64 will not see the bytes.
167
169
  - **Outbound (agent → Telegram).** A file the agent sends arrives via
168
- `receive_file`, is stored in the daemon identity's file inbox (same unread → processed →
169
- gc lifecycle as messages, bytes included), and is delivered to the chat (and
170
- forum topic, if pinned) with Telegram **`sendDocument`** — preserving the
171
- original filename. Agent → Telegram file sending was previously unsupported.
170
+ `receive_file`, is stored in the daemon's durable per-identity history, and is
171
+ delivered to the chat (and forum topic, if pinned) with Telegram
172
+ **`sendDocument`** — preserving the original filename. The connector first
173
+ lists unread metadata, reads the immutable blob, uploads it to Telegram, and
174
+ only then acknowledges that exact `wire_id` with selected `getFiles`.
172
175
  - **Caps.** Inbound media is bounded by `attachmentMaxBytes`
173
176
  (`OURS_TG_ATTACHMENT_MAX_BYTES`, **10 MB**, under Telegram's 20 MB bot
174
177
  download limit). A file a contact sends outbound is bounded by
175
178
  `outboundFileMaxBytes` (`OURS_TG_OUTBOUND_FILE_MAX_BYTES`, **50 MB**,
176
179
  Telegram's `sendDocument` upper bound); an over-cap outbound file is skipped and
177
180
  logged.
178
- - **Monitoring.** File traffic is monitored exactly like messages: a bound control
179
- plane receives a forced **metadata-only** copy (`[file] <name> (<mime>, <N> B)`)
180
- — never the bytes.
181
+
182
+ ### Replies, formatting, and receipts
183
+
184
+ - Telegram entities (bold, italic, code, links, quotes, and related formatting)
185
+ are converted to Markdown for the agent. Agent Markdown is rendered as
186
+ Telegram MarkdownV2, with a plain-text fallback if Telegram rejects the parse.
187
+ - The bounded wire-id map lets agent `reply_to.wire_id` pointers become native
188
+ Telegram replies. Telegram replies are likewise sent with a structured ours
189
+ reply pointer when their exact mapped message is still retained. Missing or
190
+ expired mappings degrade to an unthreaded message; the connector never guesses.
191
+ - Delivery and read receipts become one Telegram reaction per message (`👀` then
192
+ `👌` by default). `/receipts` and `/emoji` configure them per route, and
193
+ `/help` reports the active settings. Receipt state is monotonic and is caught
194
+ up from durable outbound history after a restart or `sync_required` event.
195
+
196
+ ### External delivery boundary
197
+
198
+ Agent messages are delivered oldest-first from the daemon's durable history.
199
+ The connector uses `listIncomingMessages` plus `getHistoryItem` to inspect one
200
+ unread body without changing state, sends it to Telegram, then acknowledges it
201
+ with `getMessages({limit:1})` and verifies the returned `wire_id` is the one it
202
+ just delivered. Per-route single-flight drains prevent concurrent notifications
203
+ from racing acknowledgements. Telegram failures leave the oldest item unread.
204
+
205
+ There is one unavoidable external side-effect window: if Telegram accepts a
206
+ message or file and the process crashes before the daemon acknowledgement, the
207
+ item stays unread and may be delivered again after restart. The connector favors
208
+ recoverability over silently losing content and does not depend on removed
209
+ defer/requeue or conversation-policy APIs.
181
210
 
182
211
  ### Voice transcription (speech-to-text)
183
212