build: add local node bin to restart script PATH

This commit is contained in:
Peter Steinberger
2025-12-07 18:49:55 +01:00
parent 558af7a454
commit d463c82c95
31 changed files with 2089 additions and 1851 deletions

View File

@@ -378,13 +378,13 @@ export async function agentCommand(
}
if (!sentViaIpc) {
if (text || media.length === 0) {
await deps.sendMessageWeb(targetTo, text, {
await deps.sendMessageWhatsApp(targetTo, text, {
verbose: false,
mediaUrl: media[0],
});
}
for (const extra of media.slice(1)) {
await deps.sendMessageWeb(targetTo, "", {
await deps.sendMessageWhatsApp(targetTo, "", {
verbose: false,
mediaUrl: extra,
});

View File

@@ -18,7 +18,8 @@ const runtime: RuntimeEnv = {
};
const makeDeps = (overrides: Partial<CliDeps> = {}): CliDeps => ({
sendMessageWeb: vi.fn(),
sendMessageWhatsApp: vi.fn(),
sendMessageTelegram: vi.fn(),
...overrides,
});
@@ -34,7 +35,7 @@ describe("sendCommand", () => {
deps,
runtime,
);
expect(deps.sendMessageWeb).not.toHaveBeenCalled();
expect(deps.sendMessageWhatsApp).not.toHaveBeenCalled();
});
it("uses IPC when available", async () => {
@@ -48,14 +49,16 @@ describe("sendCommand", () => {
deps,
runtime,
);
expect(deps.sendMessageWeb).not.toHaveBeenCalled();
expect(deps.sendMessageWhatsApp).not.toHaveBeenCalled();
expect(runtime.log).toHaveBeenCalledWith(expect.stringContaining("ipc1"));
});
it("falls back to direct send when IPC fails", async () => {
sendViaIpcMock.mockResolvedValueOnce({ success: false, error: "nope" });
const deps = makeDeps({
sendMessageWeb: vi.fn().mockResolvedValue({ messageId: "direct1" }),
sendMessageWhatsApp: vi
.fn()
.mockResolvedValue({ messageId: "direct1" }),
});
await sendCommand(
{
@@ -66,13 +69,34 @@ describe("sendCommand", () => {
deps,
runtime,
);
expect(deps.sendMessageWeb).toHaveBeenCalled();
expect(deps.sendMessageWhatsApp).toHaveBeenCalled();
});
it("routes to telegram provider", async () => {
const deps = makeDeps({
sendMessageTelegram: vi
.fn()
.mockResolvedValue({ messageId: "t1", chatId: "123" }),
});
await sendCommand(
{ to: "123", message: "hi", provider: "telegram" },
deps,
runtime,
);
expect(deps.sendMessageTelegram).toHaveBeenCalledWith(
"123",
"hi",
expect.objectContaining({ token: expect.any(String) }),
);
expect(deps.sendMessageWhatsApp).not.toHaveBeenCalled();
});
it("emits json output", async () => {
sendViaIpcMock.mockResolvedValueOnce(null);
const deps = makeDeps({
sendMessageWeb: vi.fn().mockResolvedValue({ messageId: "direct2" }),
sendMessageWhatsApp: vi
.fn()
.mockResolvedValue({ messageId: "direct2" }),
});
await sendCommand(
{

View File

@@ -7,6 +7,7 @@ export async function sendCommand(
opts: {
to: string;
message: string;
provider?: string;
json?: boolean;
dryRun?: boolean;
media?: string;
@@ -14,13 +15,44 @@ export async function sendCommand(
deps: CliDeps,
runtime: RuntimeEnv,
) {
const provider = (opts.provider ?? "whatsapp").toLowerCase();
if (opts.dryRun) {
runtime.log(
`[dry-run] would send via web -> ${opts.to}: ${opts.message}${opts.media ? ` (media ${opts.media})` : ""}`,
`[dry-run] would send via ${provider} -> ${opts.to}: ${opts.message}${opts.media ? ` (media ${opts.media})` : ""}`,
);
return;
}
if (provider === "telegram") {
const result = await deps.sendMessageTelegram(opts.to, opts.message, {
token: process.env.TELEGRAM_BOT_TOKEN,
mediaUrl: opts.media,
});
runtime.log(
success(
`✅ Sent via telegram. Message ID: ${result.messageId} (chat ${result.chatId})`,
),
);
if (opts.json) {
runtime.log(
JSON.stringify(
{
provider: "telegram",
via: "direct",
to: opts.to,
chatId: result.chatId,
messageId: result.messageId,
mediaUrl: opts.media ?? null,
},
null,
2,
),
);
}
return;
}
// Try to send via IPC to running relay first (avoids Signal session corruption)
const ipcResult = await sendViaIpc(opts.to, opts.message, opts.media);
if (ipcResult) {
@@ -55,7 +87,7 @@ export async function sendCommand(
// Fall back to direct connection (creates new Baileys socket)
const res = await deps
.sendMessageWeb(opts.to, opts.message, {
.sendMessageWhatsApp(opts.to, opts.message, {
verbose: false,
mediaUrl: opts.media,
})