@ours.network/tg-connector 0.3.1 → 0.3.3-nightly.1
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/README.md +35 -35
- package/dist/cli.js +27 -70
- package/dist/connector.js +53242 -8193
- package/docs/voice-message-contract.md +8 -2
- package/package.json +3 -5
- package/dist/mufl_code/8A84AD8E225F186F666D3EAB2AFF777A4B9BB1B9C7CCF45CF364497EF16CF3E5.muflo +0 -0
- package/dist/mufl_code/actor.mu +0 -1833
- package/dist/mufl_code/config.mufl +0 -27
- package/dist/mufl_code/core/COMMERCIAL-LICENCE.md +0 -25
- package/dist/mufl_code/core/COMPATIBILITY.md +0 -221
- package/dist/mufl_code/core/CONTRIBUTING.md +0 -37
- package/dist/mufl_code/core/LICENSE +0 -98
- package/dist/mufl_code/core/NOTIFICATIONS_CONTRACT.md +0 -290
- package/dist/mufl_code/core/README.md +0 -91
- package/dist/mufl_code/core/SECURITY.md +0 -40
- package/dist/mufl_code/core/TRADEMARKS.md +0 -24
- package/dist/mufl_code/core/a2a_capabilities.mm +0 -449
- package/dist/mufl_code/core/a2a_cluster.mm +0 -601
- package/dist/mufl_code/core/a2a_control.mm +0 -90
- package/dist/mufl_code/core/a2a_messaging.mm +0 -4817
- package/dist/mufl_code/core/a2a_monitoring.mm +0 -94
- package/dist/mufl_code/core/a2a_notification_integration.mm +0 -144
- package/dist/mufl_code/core/a2a_notifications.mm +0 -1127
- package/dist/mufl_code/core/a2a_protocol.mm +0 -246
- package/dist/mufl_code/core/a2a_versions.mm +0 -801
- package/dist/mufl_code/core/config.mufl +0 -29
- package/dist/mufl_code/core/docs/.vitepress/config.mts +0 -58
- package/dist/mufl_code/core/docs/citations.json +0 -688
- package/dist/mufl_code/core/docs/guide/01-vendor-the-core.md +0 -50
- package/dist/mufl_code/core/docs/guide/02-configure-and-compile.md +0 -100
- package/dist/mufl_code/core/docs/guide/03-wire-the-host.md +0 -154
- package/dist/mufl_code/core/docs/guide/04-connect-and-message.md +0 -156
- package/dist/mufl_code/core/docs/guide/05-test-your-app.md +0 -75
- package/dist/mufl_code/core/docs/guide/index.md +0 -63
- package/dist/mufl_code/core/docs/how-it-works/capabilities-and-control.md +0 -77
- package/dist/mufl_code/core/docs/how-it-works/cluster.md +0 -65
- package/dist/mufl_code/core/docs/how-it-works/identity.md +0 -56
- package/dist/mufl_code/core/docs/how-it-works/invites-and-contacts.md +0 -76
- package/dist/mufl_code/core/docs/how-it-works/messaging.md +0 -55
- package/dist/mufl_code/core/docs/how-it-works/monitoring-and-config.md +0 -72
- package/dist/mufl_code/core/docs/how-it-works/overview.md +0 -45
- package/dist/mufl_code/core/docs/how-it-works/versioning.md +0 -116
- package/dist/mufl_code/core/docs/index.md +0 -27
- package/dist/mufl_code/core/docs/package-lock.json +0 -3467
- package/dist/mufl_code/core/docs/package.json +0 -15
- package/dist/mufl_code/core/docs/reference/contributing.md +0 -26
- package/dist/mufl_code/core/docs/reference/glossary.md +0 -108
- package/dist/mufl_code/core/docs/reference/implementations.md +0 -23
- package/dist/mufl_code/core/docs/reference/modules.md +0 -19
- package/dist/mufl_code/core/docs/scripts/check-citations.mjs +0 -36
- package/dist/mufl_code/core/docs/scripts/check-denylist.mjs +0 -30
- package/dist/mufl_code/core/docs/scripts/gen-llms.mjs +0 -32
- package/dist/mufl_code/core/docs/workflows/cluster.md +0 -89
- package/dist/mufl_code/core/docs/workflows/contact-exchange.md +0 -60
- package/dist/mufl_code/core/docs/workflows/contact-restore.md +0 -60
- package/dist/mufl_code/core/docs/workflows/control-verbs.md +0 -70
- package/dist/mufl_code/core/docs/workflows/index.md +0 -57
- package/dist/mufl_code/core/docs/workflows/introductions.md +0 -60
- package/dist/mufl_code/core/docs/workflows/messaging.md +0 -75
- package/dist/mufl_code/core/docs/workflows/monitoring.md +0 -84
- package/dist/mufl_code/core/docs/workflows/notifications.md +0 -109
- package/dist/mufl_code/core/release-notes/0.1.md +0 -60
- package/dist/mufl_code/core/release-notes/0.3.md +0 -22
- package/dist/mufl_code/core/release-notes/0.4.md +0 -97
- package/dist/mufl_code/core/tests/README.md +0 -83
- package/dist/mufl_code/core/tests/compat/README.md +0 -82
- package/dist/mufl_code/core/tests/compat/compat.mjs +0 -245
- package/dist/mufl_code/core/tests/compat/compat_peer.mjs +0 -146
- package/dist/mufl_code/core/tests/compat/run_compat.sh +0 -96
- package/dist/mufl_code/core/tests/corpus.mjs +0 -139
- package/dist/mufl_code/core/tests/corpus_actor.mu +0 -242
- package/dist/mufl_code/core/tests/fatcompile_actor.mu +0 -52
- package/dist/mufl_code/core/tests/mig.mjs +0 -805
- package/dist/mufl_code/core/tests/mig_actor.mu +0 -518
- package/dist/mufl_code/core/tests/migapp.mjs +0 -431
- package/dist/mufl_code/core/tests/migapp_actor.mu +0 -294
- package/dist/mufl_code/core/tests/mufl_semantics/run.sh +0 -69
- package/dist/mufl_code/core/tests/mufl_semantics/t11_three_version.mufl +0 -47
- package/dist/mufl_code/core/tests/mufl_semantics/t2_extra_fields.mufl +0 -11
- package/dist/mufl_code/core/tests/mufl_semantics/t7_runtime.mufl +0 -30
- package/dist/mufl_code/core/tests/mufl_semantics/t9_passthrough.mufl +0 -19
- package/dist/mufl_code/core/tests/mufl_semantics/t_str_order.mufl +0 -19
- package/dist/mufl_code/core/tests/notif.mjs +0 -755
- package/dist/mufl_code/core/tests/notif_actor.mu +0 -450
- package/dist/mufl_code/core/tests/protocol_container.mm +0 -18
- package/dist/mufl_code/core/tests/run.sh +0 -65
- package/dist/mufl_code/core/tests/run_corpus.sh +0 -51
- package/dist/mufl_code/core/tests/run_fatcompile.sh +0 -40
- package/dist/mufl_code/core/tests/run_mig.sh +0 -51
- package/dist/mufl_code/core/tests/run_migapp.sh +0 -51
- package/dist/mufl_code/core/tests/run_notif.sh +0 -57
- package/dist/mufl_code/core/tests/test.mjs +0 -750
- package/dist/mufl_code/core/tests/test_actor.mu +0 -564
- package/dist/mufl_code/core/tests/test_common.mjs +0 -93
- package/dist/mufl_code/core/version.mm +0 -24
- package/dist/mufl_code/protocol_container.mm +0 -18
package/README.md
CHANGED
|
@@ -59,6 +59,14 @@ customers; escalate refunds to a human").
|
|
|
59
59
|
`--chat-id`/`--thread-id` to add more routes on the one bot. Point two routes at
|
|
60
60
|
the same agent and it sees two distinct contacts (distinct bios) — one per chat.
|
|
61
61
|
|
|
62
|
+
For a one-to-one route, add `--payload-mode plain` (or `--plain`) to forward
|
|
63
|
+
message text directly without the Telegram JSON envelope. The default remains
|
|
64
|
+
`envelope`, which is required for groups/topics where per-message sender and chat
|
|
65
|
+
metadata distinguishes participants. Files always use the core file channel in
|
|
66
|
+
both modes; Telegram voice notes retain the protocol MIME marker
|
|
67
|
+
`audio/ogg; x-ours-kind=voice-message`, allowing the receiving daemon to invoke
|
|
68
|
+
its native voice-transcription path even when no companion text is sent.
|
|
69
|
+
|
|
62
70
|
Messages are end-to-end encrypted between the connector packet and the agent (ADAPT
|
|
63
71
|
encrypted channels). The connector never persists message bodies to disk — only the
|
|
64
72
|
bot registry (`bot name`, `token`, `@username`), the per-route seed + serialized
|
|
@@ -192,8 +200,15 @@ added for provenance:
|
|
|
192
200
|
}
|
|
193
201
|
```
|
|
194
202
|
|
|
195
|
-
- **Opt-in
|
|
196
|
-
|
|
203
|
+
- **Opt-in, and it covers THIS PROCESS ONLY.** Off by default
|
|
204
|
+
(`sttEnabled:false`), which means *the connector* sends no audio to a
|
|
205
|
+
speech-to-text provider. It does **not** mean the audio is never transcribed:
|
|
206
|
+
the connector is a client of an ours daemon, and **the daemon runs its own
|
|
207
|
+
speech-to-text** when the receiving side pulls a voice note — under
|
|
208
|
+
configuration this connector's operator does not control and may not know
|
|
209
|
+
exists. When the connector was its own host, `sttEnabled:false` did cover the
|
|
210
|
+
whole path; attached, it no longer can. Turn it on and supply a key to
|
|
211
|
+
transcribe here as well (see [Configuration](#configuration)).
|
|
197
212
|
- **No transcoding.** Telegram voice is **OGG/Opus**, which OpenAI-compatible
|
|
198
213
|
transcription endpoints accept directly — the connector adds **no ffmpeg** and no
|
|
199
214
|
new dependency (just built-in `fetch`).
|
|
@@ -247,9 +262,11 @@ npm install
|
|
|
247
262
|
npm run build
|
|
248
263
|
```
|
|
249
264
|
|
|
250
|
-
Requires Node ≥ 20
|
|
251
|
-
|
|
252
|
-
|
|
265
|
+
Requires Node ≥ 20, and **an ours daemon already running on this box** — the
|
|
266
|
+
connector attaches to it over `/api/v1` and drives it through
|
|
267
|
+
[`@ours.network/sdk`](https://www.npmjs.com/package/@ours.network/sdk). It runs
|
|
268
|
+
no engine of its own: there is no native ADAPT SDK and no MUFL packet here, so
|
|
269
|
+
nothing beyond `npm install` is resolved at runtime.
|
|
253
270
|
|
|
254
271
|
## Usage
|
|
255
272
|
|
|
@@ -322,7 +339,8 @@ Precedence per field: **env var > `config.json` > default**. The config file is
|
|
|
322
339
|
|
|
323
340
|
| field | env var | default |
|
|
324
341
|
|----------------|---------------------------|-------------------------------------------------|
|
|
325
|
-
|
|
|
342
|
+
| daemon URL | `OURS_TG_DAEMON_URL` | `''` (the SDK's own default selection) |
|
|
343
|
+
| daemon state dir | `OURS_TG_DAEMON_STATE_DIR` | `''` (the SDK's own default selection) |
|
|
326
344
|
| control port | `OURS_TG_CONTROL_PORT` | `3051` (localhost only) |
|
|
327
345
|
| state dir | `OURS_TG_STATE_DIR` | `~/.ours-telegram` |
|
|
328
346
|
| poll timeout | `OURS_TG_POLL_TIMEOUT` | `30` (seconds, Telegram long-poll) |
|
|
@@ -332,7 +350,7 @@ Precedence per field: **env var > `config.json` > default**. The config file is
|
|
|
332
350
|
| retry backoff | `OURS_TG_FETCH_RETRY_BASE_MS` | `300` (base delay between those retries; grows exponentially with jitter) |
|
|
333
351
|
| attachment cap | `OURS_TG_ATTACHMENT_MAX_BYTES` | `10485760` (10 MB; larger inbound media forwarded as a metadata-only stub) |
|
|
334
352
|
| outbound file cap | `OURS_TG_OUTBOUND_FILE_MAX_BYTES` | `52428800` (50 MB; a larger file from a contact is skipped + logged — Telegram's `sendDocument` limit) |
|
|
335
|
-
| STT enabled | `OURS_TG_STT_ENABLED` | `false` (
|
|
353
|
+
| STT enabled | `OURS_TG_STT_ENABLED` | `false` (whether **this connector** transcribes voice; the attached daemon runs its own STT regardless — see [Voice](#voice-messages--speech-to-text)) |
|
|
336
354
|
| STT API key | `OURS_TG_STT_API_KEY` | `''` (secret; env preferred — masked if placed in `config.json`, never logged) |
|
|
337
355
|
| STT base URL | `OURS_TG_STT_BASE_URL` | `https://api.openai.com/v1` (OpenAI-compatible endpoint root; e.g. `https://api.groq.com/openai/v1` or a self-hosted whisper server) |
|
|
338
356
|
| STT model | `OURS_TG_STT_MODEL` | `whisper-1` (e.g. `whisper-large-v3-turbo` on Groq) |
|
|
@@ -345,36 +363,18 @@ Precedence per field: **env var > `config.json` > default**. The config file is
|
|
|
345
363
|
The control API is bound to `127.0.0.1` and unauthenticated — it manages bot
|
|
346
364
|
tokens, so do not expose the control port off-host.
|
|
347
365
|
|
|
348
|
-
## Control plane (
|
|
349
|
-
|
|
350
|
-
Each bridge is a self-sovereign ours node that can be **managed from the
|
|
351
|
-
ours messenger control plane** over the encrypted a2a_control
|
|
352
|
-
channel — no extra ports. The connector advertises an app manifest
|
|
353
|
-
(`network.ours.telegram-connector`) with a `core.configuration` capability, so the
|
|
354
|
-
messenger renders its generic config form for it. Two fields are configurable
|
|
355
|
-
live (no restart):
|
|
356
|
-
|
|
357
|
-
- **Allowed chat ID** — only this chat is proxied to the agent.
|
|
358
|
-
- **Denial message** — what any other chat is told.
|
|
359
|
-
|
|
360
|
-
(The bot token is *not* CP-configurable: the messenger strips secret-field values
|
|
361
|
-
on save, so the token stays set at connection creation.)
|
|
366
|
+
## Control plane (removed)
|
|
362
367
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
# 2. start the bind ceremony for that contact; read out the 6-digit code
|
|
371
|
-
ours-tg-connector bind_proxy supportbot <messenger-contact-name-or-cid>
|
|
372
|
-
# → enter the code in the messenger Control Panel (out-of-band, 5 min, 3 tries)
|
|
373
|
-
```
|
|
368
|
+
The connector used to be a **managed node**: it advertised an app manifest
|
|
369
|
+
(`network.ours.telegram-connector`) and the ours messenger could bind to it over
|
|
370
|
+
the a2a_control channel and edit the allowed chat id and denial message live.
|
|
371
|
+
That is gone — messenger manageability was removed by ruling, and with it the
|
|
372
|
+
`cp_invite` and `bind_proxy` commands, the `get_manifest` / `get_config` /
|
|
373
|
+
`set_config` verbs, and the bind ceremony.
|
|
374
374
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
375
|
+
A route is configured when it is created (`add_new_connection`) and changed by
|
|
376
|
+
removing it and adding it back. There is no live reconfiguration path, and
|
|
377
|
+
nothing to bind.
|
|
378
378
|
|
|
379
379
|
## Learn more
|
|
380
380
|
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { createRequire } from 'node:module'; const require =
|
|
2
|
+
import { createRequire as __tgCreateRequire } from 'node:module'; const require = __tgCreateRequire(import.meta.url);
|
|
3
3
|
|
|
4
4
|
// src/cli.ts
|
|
5
5
|
import { spawn, spawnSync } from "node:child_process";
|
|
@@ -14,7 +14,8 @@ import * as fs from "node:fs";
|
|
|
14
14
|
import { homedir } from "node:os";
|
|
15
15
|
import { resolve, join, dirname } from "node:path";
|
|
16
16
|
var DEFAULT_CONFIG = {
|
|
17
|
-
|
|
17
|
+
daemonUrl: "",
|
|
18
|
+
daemonStateDir: "",
|
|
18
19
|
controlPort: 3051,
|
|
19
20
|
stateDir: resolve(homedir(), ".ours-telegram"),
|
|
20
21
|
pollTimeoutSec: 30,
|
|
@@ -54,7 +55,8 @@ function readFileConfig() {
|
|
|
54
55
|
return {};
|
|
55
56
|
}
|
|
56
57
|
const out2 = {};
|
|
57
|
-
if (typeof parsed.
|
|
58
|
+
if (typeof parsed.daemonUrl === "string") out2.daemonUrl = parsed.daemonUrl;
|
|
59
|
+
if (typeof parsed.daemonStateDir === "string") out2.daemonStateDir = resolve(parsed.daemonStateDir);
|
|
58
60
|
if (typeof parsed.controlPort === "number" && Number.isFinite(parsed.controlPort)) out2.controlPort = parsed.controlPort;
|
|
59
61
|
if (typeof parsed.stateDir === "string") out2.stateDir = resolve(parsed.stateDir);
|
|
60
62
|
if (typeof parsed.pollTimeoutSec === "number" && Number.isFinite(parsed.pollTimeoutSec)) {
|
|
@@ -101,7 +103,11 @@ function envBool(name) {
|
|
|
101
103
|
function loadConfig() {
|
|
102
104
|
const file = readFileConfig();
|
|
103
105
|
return {
|
|
104
|
-
|
|
106
|
+
// NOTE: no OURS_TG_BROKER_URL any more. The connector does not talk to a
|
|
107
|
+
// broker — the daemon does. A stale one in a config file is now ignored
|
|
108
|
+
// rather than half-honoured.
|
|
109
|
+
daemonUrl: process.env.OURS_TG_DAEMON_URL ?? file.daemonUrl ?? DEFAULT_CONFIG.daemonUrl,
|
|
110
|
+
daemonStateDir: process.env.OURS_TG_DAEMON_STATE_DIR ?? file.daemonStateDir ?? DEFAULT_CONFIG.daemonStateDir,
|
|
105
111
|
controlPort: envInt("OURS_TG_CONTROL_PORT") ?? file.controlPort ?? DEFAULT_CONFIG.controlPort,
|
|
106
112
|
stateDir: resolve(process.env.OURS_TG_STATE_DIR ?? file.stateDir ?? DEFAULT_CONFIG.stateDir),
|
|
107
113
|
pollTimeoutSec: envInt("OURS_TG_POLL_TIMEOUT") ?? file.pollTimeoutSec ?? DEFAULT_CONFIG.pollTimeoutSec,
|
|
@@ -212,7 +218,7 @@ async function cmdStart() {
|
|
|
212
218
|
const ready = await waitForPort(PORT);
|
|
213
219
|
if (ready) {
|
|
214
220
|
out(`up on ${BASE}`);
|
|
215
|
-
out(`
|
|
221
|
+
out(` daemon: ${CONFIG.daemonUrl || "(default selection)"}`);
|
|
216
222
|
out(` state: ${STATE_DIR}`);
|
|
217
223
|
out(` logs: ${LOG_PATH}`);
|
|
218
224
|
} else {
|
|
@@ -257,7 +263,7 @@ async function cmdStatus() {
|
|
|
257
263
|
out("ours-tg-connector: running");
|
|
258
264
|
if (pid) out(` pid: ${pid}`);
|
|
259
265
|
out(` url: ${BASE} ${up ? "(reachable)" : "(port not answering!)"}`);
|
|
260
|
-
out(`
|
|
266
|
+
out(` daemon: ${CONFIG.daemonUrl || "(default selection)"}`);
|
|
261
267
|
out(` state: ${STATE_DIR}`);
|
|
262
268
|
out(` logs: ${LOG_PATH}`);
|
|
263
269
|
if (up) {
|
|
@@ -365,7 +371,7 @@ async function cmdRemoveBot(name) {
|
|
|
365
371
|
async function cmdAddConnection(argv) {
|
|
366
372
|
const positionals = argv.filter((a) => !a.startsWith("--"));
|
|
367
373
|
const flagged = /* @__PURE__ */ new Set();
|
|
368
|
-
for (const f of ["--name", "--bot", "--chat-id", "--thread-id", "--label", "--bio"]) {
|
|
374
|
+
for (const f of ["--name", "--bot", "--chat-id", "--thread-id", "--label", "--bio", "--payload-mode"]) {
|
|
369
375
|
const i = argv.indexOf(f);
|
|
370
376
|
if (i >= 0 && i + 1 < argv.length) flagged.add(argv[i + 1]);
|
|
371
377
|
}
|
|
@@ -376,6 +382,7 @@ async function cmdAddConnection(argv) {
|
|
|
376
382
|
const threadId = (flagValue(argv, "--thread-id", "--topic") ?? "").trim();
|
|
377
383
|
const label = (flagValue(argv, "--label") ?? "").trim();
|
|
378
384
|
const bio = (flagValue(argv, "--bio") ?? "").trim();
|
|
385
|
+
const payloadMode = (flagValue(argv, "--payload-mode") ?? (argv.includes("--plain") ? "plain" : "envelope")).trim();
|
|
379
386
|
if (!name || !botName || !chatId) {
|
|
380
387
|
err("add_new_connection requires --name, --bot and --chat-id");
|
|
381
388
|
err(" (register the bot first: ours-tg-connector add_bot <name> <token>)");
|
|
@@ -384,13 +391,17 @@ async function cmdAddConnection(argv) {
|
|
|
384
391
|
err(' [--thread-id 42] [--bio "ACME #support \u2014 paying customers"]');
|
|
385
392
|
process.exit(1);
|
|
386
393
|
}
|
|
394
|
+
if (payloadMode !== "plain" && payloadMode !== "envelope") {
|
|
395
|
+
err('add_new_connection --payload-mode must be "plain" or "envelope"');
|
|
396
|
+
process.exit(1);
|
|
397
|
+
}
|
|
387
398
|
await ensureDaemon();
|
|
388
399
|
let res;
|
|
389
400
|
try {
|
|
390
401
|
res = await fetch(`${BASE}/connections`, {
|
|
391
402
|
method: "POST",
|
|
392
403
|
headers: { "Content-Type": "application/json" },
|
|
393
|
-
body: JSON.stringify({ name, botName, chatId, threadId, label, bio })
|
|
404
|
+
body: JSON.stringify({ name, botName, chatId, threadId, label, bio, payloadMode })
|
|
394
405
|
});
|
|
395
406
|
} catch (e) {
|
|
396
407
|
err(`failed to reach the daemon control API: ${String(e)}`);
|
|
@@ -407,6 +418,7 @@ async function cmdAddConnection(argv) {
|
|
|
407
418
|
out(` telegram bot: ${botName}${body.botUsername ? ` (@${body.botUsername})` : ""}`);
|
|
408
419
|
out(` bridged chat id: ${chatId}${threadId ? ` (topic ${threadId})` : ""}`);
|
|
409
420
|
if (bio) out(` identity bio: ${bio}`);
|
|
421
|
+
out(` inbound payload mode: ${payloadMode}`);
|
|
410
422
|
out("");
|
|
411
423
|
out("Paste this invite into your proxy agent (ours `add_contact`):");
|
|
412
424
|
out("");
|
|
@@ -446,59 +458,12 @@ async function cmdListConnections() {
|
|
|
446
458
|
out(` identity: ${c.cid}`);
|
|
447
459
|
out(` chat: ${chat}`);
|
|
448
460
|
if (c.bio) out(` bio: ${c.bio}`);
|
|
461
|
+
out(` payload: ${c.payloadMode}`);
|
|
449
462
|
out(` status: ${peer}`);
|
|
450
463
|
if (c.contacts.length) out(` contacts: ${c.contacts.map((x) => `${x.name} (${x.cid})`).join(", ")}`);
|
|
451
464
|
}
|
|
452
465
|
}
|
|
453
466
|
}
|
|
454
|
-
async function cmdCpInvite(name) {
|
|
455
|
-
if (!name) {
|
|
456
|
-
err("cp_invite requires a connection name.");
|
|
457
|
-
process.exit(1);
|
|
458
|
-
}
|
|
459
|
-
if (!await portOpen(PORT)) {
|
|
460
|
-
err("daemon not running \u2014 start it first.");
|
|
461
|
-
process.exit(1);
|
|
462
|
-
}
|
|
463
|
-
const res = await fetch(`${BASE}/connections/${encodeURIComponent(name)}/cp-invite`, { method: "POST" });
|
|
464
|
-
const body = await res.json();
|
|
465
|
-
if (!body.ok || !body.invite) {
|
|
466
|
-
err(`cp_invite failed: ${body.error ?? `HTTP ${res.status}`}`);
|
|
467
|
-
process.exit(1);
|
|
468
|
-
}
|
|
469
|
-
out("");
|
|
470
|
-
out(`Add the messenger control plane as a contact of "${name}".`);
|
|
471
|
-
out("Paste this invite into the messenger (add contact / add node):");
|
|
472
|
-
out("");
|
|
473
|
-
out(body.invite);
|
|
474
|
-
out("");
|
|
475
|
-
out(`Once it is a contact, bind it: ours-tg-connector bind_proxy ${name} <contact-name-or-cid>`);
|
|
476
|
-
}
|
|
477
|
-
async function cmdBindProxy(name, contact) {
|
|
478
|
-
if (!name || !contact) {
|
|
479
|
-
err("bind_proxy requires <connection-name> <contact-name-or-cid>.");
|
|
480
|
-
process.exit(1);
|
|
481
|
-
}
|
|
482
|
-
if (!await portOpen(PORT)) {
|
|
483
|
-
err("daemon not running \u2014 start it first.");
|
|
484
|
-
process.exit(1);
|
|
485
|
-
}
|
|
486
|
-
const res = await fetch(`${BASE}/connections/${encodeURIComponent(name)}/bind`, {
|
|
487
|
-
method: "POST",
|
|
488
|
-
headers: { "Content-Type": "application/json" },
|
|
489
|
-
body: JSON.stringify({ contact })
|
|
490
|
-
});
|
|
491
|
-
const body = await res.json();
|
|
492
|
-
if (!body.ok || !body.code) {
|
|
493
|
-
err(`bind_proxy failed: ${body.error ?? `HTTP ${res.status}`}`);
|
|
494
|
-
process.exit(1);
|
|
495
|
-
}
|
|
496
|
-
out("");
|
|
497
|
-
out(`Verification code: ${body.code}`);
|
|
498
|
-
out("");
|
|
499
|
-
out("Enter it in the messenger Control Panel within 5 minutes (3 attempts).");
|
|
500
|
-
out("Do NOT send it over ours \u2014 it must travel out-of-band (this terminal counts).");
|
|
501
|
-
}
|
|
502
467
|
async function cmdRemoveConnection(name) {
|
|
503
468
|
if (!name) {
|
|
504
469
|
err("remove_connection requires a connection name.");
|
|
@@ -530,7 +495,8 @@ function run(cmd, args) {
|
|
|
530
495
|
}
|
|
531
496
|
function serviceEnv() {
|
|
532
497
|
return {
|
|
533
|
-
|
|
498
|
+
OURS_TG_DAEMON_URL: CONFIG.daemonUrl,
|
|
499
|
+
OURS_TG_DAEMON_STATE_DIR: CONFIG.daemonStateDir,
|
|
534
500
|
OURS_TG_CONTROL_PORT: String(CONFIG.controlPort),
|
|
535
501
|
OURS_TG_STATE_DIR: STATE_DIR,
|
|
536
502
|
OURS_TG_POLL_TIMEOUT: String(CONFIG.pollTimeoutSec)
|
|
@@ -660,16 +626,14 @@ function usage() {
|
|
|
660
626
|
out(" routes:");
|
|
661
627
|
out(" add_new_connection create a chat\u2194agent route (one identity) and print an invite");
|
|
662
628
|
out(" --name <n> --bot <bot-name> --chat-id <c> [--thread-id <topic>] [--label <l>] [--bio <text>]");
|
|
629
|
+
out(" [--payload-mode envelope|plain] [--plain]");
|
|
663
630
|
out(" (positional also accepted: add_new_connection <name> <bot-name> <chat-id>)");
|
|
664
631
|
out(" reuse the same --bot with different --chat-id/--thread-id to bridge many");
|
|
665
632
|
out(" chats/topics through one bot; --bio gives the agent that chat's context");
|
|
633
|
+
out(" envelope is the safe default for groups; plain forwards DM text without JSON metadata");
|
|
666
634
|
out(" list_connections list configured routes grouped by bot");
|
|
667
635
|
out(" remove_connection <name> delete a route and its state");
|
|
668
636
|
out("");
|
|
669
|
-
out(" control plane (ours messenger):");
|
|
670
|
-
out(" cp_invite <name> print an invite to add the messenger as a contact");
|
|
671
|
-
out(" bind_proxy <name> <contact> start binding the messenger as control plane (prints a 6-digit code)");
|
|
672
|
-
out("");
|
|
673
637
|
out(" start start the daemon in the background");
|
|
674
638
|
out(" stop stop the running daemon");
|
|
675
639
|
out(" restart stop then start");
|
|
@@ -681,7 +645,8 @@ function usage() {
|
|
|
681
645
|
out("");
|
|
682
646
|
out("Config precedence (per field): env var > config.json > default.");
|
|
683
647
|
out(" config.json: OURS_TG_CONFIG, else ~/.ours-telegram/config.json");
|
|
684
|
-
out(" env:
|
|
648
|
+
out(" env: OURS_TG_DAEMON_URL + OURS_TG_DAEMON_STATE_DIR (both, or neither), OURS_TG_CONTROL_PORT (3051),");
|
|
649
|
+
out(" OURS_TG_STATE_DIR, OURS_TG_POLL_TIMEOUT (30)");
|
|
685
650
|
}
|
|
686
651
|
async function main() {
|
|
687
652
|
const cmd = process.argv[2] ?? "help";
|
|
@@ -732,14 +697,6 @@ async function main() {
|
|
|
732
697
|
case "remove":
|
|
733
698
|
await cmdRemoveConnection(process.argv[3]);
|
|
734
699
|
break;
|
|
735
|
-
case "cp_invite":
|
|
736
|
-
case "cp-invite":
|
|
737
|
-
await cmdCpInvite(process.argv[3]);
|
|
738
|
-
break;
|
|
739
|
-
case "bind_proxy":
|
|
740
|
-
case "bind-proxy":
|
|
741
|
-
await cmdBindProxy(process.argv[3], process.argv[4]);
|
|
742
|
-
break;
|
|
743
700
|
case "start":
|
|
744
701
|
await cmdStart();
|
|
745
702
|
break;
|