build: add local node bin to restart script PATH
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
import { logWebSelfId, sendMessageWeb } from "../providers/web/index.js";
|
||||
import { logWebSelfId, sendMessageWhatsApp } from "../providers/web/index.js";
|
||||
import { sendMessageTelegram } from "../telegram/send.js";
|
||||
|
||||
export type CliDeps = {
|
||||
sendMessageWeb: typeof sendMessageWeb;
|
||||
sendMessageWhatsApp: typeof sendMessageWhatsApp;
|
||||
sendMessageTelegram: typeof sendMessageTelegram;
|
||||
};
|
||||
|
||||
export function createDefaultDeps(): CliDeps {
|
||||
return {
|
||||
sendMessageWeb,
|
||||
sendMessageWhatsApp,
|
||||
sendMessageTelegram,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ const monitorWebProvider = vi.fn();
|
||||
const logWebSelfId = vi.fn();
|
||||
const waitForever = vi.fn();
|
||||
const spawnRelayTmux = vi.fn().mockResolvedValue("clawdis-relay");
|
||||
const monitorTelegramProvider = vi.fn();
|
||||
|
||||
const runtime = {
|
||||
log: vi.fn(),
|
||||
@@ -23,6 +24,9 @@ vi.mock("../provider-web.js", () => ({
|
||||
loginWeb,
|
||||
monitorWebProvider,
|
||||
}));
|
||||
vi.mock("../telegram/monitor.js", () => ({
|
||||
monitorTelegramProvider,
|
||||
}));
|
||||
vi.mock("./deps.js", () => ({
|
||||
createDefaultDeps: () => ({ waitForever }),
|
||||
logWebSelfId,
|
||||
@@ -86,6 +90,15 @@ describe("cli program", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("runs telegram relay when token set", async () => {
|
||||
const program = buildProgram();
|
||||
const prev = process.env.TELEGRAM_BOT_TOKEN;
|
||||
process.env.TELEGRAM_BOT_TOKEN = "token123";
|
||||
await program.parseAsync(["relay:telegram"], { from: "user" });
|
||||
expect(monitorTelegramProvider).toHaveBeenCalled();
|
||||
process.env.TELEGRAM_BOT_TOKEN = prev;
|
||||
});
|
||||
|
||||
it("runs status command", async () => {
|
||||
const program = buildProgram();
|
||||
await program.parseAsync(["status"], { from: "user" });
|
||||
|
||||
@@ -135,16 +135,20 @@ export function buildProgram() {
|
||||
|
||||
program
|
||||
.command("send")
|
||||
.description("Send a WhatsApp message (web provider)")
|
||||
.description("Send a message (WhatsApp web or Telegram bot)")
|
||||
.requiredOption(
|
||||
"-t, --to <number>",
|
||||
"Recipient number in E.164 (e.g. +15555550123)",
|
||||
"Recipient: E.164 for WhatsApp (e.g. +15555550123) or Telegram chat id/@username",
|
||||
)
|
||||
.requiredOption("-m, --message <text>", "Message body")
|
||||
.option(
|
||||
"--media <path-or-url>",
|
||||
"Attach media (image/audio/video/document). Accepts local paths or URLs.",
|
||||
)
|
||||
.option(
|
||||
"--provider <provider>",
|
||||
"Delivery provider: whatsapp|telegram (default: whatsapp)",
|
||||
)
|
||||
.option("--dry-run", "Print payload and skip sending", false)
|
||||
.option("--json", "Output result as JSON", false)
|
||||
.option("--verbose", "Verbose logging", false)
|
||||
@@ -562,6 +566,42 @@ Examples:
|
||||
}
|
||||
});
|
||||
|
||||
program
|
||||
.command("relay:telegram")
|
||||
.description("Auto-reply to Telegram (Bot API, long-poll)")
|
||||
.option("--verbose", "Verbose logging", false)
|
||||
.addHelpText(
|
||||
"after",
|
||||
`
|
||||
Examples:
|
||||
clawdis relay:telegram # uses TELEGRAM_BOT_TOKEN env
|
||||
TELEGRAM_BOT_TOKEN=xxx clawdis relay:telegram --verbose
|
||||
`,
|
||||
)
|
||||
.action(async (opts) => {
|
||||
setVerbose(Boolean(opts.verbose));
|
||||
const token = process.env.TELEGRAM_BOT_TOKEN;
|
||||
if (!token) {
|
||||
defaultRuntime.error(
|
||||
danger("Set TELEGRAM_BOT_TOKEN to use telegram relay"),
|
||||
);
|
||||
defaultRuntime.exit(1);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await import("../telegram/monitor.js").then((m) =>
|
||||
m.monitorTelegramProvider({
|
||||
verbose: Boolean(opts.verbose),
|
||||
token,
|
||||
runtime: defaultRuntime,
|
||||
}),
|
||||
);
|
||||
} catch (err) {
|
||||
defaultRuntime.error(danger(`Telegram relay failed: ${String(err)}`));
|
||||
defaultRuntime.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
program
|
||||
.command("status")
|
||||
.description("Show web session health and recent session recipients")
|
||||
|
||||
Reference in New Issue
Block a user