gateway: force ws-only clients
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
||||
waitForWaConnection,
|
||||
webAuthExists,
|
||||
} from "../web/session.js";
|
||||
import { callGateway } from "../gateway/call.js";
|
||||
|
||||
type HealthConnect = {
|
||||
ok: boolean;
|
||||
@@ -236,12 +237,13 @@ export async function getHealthSnapshot(
|
||||
}
|
||||
|
||||
export async function healthCommand(
|
||||
opts: { json?: boolean; timeoutMs?: number; probe?: boolean },
|
||||
opts: { json?: boolean; timeoutMs?: number },
|
||||
runtime: RuntimeEnv,
|
||||
) {
|
||||
const probe = opts.probe ?? true;
|
||||
const summary = await getHealthSnapshot(opts.timeoutMs, {
|
||||
probe,
|
||||
// Always query the running gateway; do not open a direct Baileys socket here.
|
||||
const summary = await callGateway<HealthSummary>({
|
||||
method: "health",
|
||||
timeoutMs: opts.timeoutMs,
|
||||
});
|
||||
const fatal =
|
||||
!summary.web.linked ||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { CliDeps } from "../cli/deps.js";
|
||||
import { listPortListeners } from "../cli/ports.js";
|
||||
import { callGateway, randomIdempotencyKey } from "../gateway/call.js";
|
||||
import { startGatewayServer } from "../gateway/server.js";
|
||||
import { success } from "../globals.js";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
|
||||
@@ -13,7 +11,6 @@ export async function sendCommand(
|
||||
json?: boolean;
|
||||
dryRun?: boolean;
|
||||
media?: string;
|
||||
spawnGateway?: boolean;
|
||||
},
|
||||
deps: CliDeps,
|
||||
runtime: RuntimeEnv,
|
||||
@@ -74,21 +71,7 @@ export async function sendCommand(
|
||||
mode: "cli",
|
||||
});
|
||||
|
||||
let result: { messageId: string } | undefined;
|
||||
try {
|
||||
result = await sendViaGateway();
|
||||
} catch (err) {
|
||||
if (!opts.spawnGateway) throw err;
|
||||
// Only spawn when nothing is listening.
|
||||
try {
|
||||
const listeners = listPortListeners(18789);
|
||||
if (listeners.length > 0) throw err;
|
||||
await startGatewayServer(18789);
|
||||
result = await sendViaGateway();
|
||||
} catch {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
const result = await sendViaGateway();
|
||||
|
||||
runtime.log(
|
||||
success(
|
||||
|
||||
@@ -10,13 +10,14 @@ import { info } from "../globals.js";
|
||||
import { buildProviderSummary } from "../infra/provider-summary.js";
|
||||
import { peekSystemEvents } from "../infra/system-events.js";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import { callGateway } from "../gateway/call.js";
|
||||
import { resolveHeartbeatSeconds } from "../web/reconnect.js";
|
||||
import {
|
||||
getWebAuthAgeMs,
|
||||
logWebSelfId,
|
||||
webAuthExists,
|
||||
} from "../web/session.js";
|
||||
import { getHealthSnapshot, type HealthSummary } from "./health.js";
|
||||
import type { HealthSummary } from "./health.js";
|
||||
|
||||
export type SessionStatus = {
|
||||
key: string;
|
||||
@@ -193,7 +194,10 @@ export async function statusCommand(
|
||||
) {
|
||||
const summary = await getStatusSummary();
|
||||
const health: HealthSummary | undefined = opts.deep
|
||||
? await getHealthSnapshot(opts.timeoutMs)
|
||||
? await callGateway<HealthSummary>({
|
||||
method: "health",
|
||||
timeoutMs: opts.timeoutMs,
|
||||
})
|
||||
: undefined;
|
||||
|
||||
if (opts.json) {
|
||||
|
||||
Reference in New Issue
Block a user