@ours.network/tg-connector 0.3.1 → 0.3.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.
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
|
package/dist/cli.js
CHANGED
|
@@ -365,7 +365,7 @@ async function cmdRemoveBot(name) {
|
|
|
365
365
|
async function cmdAddConnection(argv) {
|
|
366
366
|
const positionals = argv.filter((a) => !a.startsWith("--"));
|
|
367
367
|
const flagged = /* @__PURE__ */ new Set();
|
|
368
|
-
for (const f of ["--name", "--bot", "--chat-id", "--thread-id", "--label", "--bio"]) {
|
|
368
|
+
for (const f of ["--name", "--bot", "--chat-id", "--thread-id", "--label", "--bio", "--payload-mode"]) {
|
|
369
369
|
const i = argv.indexOf(f);
|
|
370
370
|
if (i >= 0 && i + 1 < argv.length) flagged.add(argv[i + 1]);
|
|
371
371
|
}
|
|
@@ -376,6 +376,7 @@ async function cmdAddConnection(argv) {
|
|
|
376
376
|
const threadId = (flagValue(argv, "--thread-id", "--topic") ?? "").trim();
|
|
377
377
|
const label = (flagValue(argv, "--label") ?? "").trim();
|
|
378
378
|
const bio = (flagValue(argv, "--bio") ?? "").trim();
|
|
379
|
+
const payloadMode = (flagValue(argv, "--payload-mode") ?? (argv.includes("--plain") ? "plain" : "envelope")).trim();
|
|
379
380
|
if (!name || !botName || !chatId) {
|
|
380
381
|
err("add_new_connection requires --name, --bot and --chat-id");
|
|
381
382
|
err(" (register the bot first: ours-tg-connector add_bot <name> <token>)");
|
|
@@ -384,13 +385,17 @@ async function cmdAddConnection(argv) {
|
|
|
384
385
|
err(' [--thread-id 42] [--bio "ACME #support \u2014 paying customers"]');
|
|
385
386
|
process.exit(1);
|
|
386
387
|
}
|
|
388
|
+
if (payloadMode !== "plain" && payloadMode !== "envelope") {
|
|
389
|
+
err('add_new_connection --payload-mode must be "plain" or "envelope"');
|
|
390
|
+
process.exit(1);
|
|
391
|
+
}
|
|
387
392
|
await ensureDaemon();
|
|
388
393
|
let res;
|
|
389
394
|
try {
|
|
390
395
|
res = await fetch(`${BASE}/connections`, {
|
|
391
396
|
method: "POST",
|
|
392
397
|
headers: { "Content-Type": "application/json" },
|
|
393
|
-
body: JSON.stringify({ name, botName, chatId, threadId, label, bio })
|
|
398
|
+
body: JSON.stringify({ name, botName, chatId, threadId, label, bio, payloadMode })
|
|
394
399
|
});
|
|
395
400
|
} catch (e) {
|
|
396
401
|
err(`failed to reach the daemon control API: ${String(e)}`);
|
|
@@ -407,6 +412,7 @@ async function cmdAddConnection(argv) {
|
|
|
407
412
|
out(` telegram bot: ${botName}${body.botUsername ? ` (@${body.botUsername})` : ""}`);
|
|
408
413
|
out(` bridged chat id: ${chatId}${threadId ? ` (topic ${threadId})` : ""}`);
|
|
409
414
|
if (bio) out(` identity bio: ${bio}`);
|
|
415
|
+
out(` inbound payload mode: ${payloadMode}`);
|
|
410
416
|
out("");
|
|
411
417
|
out("Paste this invite into your proxy agent (ours `add_contact`):");
|
|
412
418
|
out("");
|
|
@@ -446,6 +452,7 @@ async function cmdListConnections() {
|
|
|
446
452
|
out(` identity: ${c.cid}`);
|
|
447
453
|
out(` chat: ${chat}`);
|
|
448
454
|
if (c.bio) out(` bio: ${c.bio}`);
|
|
455
|
+
out(` payload: ${c.payloadMode}`);
|
|
449
456
|
out(` status: ${peer}`);
|
|
450
457
|
if (c.contacts.length) out(` contacts: ${c.contacts.map((x) => `${x.name} (${x.cid})`).join(", ")}`);
|
|
451
458
|
}
|
|
@@ -660,9 +667,11 @@ function usage() {
|
|
|
660
667
|
out(" routes:");
|
|
661
668
|
out(" add_new_connection create a chat\u2194agent route (one identity) and print an invite");
|
|
662
669
|
out(" --name <n> --bot <bot-name> --chat-id <c> [--thread-id <topic>] [--label <l>] [--bio <text>]");
|
|
670
|
+
out(" [--payload-mode envelope|plain] [--plain]");
|
|
663
671
|
out(" (positional also accepted: add_new_connection <name> <bot-name> <chat-id>)");
|
|
664
672
|
out(" reuse the same --bot with different --chat-id/--thread-id to bridge many");
|
|
665
673
|
out(" chats/topics through one bot; --bio gives the agent that chat's context");
|
|
674
|
+
out(" envelope is the safe default for groups; plain forwards DM text without JSON metadata");
|
|
666
675
|
out(" list_connections list configured routes grouped by bot");
|
|
667
676
|
out(" remove_connection <name> delete a route and its state");
|
|
668
677
|
out("");
|
package/dist/connector.js
CHANGED
|
@@ -25476,6 +25476,14 @@ var CONFIG_SCHEMA = {
|
|
|
25476
25476
|
title: "Telegram routing",
|
|
25477
25477
|
desc: "Control which Telegram chat may talk to this bot, and what everyone else is told.",
|
|
25478
25478
|
fields: [
|
|
25479
|
+
{
|
|
25480
|
+
key: "payloadMode",
|
|
25481
|
+
label: "Inbound payload mode",
|
|
25482
|
+
type: "string",
|
|
25483
|
+
required: true,
|
|
25484
|
+
help: "envelope keeps Telegram sender/chat metadata for groups; plain forwards direct-chat text without a JSON wrapper.",
|
|
25485
|
+
placeholder: "envelope"
|
|
25486
|
+
},
|
|
25479
25487
|
{
|
|
25480
25488
|
key: "allowedChatId",
|
|
25481
25489
|
label: "Allowed chat ID",
|
|
@@ -25524,7 +25532,8 @@ function buildManifest(pkt, cfg, bound) {
|
|
|
25524
25532
|
function configValues(cfg) {
|
|
25525
25533
|
return {
|
|
25526
25534
|
allowedChatId: cfg.chatId,
|
|
25527
|
-
deniedMessage: cfg.deniedMessage || DEFAULT_DENIED
|
|
25535
|
+
deniedMessage: cfg.deniedMessage || DEFAULT_DENIED,
|
|
25536
|
+
payloadMode: cfg.payloadMode === "plain" ? "plain" : "envelope"
|
|
25528
25537
|
};
|
|
25529
25538
|
}
|
|
25530
25539
|
function applyConfig(cfg, values) {
|
|
@@ -25540,6 +25549,10 @@ function applyConfig(cfg, values) {
|
|
|
25540
25549
|
cfg.deniedMessage = values.deniedMessage;
|
|
25541
25550
|
changed = true;
|
|
25542
25551
|
}
|
|
25552
|
+
if ((values.payloadMode === "plain" || values.payloadMode === "envelope") && values.payloadMode !== cfg.payloadMode) {
|
|
25553
|
+
cfg.payloadMode = values.payloadMode;
|
|
25554
|
+
changed = true;
|
|
25555
|
+
}
|
|
25543
25556
|
return changed;
|
|
25544
25557
|
}
|
|
25545
25558
|
async function dispatchControlRequest(pkt, cfg, req, hooks) {
|
|
@@ -25985,6 +25998,19 @@ function buildEnvelope(m, resolved, fileWireId, transcription) {
|
|
|
25985
25998
|
};
|
|
25986
25999
|
return JSON.stringify(envelope);
|
|
25987
26000
|
}
|
|
26001
|
+
function buildPlainPayload(m, resolved, fileWireId, transcription) {
|
|
26002
|
+
const transcribed = transcription?.status === "ok" && typeof transcription.text === "string";
|
|
26003
|
+
const text = transcribed && m.text === "" ? transcription.text : m.text;
|
|
26004
|
+
if (text !== "") return text;
|
|
26005
|
+
if (m.attachment && resolved && !resolved.ok) {
|
|
26006
|
+
const status = resolved.reason === "too_large" ? "omitted" : "unavailable";
|
|
26007
|
+
return `[Telegram ${m.attachment.kind} ${status}: ${resolved.detail}]`;
|
|
26008
|
+
}
|
|
26009
|
+
if (m.attachment && resolved?.ok && !fileWireId) {
|
|
26010
|
+
return `[Telegram ${m.attachment.kind} unavailable: file transfer failed]`;
|
|
26011
|
+
}
|
|
26012
|
+
return void 0;
|
|
26013
|
+
}
|
|
25988
26014
|
|
|
25989
26015
|
// src/stt.ts
|
|
25990
26016
|
function baseMime(mime) {
|
|
@@ -26122,6 +26148,7 @@ function readMeta(dir) {
|
|
|
26122
26148
|
if (typeof cfg.threadId !== "string") cfg.threadId = "";
|
|
26123
26149
|
if (typeof cfg.bio !== "string") cfg.bio = "";
|
|
26124
26150
|
if (typeof cfg.deniedMessage !== "string") cfg.deniedMessage = DEFAULT_DENIED;
|
|
26151
|
+
if (cfg.payloadMode !== "plain" && cfg.payloadMode !== "envelope") cfg.payloadMode = "envelope";
|
|
26125
26152
|
return cfg;
|
|
26126
26153
|
}
|
|
26127
26154
|
function writeMeta(dir, cfg) {
|
|
@@ -26397,7 +26424,8 @@ async function forwardToNode(conn, m) {
|
|
|
26397
26424
|
log(`[${cfg.name}] send_file to ${target} failed:`, String(err));
|
|
26398
26425
|
}
|
|
26399
26426
|
}
|
|
26400
|
-
const body = buildEnvelope(m, sendAudio ? resolved : void 0, fileWireId, transcription);
|
|
26427
|
+
const body = cfg.payloadMode === "plain" ? buildPlainPayload(m, resolved, fileWireId, transcription) : buildEnvelope(m, sendAudio ? resolved : void 0, fileWireId, transcription);
|
|
26428
|
+
if (body === void 0) continue;
|
|
26401
26429
|
try {
|
|
26402
26430
|
const { deferred, queued } = await withScopeAsync(async (lt) => {
|
|
26403
26431
|
const sent = await pkt.mutatingTx("::a2a_messaging::send_message", { contact: target, text: body }, lt);
|
|
@@ -26642,6 +26670,7 @@ async function createConnection(args) {
|
|
|
26642
26670
|
threadId: args.threadId,
|
|
26643
26671
|
label: args.label,
|
|
26644
26672
|
bio: args.bio,
|
|
26673
|
+
payloadMode: args.payloadMode,
|
|
26645
26674
|
deniedMessage: DEFAULT_DENIED,
|
|
26646
26675
|
peerCid: "",
|
|
26647
26676
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
@@ -26804,6 +26833,7 @@ function describeConnection(conn) {
|
|
|
26804
26833
|
threadId: conn.cfg.threadId || null,
|
|
26805
26834
|
label: conn.cfg.label,
|
|
26806
26835
|
bio: conn.cfg.bio || null,
|
|
26836
|
+
payloadMode: conn.cfg.payloadMode,
|
|
26807
26837
|
deniedMessage: conn.cfg.deniedMessage || DEFAULT_DENIED,
|
|
26808
26838
|
peerCid: conn.cfg.peerCid || null,
|
|
26809
26839
|
controlPlaneCid: mon.proxyCid || null,
|
|
@@ -26830,14 +26860,26 @@ function startControlServer() {
|
|
|
26830
26860
|
const threadId = String(body.threadId ?? "").trim();
|
|
26831
26861
|
const label = String(body.label ?? "").trim();
|
|
26832
26862
|
const bio = String(body.bio ?? "").trim();
|
|
26863
|
+
const payloadMode = String(body.payloadMode ?? "envelope").trim();
|
|
26833
26864
|
const bad = validateName(name);
|
|
26834
26865
|
if (bad) return sendJson(res, 400, { ok: false, error: bad });
|
|
26835
26866
|
if (!botName) return sendJson(res, 400, { ok: false, error: "botName is required (register a bot with add_bot first)" });
|
|
26836
26867
|
if (!chatId) return sendJson(res, 400, { ok: false, error: "chatId is required (use 0 for a catch-all route)" });
|
|
26868
|
+
if (payloadMode !== "plain" && payloadMode !== "envelope") {
|
|
26869
|
+
return sendJson(res, 400, { ok: false, error: 'payloadMode must be "plain" or "envelope"' });
|
|
26870
|
+
}
|
|
26837
26871
|
if (!bots.has(botName)) return sendJson(res, 404, { ok: false, error: `no bot named "${botName}" \u2014 register it with add_bot` });
|
|
26838
26872
|
if (connections.has(name)) return sendJson(res, 409, { ok: false, error: `a connection named "${name}" already exists` });
|
|
26839
26873
|
try {
|
|
26840
|
-
const out = await createConnection({
|
|
26874
|
+
const out = await createConnection({
|
|
26875
|
+
name,
|
|
26876
|
+
botName,
|
|
26877
|
+
chatId,
|
|
26878
|
+
threadId,
|
|
26879
|
+
label,
|
|
26880
|
+
bio,
|
|
26881
|
+
payloadMode
|
|
26882
|
+
});
|
|
26841
26883
|
return sendJson(res, 201, { ok: true, ...out });
|
|
26842
26884
|
} catch (err) {
|
|
26843
26885
|
return sendJson(res, 500, { ok: false, error: String(err) });
|
package/dist/mufl_code/8A84AD8E225F186F666D3EAB2AFF777A4B9BB1B9C7CCF45CF364497EF16CF3E5.muflo
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ours.network/tg-connector",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Bridge Telegram bots to ours proxy nodes — one ADAPT wrapper hosting N messenger packets, each connecting one Telegram bot to one ours node. Run `ours-tg-connector add_new_connection`.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "FSL-1.1-Apache-2.0",
|