openclaw / src /cli /nodes-cli /register.notify.ts
SaylorTwift's picture
SaylorTwift HF Staff
Add files using upload-large-folder tool
f778c12 verified
Raw
History Blame Contribute Delete
2.71 kB
// 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 <idOrNameOrIp>", "Node id, name, or IP")
.option("--title <text>", "Notification title")
.option("--body <text>", "Notification body")
.option("--sound <name>", "Notification sound")
.addOption(
new Option("--priority <passive|active|timeSensitive>", "Notification priority").choices([
"passive",
"active",
"timeSensitive",
]),
)
.addOption(
new Option("--delivery <system|overlay|auto>", "Delivery mode")
.choices(["system", "overlay", "auto"])
.default("system"),
)
.option("--invoke-timeout <ms>", "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"));
});
}),
);
}