// Local notification command for paired nodes. import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce"; import { type Command, Option } from "commander"; import { defaultRuntime } from "../../runtime.js"; import { getNodesTheme, runNodesCommand } from "./cli-utils.js"; import { buildNodeInvokeParams, callNodesGatewayCli, nodesCallOpts, parseOptionalNodePositiveInteger, resolveCliNodeId, } from "./rpc.js"; import type { NodesRpcOpts } from "./types.js"; /** Register node notification command. */ export function registerNodesNotifyCommand(nodes: Command) { nodesCallOpts( nodes .command("notify") .description("Send a local notification on a node") .requiredOption("--node ", "Node id, name, or IP") .option("--title ", "Notification title") .option("--body ", "Notification body") .option("--sound ", "Notification sound") .addOption( new Option("--priority ", "Notification priority").choices([ "passive", "active", "timeSensitive", ]), ) .addOption( new Option("--delivery ", "Delivery mode") .choices(["system", "overlay", "auto"]) .default("system"), ) .option("--invoke-timeout ", "Node invoke timeout in ms (default 15000)", "15000") .action(async (opts: NodesRpcOpts) => { await runNodesCommand("notify", async () => { const title = normalizeOptionalString(opts.title) ?? ""; const body = normalizeOptionalString(opts.body) ?? ""; if (!title && !body) { throw new Error("missing --title or --body"); } const invokeTimeout = parseOptionalNodePositiveInteger( opts.invokeTimeout, "--invoke-timeout", ); const nodeId = await resolveCliNodeId(opts, normalizeOptionalString(opts.node) ?? ""); const invokeParams = buildNodeInvokeParams({ nodeId, command: "system.notify", params: { title, body, sound: opts.sound, priority: opts.priority, delivery: opts.delivery, }, idempotencyKey: opts.idempotencyKey, timeoutMs: invokeTimeout, }); const result = await callNodesGatewayCli("node.invoke", opts, invokeParams); if (opts.json) { defaultRuntime.writeJson(result); return; } const { ok } = getNodesTheme(); defaultRuntime.log(ok("notify ok")); }); }), ); }