@aight-cool/aight-utils 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.ts +2 -0
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/src/groups.ts +69 -0
- package/src/push-hook.ts +20 -2
- package/src/push.ts +2 -0
package/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { registerBootstrap } from "./src/bootstrap.js";
|
|
|
13
13
|
import { registerPushHook } from "./src/push-hook.js";
|
|
14
14
|
import { registerHealth } from "./src/health.js";
|
|
15
15
|
import { registerVersion } from "./src/version.js";
|
|
16
|
+
import { registerGroupRpc } from "./src/groups.js";
|
|
16
17
|
|
|
17
18
|
const aightPlugin = {
|
|
18
19
|
id: "aight-utils",
|
|
@@ -66,6 +67,7 @@ const aightPlugin = {
|
|
|
66
67
|
registerPushHook(api);
|
|
67
68
|
registerHealth(api);
|
|
68
69
|
registerVersion(api);
|
|
70
|
+
registerGroupRpc(api);
|
|
69
71
|
|
|
70
72
|
api.logger.info("[aight-utils] Plugin loaded");
|
|
71
73
|
},
|
package/openclaw.plugin.json
CHANGED
package/package.json
CHANGED
package/src/groups.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Group name store — simple mapping of groupId → display name.
|
|
3
|
+
* The app registers group names via RPC so push notifications
|
|
4
|
+
* can show friendly titles instead of raw IDs.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
|
8
|
+
import { readFileSync, writeFileSync, mkdirSync } from "fs";
|
|
9
|
+
import { join } from "path";
|
|
10
|
+
|
|
11
|
+
const FILENAME = "group-names.json";
|
|
12
|
+
|
|
13
|
+
function filePath(api: OpenClawPluginApi): string {
|
|
14
|
+
const dir = (api as any).dataDir ?? join(process.env.HOME ?? "/tmp", ".openclaw", "plugin-data", "aight-utils");
|
|
15
|
+
mkdirSync(dir, { recursive: true });
|
|
16
|
+
return join(dir, FILENAME);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function loadAll(api: OpenClawPluginApi): Record<string, string> {
|
|
20
|
+
try {
|
|
21
|
+
return JSON.parse(readFileSync(filePath(api), "utf-8"));
|
|
22
|
+
} catch {
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function saveAll(api: OpenClawPluginApi, data: Record<string, string>): void {
|
|
28
|
+
writeFileSync(filePath(api), JSON.stringify(data), "utf-8");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function loadGroupName(api: OpenClawPluginApi, groupId: string): string | undefined {
|
|
32
|
+
return loadAll(api)[groupId];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function registerGroupName(api: OpenClawPluginApi, groupId: string, name: string): void {
|
|
36
|
+
const data = loadAll(api);
|
|
37
|
+
data[groupId] = name;
|
|
38
|
+
saveAll(api, data);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function removeGroupName(api: OpenClawPluginApi, groupId: string): void {
|
|
42
|
+
const data = loadAll(api);
|
|
43
|
+
delete data[groupId];
|
|
44
|
+
saveAll(api, data);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function registerGroupRpc(api: OpenClawPluginApi): void {
|
|
48
|
+
api.registerGatewayMethod("aight.groups.setName", ({ params, respond }: any) => {
|
|
49
|
+
const { groupId, name } = (params ?? {}) as { groupId?: string; name?: string };
|
|
50
|
+
if (!groupId || !name) {
|
|
51
|
+
respond(false, { error: "groupId and name are required" });
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
registerGroupName(api, groupId, name);
|
|
55
|
+
respond(true, { ok: true });
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
api.registerGatewayMethod("aight.groups.removeName", ({ params, respond }: any) => {
|
|
59
|
+
const { groupId } = (params ?? {}) as { groupId?: string };
|
|
60
|
+
if (!groupId) {
|
|
61
|
+
respond(false, { error: "groupId is required" });
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
removeGroupName(api, groupId);
|
|
65
|
+
respond(true, { ok: true });
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
api.logger.info("[aight-utils] Group name RPC registered");
|
|
69
|
+
}
|
package/src/push-hook.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
|
6
6
|
import { getPluginConfig } from "./config.js";
|
|
7
7
|
import { sendPush, loadTokens } from "./push.js";
|
|
8
|
+
import { loadGroupName } from "./groups.js";
|
|
8
9
|
|
|
9
10
|
export function registerPushHook(api: OpenClawPluginApi) {
|
|
10
11
|
try {
|
|
@@ -61,14 +62,31 @@ export function registerPushHook(api: OpenClawPluginApi) {
|
|
|
61
62
|
const agent = agents.find((a: any) => a.id === agentId);
|
|
62
63
|
const displayName = agent?.name ?? agent?.identity?.name ?? agentId;
|
|
63
64
|
|
|
65
|
+
// Resolve group chat name for push subtitle (WhatsApp-style layout)
|
|
66
|
+
let pushTitle = displayName;
|
|
67
|
+
let pushSubtitle: string | undefined;
|
|
68
|
+
const sessionKey = ctx.sessionKey ?? "";
|
|
69
|
+
if (sessionKey.includes(":group-chat:")) {
|
|
70
|
+
const groupId = sessionKey.split(":group-chat:")[1];
|
|
71
|
+
if (groupId) {
|
|
72
|
+
const groupName = loadGroupName(api, groupId);
|
|
73
|
+
if (groupName) {
|
|
74
|
+
pushSubtitle = groupName;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const cleanBody = preview.trim().replace(/\n+/g, " ").trim();
|
|
80
|
+
|
|
64
81
|
for (const device of tokens) {
|
|
65
82
|
if (!device.sendKey) continue;
|
|
66
83
|
try {
|
|
67
84
|
await sendPush(
|
|
68
85
|
device.deviceId,
|
|
69
86
|
{
|
|
70
|
-
title:
|
|
71
|
-
|
|
87
|
+
title: pushTitle.trim(),
|
|
88
|
+
subtitle: pushSubtitle,
|
|
89
|
+
body: cleanBody,
|
|
72
90
|
data: { sessionKey: ctx.sessionKey, agentId },
|
|
73
91
|
},
|
|
74
92
|
freshConfig,
|
package/src/push.ts
CHANGED
|
@@ -87,6 +87,7 @@ async function obtainSendKey(relayUrl: string, pushToken: string): Promise<strin
|
|
|
87
87
|
|
|
88
88
|
export interface PushPayload {
|
|
89
89
|
title?: string;
|
|
90
|
+
subtitle?: string;
|
|
90
91
|
body?: string;
|
|
91
92
|
data?: Record<string, unknown>;
|
|
92
93
|
silent?: boolean;
|
|
@@ -118,6 +119,7 @@ export async function sendPush(
|
|
|
118
119
|
|
|
119
120
|
if (mode === "rich" && !payload.silent) {
|
|
120
121
|
pushBody.title = payload.title;
|
|
122
|
+
if (payload.subtitle) pushBody.subtitle = payload.subtitle;
|
|
121
123
|
pushBody.body = payload.body;
|
|
122
124
|
}
|
|
123
125
|
|