@openclaw-channel/socket-chat 1.0.5 → 1.0.6
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/README.md +9 -0
- package/package.json +1 -1
- package/src/channel.ts +3 -3
- package/src/outbound.test.ts +16 -15
- package/src/outbound.ts +6 -6
package/README.md
CHANGED
package/package.json
CHANGED
package/src/channel.ts
CHANGED
|
@@ -242,7 +242,7 @@ export const socketChatPlugin: ChannelPlugin<ResolvedSocketChatAccount> = {
|
|
|
242
242
|
normalizeTarget: normalizeSocketChatTarget,
|
|
243
243
|
targetResolver: {
|
|
244
244
|
looksLikeId: looksLikeSocketChatTargetId,
|
|
245
|
-
hint: "<contactId|group:groupId|group:groupId
|
|
245
|
+
hint: "<contactId|group:groupId|group:groupId|userId1,userId2>",
|
|
246
246
|
},
|
|
247
247
|
},
|
|
248
248
|
|
|
@@ -383,8 +383,8 @@ export const socketChatPlugin: ChannelPlugin<ResolvedSocketChatAccount> = {
|
|
|
383
383
|
// -------------------------------------------------------------------------
|
|
384
384
|
agentPrompt: {
|
|
385
385
|
messageToolHints: () => [
|
|
386
|
-
"- socket-chat: to send to a group, use target format `group:<groupId
|
|
387
|
-
"To @mention users in a group: `group:<groupId
|
|
386
|
+
"- socket-chat: to send to a group, use target format `group:<groupId>` (groupId may contain @, e.g. `group:17581395450@chatroom`). " +
|
|
387
|
+
"To @mention users in a group: `group:<groupId>|<userId1>,<userId2>`.",
|
|
388
388
|
"- socket-chat: to send an image, provide a public HTTP URL as the media parameter.",
|
|
389
389
|
"- socket-chat: direct messages use the sender's contactId as the target.",
|
|
390
390
|
],
|
package/src/outbound.test.ts
CHANGED
|
@@ -18,20 +18,20 @@ describe("parseSocketChatTarget", () => {
|
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
it("parses a group target without mentions", () => {
|
|
21
|
-
const result = parseSocketChatTarget("group:
|
|
22
|
-
expect(result).toEqual({ isGroup: true, groupId: "
|
|
21
|
+
const result = parseSocketChatTarget("group:17581395450@chatroom");
|
|
22
|
+
expect(result).toEqual({ isGroup: true, groupId: "17581395450@chatroom" });
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
it("parses a group target with single mention", () => {
|
|
26
|
-
const result = parseSocketChatTarget("group:
|
|
27
|
-
expect(result).toEqual({ isGroup: true, groupId: "
|
|
26
|
+
const result = parseSocketChatTarget("group:17581395450@chatroom|wxid_a");
|
|
27
|
+
expect(result).toEqual({ isGroup: true, groupId: "17581395450@chatroom", mentionIds: ["wxid_a"] });
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
it("parses a group target with multiple mentions", () => {
|
|
31
|
-
const result = parseSocketChatTarget("group:
|
|
31
|
+
const result = parseSocketChatTarget("group:17581395450@chatroom|wxid_a,wxid_b,wxid_c");
|
|
32
32
|
expect(result).toEqual({
|
|
33
33
|
isGroup: true,
|
|
34
|
-
groupId: "
|
|
34
|
+
groupId: "17581395450@chatroom",
|
|
35
35
|
mentionIds: ["wxid_a", "wxid_b", "wxid_c"],
|
|
36
36
|
});
|
|
37
37
|
});
|
|
@@ -42,7 +42,7 @@ describe("parseSocketChatTarget", () => {
|
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
it("filters empty mention ids", () => {
|
|
45
|
-
const result = parseSocketChatTarget("group:
|
|
45
|
+
const result = parseSocketChatTarget("group:17581395450@chatroom|wxid_a,,wxid_b");
|
|
46
46
|
expect(result.isGroup).toBe(true);
|
|
47
47
|
if (result.isGroup) {
|
|
48
48
|
expect(result.mentionIds).toEqual(["wxid_a", "wxid_b"]);
|
|
@@ -57,7 +57,8 @@ describe("parseSocketChatTarget", () => {
|
|
|
57
57
|
describe("normalizeSocketChatTarget", () => {
|
|
58
58
|
it("returns the target unchanged for native IDs", () => {
|
|
59
59
|
expect(normalizeSocketChatTarget("wxid_abc")).toBe("wxid_abc");
|
|
60
|
-
expect(normalizeSocketChatTarget("group:
|
|
60
|
+
expect(normalizeSocketChatTarget("group:17581395450@chatroom")).toBe("group:17581395450@chatroom");
|
|
61
|
+
expect(normalizeSocketChatTarget("group:17581395450@chatroom|wxid_a")).toBe("group:17581395450@chatroom|wxid_a");
|
|
61
62
|
});
|
|
62
63
|
|
|
63
64
|
it("strips socket-chat: prefix (case-insensitive)", () => {
|
|
@@ -116,24 +117,24 @@ describe("buildTextPayload", () => {
|
|
|
116
117
|
});
|
|
117
118
|
|
|
118
119
|
it("builds a group text payload", () => {
|
|
119
|
-
const payload = buildTextPayload("group:
|
|
120
|
+
const payload = buildTextPayload("group:17581395450@chatroom", "hi group");
|
|
120
121
|
expect(payload.isGroup).toBe(true);
|
|
121
|
-
expect(payload.groupId).toBe("
|
|
122
|
+
expect(payload.groupId).toBe("17581395450@chatroom");
|
|
122
123
|
expect(payload.messages).toEqual([{ type: 1, content: "hi group" }]);
|
|
123
124
|
});
|
|
124
125
|
|
|
125
126
|
it("extracts mentions from group target string", () => {
|
|
126
|
-
const payload = buildTextPayload("group:
|
|
127
|
+
const payload = buildTextPayload("group:17581395450@chatroom|wxid_a,wxid_b", "hi");
|
|
127
128
|
expect(payload.mentionIds).toEqual(["wxid_a", "wxid_b"]);
|
|
128
129
|
});
|
|
129
130
|
|
|
130
131
|
it("allows explicit override of mentionIds", () => {
|
|
131
|
-
const payload = buildTextPayload("group:
|
|
132
|
+
const payload = buildTextPayload("group:17581395450@chatroom", "hi", { mentionIds: ["wxid_override"] });
|
|
132
133
|
expect(payload.mentionIds).toEqual(["wxid_override"]);
|
|
133
134
|
});
|
|
134
135
|
|
|
135
136
|
it("sets mentionIds to undefined when empty", () => {
|
|
136
|
-
const payload = buildTextPayload("group:
|
|
137
|
+
const payload = buildTextPayload("group:17581395450@chatroom", "hi", { mentionIds: [] });
|
|
137
138
|
expect(payload.mentionIds).toBeUndefined();
|
|
138
139
|
});
|
|
139
140
|
});
|
|
@@ -167,8 +168,8 @@ describe("buildMediaPayload", () => {
|
|
|
167
168
|
});
|
|
168
169
|
|
|
169
170
|
it("builds group media payload", () => {
|
|
170
|
-
const payload = buildMediaPayload("group:
|
|
171
|
+
const payload = buildMediaPayload("group:17581395450@chatroom", "https://img.example.com/photo.jpg");
|
|
171
172
|
expect(payload.isGroup).toBe(true);
|
|
172
|
-
expect(payload.groupId).toBe("
|
|
173
|
+
expect(payload.groupId).toBe("17581395450@chatroom");
|
|
173
174
|
});
|
|
174
175
|
});
|
package/src/outbound.ts
CHANGED
|
@@ -9,19 +9,19 @@ import type { SocketChatMqttConfig, SocketChatOutboundPayload } from "./types.js
|
|
|
9
9
|
*
|
|
10
10
|
* 格式约定:
|
|
11
11
|
* - 私聊:contactId,例如 "wxid_abc123"
|
|
12
|
-
* - 群聊:以 "group:" 前缀,例如 "group:
|
|
13
|
-
* - 群聊带
|
|
12
|
+
* - 群聊:以 "group:" 前缀,例如 "group:17581395450@chatroom"
|
|
13
|
+
* - 群聊带 mention:用 "|" 分隔 groupId 与 mentionIds,例如 "group:17581395450@chatroom|wxid_a,wxid_b"
|
|
14
14
|
*/
|
|
15
15
|
export function parseSocketChatTarget(to: string): Omit<SocketChatOutboundPayload, "messages"> {
|
|
16
16
|
const trimmed = to.trim();
|
|
17
17
|
|
|
18
18
|
if (trimmed.startsWith("group:")) {
|
|
19
19
|
const withoutPrefix = trimmed.slice("group:".length);
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
22
|
-
const groupId = withoutPrefix.slice(0,
|
|
20
|
+
const pipeIdx = withoutPrefix.indexOf("|");
|
|
21
|
+
if (pipeIdx !== -1) {
|
|
22
|
+
const groupId = withoutPrefix.slice(0, pipeIdx);
|
|
23
23
|
const mentionIds = withoutPrefix
|
|
24
|
-
.slice(
|
|
24
|
+
.slice(pipeIdx + 1)
|
|
25
25
|
.split(",")
|
|
26
26
|
.map((s) => s.trim())
|
|
27
27
|
.filter(Boolean);
|