@ours.network/tg-connector 0.5.0 → 0.5.1-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 +55 -145
- package/dist/cli.js +91 -117
- package/dist/connector.js +1518 -2566
- package/docs/voice-message-contract.md +8 -2
- package/package.json +4 -5
- package/dist/mufl_code/ED9CAFA60E1A0884E2CBC8E71BA8A137488A14763C57587D25AEC4BAD7F58C81.muflo +0 -0
- package/dist/mufl_code/actor.mu +0 -1937
- 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/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,
|
|
@@ -123,6 +129,52 @@ function loadConfig() {
|
|
|
123
129
|
};
|
|
124
130
|
}
|
|
125
131
|
|
|
132
|
+
// src/service-definition.ts
|
|
133
|
+
function serviceEnvironment(config, stateDir) {
|
|
134
|
+
const env = {
|
|
135
|
+
OURS_TG_CONTROL_PORT: String(config.controlPort),
|
|
136
|
+
OURS_TG_STATE_DIR: stateDir,
|
|
137
|
+
OURS_TG_POLL_TIMEOUT: String(config.pollTimeoutSec)
|
|
138
|
+
};
|
|
139
|
+
if (config.daemonUrl) env.OURS_TG_DAEMON_URL = config.daemonUrl;
|
|
140
|
+
if (config.daemonStateDir) env.OURS_TG_DAEMON_STATE_DIR = config.daemonStateDir;
|
|
141
|
+
return env;
|
|
142
|
+
}
|
|
143
|
+
function xmlText(value) {
|
|
144
|
+
return String(value).replace(/[&<>"']/g, (character) => ({
|
|
145
|
+
"&": "&",
|
|
146
|
+
"<": "<",
|
|
147
|
+
">": ">",
|
|
148
|
+
'"': """,
|
|
149
|
+
"'": "'"
|
|
150
|
+
})[character]);
|
|
151
|
+
}
|
|
152
|
+
function launchdPlist(input) {
|
|
153
|
+
const envEntries = Object.entries(input.env).map(([key, value]) => ` <key>${xmlText(key)}</key><string>${xmlText(value)}</string>`).join("\n");
|
|
154
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
155
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
156
|
+
<plist version="1.0">
|
|
157
|
+
<dict>
|
|
158
|
+
<key>Label</key><string>${xmlText(input.label)}</string>
|
|
159
|
+
<key>ProgramArguments</key>
|
|
160
|
+
<array>
|
|
161
|
+
<string>${xmlText(input.execPath)}</string>
|
|
162
|
+
<string>${xmlText(input.self)}</string>
|
|
163
|
+
<string>serve</string>
|
|
164
|
+
</array>
|
|
165
|
+
<key>EnvironmentVariables</key>
|
|
166
|
+
<dict>
|
|
167
|
+
${envEntries}
|
|
168
|
+
</dict>
|
|
169
|
+
<key>RunAtLoad</key><true/>
|
|
170
|
+
<key>KeepAlive</key><true/>
|
|
171
|
+
<key>StandardOutPath</key><string>${xmlText(input.logPath)}</string>
|
|
172
|
+
<key>StandardErrorPath</key><string>${xmlText(input.logPath)}</string>
|
|
173
|
+
</dict>
|
|
174
|
+
</plist>
|
|
175
|
+
`;
|
|
176
|
+
}
|
|
177
|
+
|
|
126
178
|
// src/routing.ts
|
|
127
179
|
function looksLikeBotToken(s) {
|
|
128
180
|
return /^\d+:[A-Za-z0-9_-]+$/.test(s);
|
|
@@ -204,7 +256,7 @@ async function cmdStart() {
|
|
|
204
256
|
});
|
|
205
257
|
child.unref();
|
|
206
258
|
if (!child.pid) {
|
|
207
|
-
err("failed to spawn the
|
|
259
|
+
err("failed to spawn the connector.");
|
|
208
260
|
process.exit(1);
|
|
209
261
|
}
|
|
210
262
|
fs2.writeFileSync(PID_PATH, String(child.pid));
|
|
@@ -212,11 +264,11 @@ async function cmdStart() {
|
|
|
212
264
|
const ready = await waitForPort(PORT);
|
|
213
265
|
if (ready) {
|
|
214
266
|
out(`up on ${BASE}`);
|
|
215
|
-
out(`
|
|
267
|
+
out(` daemon: ${CONFIG.daemonUrl || "(default selection)"}`);
|
|
216
268
|
out(` state: ${STATE_DIR}`);
|
|
217
269
|
out(` logs: ${LOG_PATH}`);
|
|
218
270
|
} else {
|
|
219
|
-
err(`
|
|
271
|
+
err(`connector started (pid ${child.pid}) but control port ${PORT} did not open within 30s \u2014 check ${LOG_PATH}.`);
|
|
220
272
|
process.exit(1);
|
|
221
273
|
}
|
|
222
274
|
}
|
|
@@ -257,7 +309,7 @@ async function cmdStatus() {
|
|
|
257
309
|
out("ours-tg-connector: running");
|
|
258
310
|
if (pid) out(` pid: ${pid}`);
|
|
259
311
|
out(` url: ${BASE} ${up ? "(reachable)" : "(port not answering!)"}`);
|
|
260
|
-
out(`
|
|
312
|
+
out(` daemon: ${CONFIG.daemonUrl || "(default selection)"}`);
|
|
261
313
|
out(` state: ${STATE_DIR}`);
|
|
262
314
|
out(` logs: ${LOG_PATH}`);
|
|
263
315
|
if (up) {
|
|
@@ -269,12 +321,12 @@ async function cmdStatus() {
|
|
|
269
321
|
}
|
|
270
322
|
}
|
|
271
323
|
}
|
|
272
|
-
async function
|
|
324
|
+
async function ensureConnector() {
|
|
273
325
|
if (await portOpen(PORT)) return;
|
|
274
|
-
out("
|
|
326
|
+
out("connector not running \u2014 starting it\u2026");
|
|
275
327
|
await cmdStart();
|
|
276
328
|
if (!await portOpen(PORT)) {
|
|
277
|
-
err("
|
|
329
|
+
err("connector did not come up; aborting.");
|
|
278
330
|
process.exit(1);
|
|
279
331
|
}
|
|
280
332
|
}
|
|
@@ -305,7 +357,7 @@ async function cmdAddBot(argv) {
|
|
|
305
357
|
err(" ours-tg-connector add_bot --name supportbot --bot-token 123456:ABC...");
|
|
306
358
|
process.exit(1);
|
|
307
359
|
}
|
|
308
|
-
await
|
|
360
|
+
await ensureConnector();
|
|
309
361
|
let res;
|
|
310
362
|
try {
|
|
311
363
|
res = await fetch(`${BASE}/bots`, {
|
|
@@ -314,7 +366,7 @@ async function cmdAddBot(argv) {
|
|
|
314
366
|
body: JSON.stringify({ name, botToken: token })
|
|
315
367
|
});
|
|
316
368
|
} catch (e) {
|
|
317
|
-
err(`failed to reach the
|
|
369
|
+
err(`failed to reach the connector control API: ${String(e)}`);
|
|
318
370
|
process.exit(1);
|
|
319
371
|
}
|
|
320
372
|
const body = await res.json();
|
|
@@ -328,7 +380,7 @@ async function cmdAddBot(argv) {
|
|
|
328
380
|
}
|
|
329
381
|
async function cmdListBots() {
|
|
330
382
|
if (!await portOpen(PORT)) {
|
|
331
|
-
out("
|
|
383
|
+
out("connector not running \u2014 no live bots. (Persisted ones load on `start`.)");
|
|
332
384
|
return;
|
|
333
385
|
}
|
|
334
386
|
const res = await fetch(`${BASE}/bots`);
|
|
@@ -351,7 +403,7 @@ async function cmdRemoveBot(name) {
|
|
|
351
403
|
process.exit(1);
|
|
352
404
|
}
|
|
353
405
|
if (!await portOpen(PORT)) {
|
|
354
|
-
err("
|
|
406
|
+
err("connector not running \u2014 start it first to remove a bot.");
|
|
355
407
|
process.exit(1);
|
|
356
408
|
}
|
|
357
409
|
const res = await fetch(`${BASE}/bots/${encodeURIComponent(name)}`, { method: "DELETE" });
|
|
@@ -389,7 +441,7 @@ async function cmdAddConnection(argv) {
|
|
|
389
441
|
err('add_new_connection --payload-mode must be "plain" or "envelope"');
|
|
390
442
|
process.exit(1);
|
|
391
443
|
}
|
|
392
|
-
await
|
|
444
|
+
await ensureConnector();
|
|
393
445
|
let res;
|
|
394
446
|
try {
|
|
395
447
|
res = await fetch(`${BASE}/connections`, {
|
|
@@ -398,7 +450,7 @@ async function cmdAddConnection(argv) {
|
|
|
398
450
|
body: JSON.stringify({ name, botName, chatId, threadId, label, bio, payloadMode })
|
|
399
451
|
});
|
|
400
452
|
} catch (e) {
|
|
401
|
-
err(`failed to reach the
|
|
453
|
+
err(`failed to reach the connector control API: ${String(e)}`);
|
|
402
454
|
process.exit(1);
|
|
403
455
|
}
|
|
404
456
|
const body = await res.json();
|
|
@@ -427,7 +479,7 @@ async function cmdAddConnection(argv) {
|
|
|
427
479
|
}
|
|
428
480
|
async function cmdListConnections() {
|
|
429
481
|
if (!await portOpen(PORT)) {
|
|
430
|
-
out("
|
|
482
|
+
out("connector not running \u2014 no live connections. (Persisted ones load on `start`.)");
|
|
431
483
|
return;
|
|
432
484
|
}
|
|
433
485
|
const res = await fetch(`${BASE}/connections`);
|
|
@@ -458,70 +510,26 @@ async function cmdListConnections() {
|
|
|
458
510
|
}
|
|
459
511
|
}
|
|
460
512
|
}
|
|
461
|
-
async function cmdCpInvite(name) {
|
|
462
|
-
if (!name) {
|
|
463
|
-
err("cp_invite requires a connection name.");
|
|
464
|
-
process.exit(1);
|
|
465
|
-
}
|
|
466
|
-
if (!await portOpen(PORT)) {
|
|
467
|
-
err("daemon not running \u2014 start it first.");
|
|
468
|
-
process.exit(1);
|
|
469
|
-
}
|
|
470
|
-
const res = await fetch(`${BASE}/connections/${encodeURIComponent(name)}/cp-invite`, { method: "POST" });
|
|
471
|
-
const body = await res.json();
|
|
472
|
-
if (!body.ok || !body.invite) {
|
|
473
|
-
err(`cp_invite failed: ${body.error ?? `HTTP ${res.status}`}`);
|
|
474
|
-
process.exit(1);
|
|
475
|
-
}
|
|
476
|
-
out("");
|
|
477
|
-
out(`Add the messenger control plane as a contact of "${name}".`);
|
|
478
|
-
out("Paste this invite into the messenger (add contact / add node):");
|
|
479
|
-
out("");
|
|
480
|
-
out(body.invite);
|
|
481
|
-
out("");
|
|
482
|
-
out(`Once it is a contact, bind it: ours-tg-connector bind_proxy ${name} <contact-name-or-cid>`);
|
|
483
|
-
}
|
|
484
|
-
async function cmdBindProxy(name, contact) {
|
|
485
|
-
if (!name || !contact) {
|
|
486
|
-
err("bind_proxy requires <connection-name> <contact-name-or-cid>.");
|
|
487
|
-
process.exit(1);
|
|
488
|
-
}
|
|
489
|
-
if (!await portOpen(PORT)) {
|
|
490
|
-
err("daemon not running \u2014 start it first.");
|
|
491
|
-
process.exit(1);
|
|
492
|
-
}
|
|
493
|
-
const res = await fetch(`${BASE}/connections/${encodeURIComponent(name)}/bind`, {
|
|
494
|
-
method: "POST",
|
|
495
|
-
headers: { "Content-Type": "application/json" },
|
|
496
|
-
body: JSON.stringify({ contact })
|
|
497
|
-
});
|
|
498
|
-
const body = await res.json();
|
|
499
|
-
if (!body.ok || !body.code) {
|
|
500
|
-
err(`bind_proxy failed: ${body.error ?? `HTTP ${res.status}`}`);
|
|
501
|
-
process.exit(1);
|
|
502
|
-
}
|
|
503
|
-
out("");
|
|
504
|
-
out(`Verification code: ${body.code}`);
|
|
505
|
-
out("");
|
|
506
|
-
out("Enter it in the messenger Control Panel within 5 minutes (3 attempts).");
|
|
507
|
-
out("Do NOT send it over ours \u2014 it must travel out-of-band (this terminal counts).");
|
|
508
|
-
}
|
|
509
513
|
async function cmdRemoveConnection(name) {
|
|
510
514
|
if (!name) {
|
|
511
515
|
err("remove_connection requires a connection name.");
|
|
512
516
|
process.exit(1);
|
|
513
517
|
}
|
|
514
518
|
if (!await portOpen(PORT)) {
|
|
515
|
-
err("
|
|
519
|
+
err("connector not running \u2014 start it first to remove a live connection.");
|
|
516
520
|
process.exit(1);
|
|
517
521
|
}
|
|
518
522
|
const res = await fetch(`${BASE}/connections/${encodeURIComponent(name)}`, { method: "DELETE" });
|
|
519
523
|
const body = await res.json();
|
|
520
524
|
if (!body.ok) {
|
|
521
|
-
|
|
525
|
+
if (body.removed) {
|
|
526
|
+
err(`Removed connection "${body.removed}" locally, but its daemon identity was left behind: ${body.error ?? `HTTP ${res.status}`}`);
|
|
527
|
+
} else {
|
|
528
|
+
err(`remove_connection failed: ${body.error ?? `HTTP ${res.status}`}`);
|
|
529
|
+
}
|
|
522
530
|
process.exit(1);
|
|
523
531
|
}
|
|
524
|
-
out(`Removed connection "${name}" and its
|
|
532
|
+
out(`Removed connection "${name}", its state, and its name-listed daemon identity.`);
|
|
525
533
|
}
|
|
526
534
|
var SYSTEMD_UNIT = "ours-telegram.service";
|
|
527
535
|
var LAUNCHD_LABEL = "solutions.adaptframework.ours-telegram";
|
|
@@ -535,14 +543,7 @@ function run(cmd, args) {
|
|
|
535
543
|
const r = spawnSync(cmd, args, { stdio: "inherit" });
|
|
536
544
|
return r.status === 0;
|
|
537
545
|
}
|
|
538
|
-
|
|
539
|
-
return {
|
|
540
|
-
OURS_TG_BROKER_URL: CONFIG.brokerUrl,
|
|
541
|
-
OURS_TG_CONTROL_PORT: String(CONFIG.controlPort),
|
|
542
|
-
OURS_TG_STATE_DIR: STATE_DIR,
|
|
543
|
-
OURS_TG_POLL_TIMEOUT: String(CONFIG.pollTimeoutSec)
|
|
544
|
-
};
|
|
545
|
-
}
|
|
546
|
+
var serviceEnv = () => serviceEnvironment(CONFIG, STATE_DIR);
|
|
546
547
|
function installSystemd() {
|
|
547
548
|
const unitPath = systemdUnitPath();
|
|
548
549
|
fs2.mkdirSync(dirname2(unitPath), { recursive: true });
|
|
@@ -596,29 +597,13 @@ function installLaunchd() {
|
|
|
596
597
|
const plistPath = launchdPlistPath();
|
|
597
598
|
fs2.mkdirSync(dirname2(plistPath), { recursive: true });
|
|
598
599
|
const env = serviceEnv();
|
|
599
|
-
const
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
<array>
|
|
607
|
-
<string>${process.execPath}</string>
|
|
608
|
-
<string>${SELF}</string>
|
|
609
|
-
<string>serve</string>
|
|
610
|
-
</array>
|
|
611
|
-
<key>EnvironmentVariables</key>
|
|
612
|
-
<dict>
|
|
613
|
-
${envEntries}
|
|
614
|
-
</dict>
|
|
615
|
-
<key>RunAtLoad</key><true/>
|
|
616
|
-
<key>KeepAlive</key><true/>
|
|
617
|
-
<key>StandardOutPath</key><string>${LOG_PATH}</string>
|
|
618
|
-
<key>StandardErrorPath</key><string>${LOG_PATH}</string>
|
|
619
|
-
</dict>
|
|
620
|
-
</plist>
|
|
621
|
-
`;
|
|
600
|
+
const plist = launchdPlist({
|
|
601
|
+
label: LAUNCHD_LABEL,
|
|
602
|
+
execPath: process.execPath,
|
|
603
|
+
self: SELF,
|
|
604
|
+
logPath: LOG_PATH,
|
|
605
|
+
env
|
|
606
|
+
});
|
|
622
607
|
fs2.writeFileSync(plistPath, plist);
|
|
623
608
|
out(`wrote ${plistPath}`);
|
|
624
609
|
run("launchctl", ["unload", plistPath]);
|
|
@@ -675,22 +660,19 @@ function usage() {
|
|
|
675
660
|
out(" list_connections list configured routes grouped by bot");
|
|
676
661
|
out(" remove_connection <name> delete a route and its state");
|
|
677
662
|
out("");
|
|
678
|
-
out("
|
|
679
|
-
out("
|
|
680
|
-
out(" bind_proxy <name> <contact> start binding the messenger as control plane (prints a 6-digit code)");
|
|
681
|
-
out("");
|
|
682
|
-
out(" start start the daemon in the background");
|
|
683
|
-
out(" stop stop the running daemon");
|
|
663
|
+
out(" start start the connector in the background");
|
|
664
|
+
out(" stop stop the running connector");
|
|
684
665
|
out(" restart stop then start");
|
|
685
|
-
out(" status show whether the
|
|
686
|
-
out(" serve run the
|
|
666
|
+
out(" status show whether the connector is running");
|
|
667
|
+
out(" serve run the connector in the foreground (used by start; handy for debugging)");
|
|
687
668
|
out("");
|
|
688
669
|
out(" install-service install + start a boot-persistent service (systemd/launchd)");
|
|
689
670
|
out(" uninstall-service stop + remove that service");
|
|
690
671
|
out("");
|
|
691
672
|
out("Config precedence (per field): env var > config.json > default.");
|
|
692
673
|
out(" config.json: OURS_TG_CONFIG, else ~/.ours-telegram/config.json");
|
|
693
|
-
out(" env:
|
|
674
|
+
out(" env: OURS_TG_DAEMON_URL + OURS_TG_DAEMON_STATE_DIR (both, or neither), OURS_TG_CONTROL_PORT (3051),");
|
|
675
|
+
out(" OURS_TG_STATE_DIR, OURS_TG_POLL_TIMEOUT (30)");
|
|
694
676
|
}
|
|
695
677
|
async function main() {
|
|
696
678
|
const cmd = process.argv[2] ?? "help";
|
|
@@ -741,14 +723,6 @@ async function main() {
|
|
|
741
723
|
case "remove":
|
|
742
724
|
await cmdRemoveConnection(process.argv[3]);
|
|
743
725
|
break;
|
|
744
|
-
case "cp_invite":
|
|
745
|
-
case "cp-invite":
|
|
746
|
-
await cmdCpInvite(process.argv[3]);
|
|
747
|
-
break;
|
|
748
|
-
case "bind_proxy":
|
|
749
|
-
case "bind-proxy":
|
|
750
|
-
await cmdBindProxy(process.argv[3], process.argv[4]);
|
|
751
|
-
break;
|
|
752
726
|
case "start":
|
|
753
727
|
await cmdStart();
|
|
754
728
|
break;
|