appback-remoteagent 0.20.0 → 0.20.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.
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
1
2
|
import fs from "node:fs/promises";
|
|
2
3
|
import path from "node:path";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
const execFileAsync = promisify(execFile);
|
|
3
6
|
export async function registerTelegramBot(options) {
|
|
4
7
|
const token = options.token.trim();
|
|
5
8
|
const ownerId = options.ownerId.trim();
|
|
@@ -63,24 +66,35 @@ export async function readConfiguredOwnerId(dataDir) {
|
|
|
63
66
|
}
|
|
64
67
|
export async function fetchTelegramBotIdentity(token) {
|
|
65
68
|
assertBotToken(token);
|
|
66
|
-
let
|
|
69
|
+
let stdout;
|
|
67
70
|
try {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
const result = await execFileAsync("curl", [
|
|
72
|
+
"-4",
|
|
73
|
+
"-sS",
|
|
74
|
+
"--connect-timeout",
|
|
75
|
+
"10",
|
|
76
|
+
"--max-time",
|
|
77
|
+
"20",
|
|
78
|
+
`https://api.telegram.org/bot${token}/getMe`,
|
|
79
|
+
]);
|
|
80
|
+
stdout = result.stdout;
|
|
81
|
+
if (result.stderr?.trim()) {
|
|
82
|
+
console.error(`curl stderr for Telegram getMe: ${result.stderr.trim()}`);
|
|
83
|
+
}
|
|
71
84
|
}
|
|
72
|
-
catch {
|
|
73
|
-
|
|
85
|
+
catch (error) {
|
|
86
|
+
const detail = error instanceof Error ? error.message.replace(token, "[redacted]") : String(error);
|
|
87
|
+
throw new Error(`Telegram getMe request failed over IPv4: ${detail}`);
|
|
74
88
|
}
|
|
75
89
|
let payload;
|
|
76
90
|
try {
|
|
77
|
-
payload =
|
|
91
|
+
payload = JSON.parse(stdout);
|
|
78
92
|
}
|
|
79
93
|
catch {
|
|
80
|
-
throw new Error(
|
|
94
|
+
throw new Error("Telegram getMe returned an invalid response.");
|
|
81
95
|
}
|
|
82
|
-
if (!
|
|
83
|
-
throw new Error(payload.description ||
|
|
96
|
+
if (!payload.ok || !payload.result?.id || !payload.result.username) {
|
|
97
|
+
throw new Error(payload.description || "Telegram rejected the supplied bot token.");
|
|
84
98
|
}
|
|
85
99
|
return {
|
|
86
100
|
id: payload.result.id,
|
package/package.json
CHANGED
package/scripts/selftest-cli.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import assert from "node:assert/strict";
|
|
|
4
4
|
import fs from "node:fs/promises";
|
|
5
5
|
import os from "node:os";
|
|
6
6
|
import path from "node:path";
|
|
7
|
-
import { registerTelegramBot } from "../dist/services/cli-config-service.js";
|
|
7
|
+
import { fetchTelegramBotIdentity, registerTelegramBot } from "../dist/services/cli-config-service.js";
|
|
8
8
|
import { exportSecrets, importSecrets } from "../dist/services/secret-transfer-service.js";
|
|
9
9
|
|
|
10
10
|
const root = await fs.mkdtemp(path.join(os.tmpdir(), "remoteagent-cli-selftest-"));
|
|
@@ -15,6 +15,22 @@ const selectedBundlePath = path.join(root, "selected-transfer.ra-secrets");
|
|
|
15
15
|
const passphrase = "correct-horse-battery-staple";
|
|
16
16
|
|
|
17
17
|
try {
|
|
18
|
+
const binDir = path.join(root, "bin");
|
|
19
|
+
const curlArgsPath = path.join(root, "curl-args.txt");
|
|
20
|
+
await fs.mkdir(binDir, { recursive: true });
|
|
21
|
+
await fs.writeFile(path.join(binDir, "curl"), `#!/usr/bin/env bash
|
|
22
|
+
printf '%s\\n' "$@" > ${JSON.stringify(curlArgsPath)}
|
|
23
|
+
printf '{"ok":true,"result":{"id":100000,"username":"bootstrap_test_bot"}}'
|
|
24
|
+
`, { mode: 0o755 });
|
|
25
|
+
const originalPath = process.env.PATH;
|
|
26
|
+
process.env.PATH = `${binDir}:${originalPath ?? ""}`;
|
|
27
|
+
const fetchedIdentity = await fetchTelegramBotIdentity("100000:abcdefghijklmnopqrstuvwxyz_123456");
|
|
28
|
+
assert.deepEqual(fetchedIdentity, { id: 100000, username: "bootstrap_test_bot" });
|
|
29
|
+
const curlArgs = await fs.readFile(curlArgsPath, "utf8");
|
|
30
|
+
assert.match(curlArgs, /^-4$/m);
|
|
31
|
+
assert.match(curlArgs, /\/getMe$/m);
|
|
32
|
+
process.env.PATH = originalPath;
|
|
33
|
+
|
|
18
34
|
await fs.mkdir(sourceDataDir, { recursive: true });
|
|
19
35
|
await fs.writeFile(path.join(sourceDataDir, ".env"), [
|
|
20
36
|
"TELEGRAM_BOT_TOKEN=your-telegram-bot-token",
|