feat: retries for webhook bring-up and send --json docs
This commit is contained in:
@@ -122,10 +122,7 @@ Examples:
|
||||
const provider = await pickProvider(providerPref as Provider | "auto");
|
||||
|
||||
if (provider === "web") {
|
||||
defaultRuntime.log(
|
||||
info("Provider: web (personal WhatsApp Web session)"),
|
||||
);
|
||||
logWebSelfId();
|
||||
logWebSelfId(defaultRuntime, true);
|
||||
try {
|
||||
await monitorWebProvider(Boolean(opts.verbose));
|
||||
return;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { CliDeps } from "../cli/deps.js";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import { waitForever as defaultWaitForever } from "../cli/wait.js";
|
||||
import { retryAsync } from "../infra/retry.js";
|
||||
|
||||
export async function upCommand(
|
||||
opts: { port: string; path: string; verbose?: boolean; yes?: boolean; dryRun?: boolean },
|
||||
@@ -23,17 +24,22 @@ export async function upCommand(
|
||||
return { server: undefined, publicUrl, senderSid: undefined, waiter };
|
||||
}
|
||||
await deps.ensureBinary("tailscale", undefined, runtime);
|
||||
await deps.ensureFunnel(port, undefined, runtime);
|
||||
await retryAsync(() => deps.ensureFunnel(port, undefined, runtime), 3, 500);
|
||||
const host = await deps.getTailnetHostname();
|
||||
const publicUrl = `https://${host}${opts.path}`;
|
||||
runtime.log(`🌐 Public webhook URL (via Funnel): ${publicUrl}`);
|
||||
|
||||
const server = await deps.startWebhook(
|
||||
port,
|
||||
opts.path,
|
||||
undefined,
|
||||
Boolean(opts.verbose),
|
||||
runtime,
|
||||
const server = await retryAsync(
|
||||
() =>
|
||||
deps.startWebhook(
|
||||
port,
|
||||
opts.path,
|
||||
undefined,
|
||||
Boolean(opts.verbose),
|
||||
runtime,
|
||||
),
|
||||
3,
|
||||
300,
|
||||
);
|
||||
|
||||
if (!deps.createClient) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { CliDeps } from "../cli/deps.js";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import { retryAsync } from "../infra/retry.js";
|
||||
|
||||
export async function webhookCommand(
|
||||
opts: {
|
||||
@@ -21,12 +22,17 @@ export async function webhookCommand(
|
||||
runtime.log(`[dry-run] would start webhook on port ${port} path ${opts.path}`);
|
||||
return undefined;
|
||||
}
|
||||
const server = await deps.startWebhook(
|
||||
port,
|
||||
opts.path,
|
||||
opts.reply,
|
||||
Boolean(opts.verbose),
|
||||
runtime,
|
||||
const server = await retryAsync(
|
||||
() =>
|
||||
deps.startWebhook(
|
||||
port,
|
||||
opts.path,
|
||||
opts.reply,
|
||||
Boolean(opts.verbose),
|
||||
runtime,
|
||||
),
|
||||
3,
|
||||
300,
|
||||
);
|
||||
return server;
|
||||
}
|
||||
|
||||
@@ -364,14 +364,20 @@ function readWebSelfId() {
|
||||
}
|
||||
}
|
||||
|
||||
export function logWebSelfId(runtime: RuntimeEnv = defaultRuntime) {
|
||||
export function logWebSelfId(
|
||||
runtime: RuntimeEnv = defaultRuntime,
|
||||
includeProviderPrefix = false,
|
||||
) {
|
||||
// Human-friendly log of the currently linked personal web session.
|
||||
const { e164, jid } = readWebSelfId();
|
||||
const details =
|
||||
e164 || jid
|
||||
? `${e164 ?? "unknown"}${jid ? ` (jid ${jid})` : ""}`
|
||||
: "unknown";
|
||||
runtime.log(info(`Listening on web session: ${details}`));
|
||||
const prefix = includeProviderPrefix
|
||||
? "Provider: web (personal WhatsApp Web session) — "
|
||||
: "";
|
||||
runtime.log(info(`${prefix}Listening on web session: ${details}`));
|
||||
}
|
||||
|
||||
export async function pickProvider(pref: Provider | "auto"): Promise<Provider> {
|
||||
|
||||
Reference in New Issue
Block a user