@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 CHANGED
@@ -30,6 +30,15 @@ openclaw plugins install /path/to/socket-chat
30
30
 
31
31
  ---
32
32
 
33
+ ## 更新
34
+
35
+ ```bash
36
+ # 从 npm 更新
37
+ openclaw plugins update socket-chat
38
+ ```
39
+
40
+ ---
41
+
33
42
  ## 通过 CLI 添加账号
34
43
 
35
44
  apiKey 从微秘书平台[个人中心](https://wechat.aibotk.com/user/info)获取
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw-channel/socket-chat",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "OpenClaw Socket Chat channel plugin — MQTT-based IM bridge",
5
5
  "type": "module",
6
6
  "publishConfig": {
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@userId1,userId2>",
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>@<userId1>,<userId2>`.",
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
  ],
@@ -18,20 +18,20 @@ describe("parseSocketChatTarget", () => {
18
18
  });
19
19
 
20
20
  it("parses a group target without mentions", () => {
21
- const result = parseSocketChatTarget("group:roomid_xxx");
22
- expect(result).toEqual({ isGroup: true, groupId: "roomid_xxx" });
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:roomid_xxx@wxid_a");
27
- expect(result).toEqual({ isGroup: true, groupId: "roomid_xxx", mentionIds: ["wxid_a"] });
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:roomid_xxx@wxid_a,wxid_b,wxid_c");
31
+ const result = parseSocketChatTarget("group:17581395450@chatroom|wxid_a,wxid_b,wxid_c");
32
32
  expect(result).toEqual({
33
33
  isGroup: true,
34
- groupId: "roomid_xxx",
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:roomid@wxid_a,,wxid_b");
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:roomid_xxx")).toBe("group:roomid_xxx");
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:roomid_xxx", "hi group");
120
+ const payload = buildTextPayload("group:17581395450@chatroom", "hi group");
120
121
  expect(payload.isGroup).toBe(true);
121
- expect(payload.groupId).toBe("roomid_xxx");
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:roomid_xxx@wxid_a,wxid_b", "hi");
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:roomid_xxx", "hi", { mentionIds: ["wxid_override"] });
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:roomid_xxx", "hi", { mentionIds: [] });
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:roomid_xxx", "https://img.example.com/photo.jpg");
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("roomid_xxx");
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:roomid_xxx"
13
- * - 群聊带 @:以 "group:roomid_xxx@wxid_a,wxid_b"(@ 后面逗号分隔 mentionIds)
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 atIdx = withoutPrefix.indexOf("@");
21
- if (atIdx !== -1) {
22
- const groupId = withoutPrefix.slice(0, atIdx);
20
+ const pipeIdx = withoutPrefix.indexOf("|");
21
+ if (pipeIdx !== -1) {
22
+ const groupId = withoutPrefix.slice(0, pipeIdx);
23
23
  const mentionIds = withoutPrefix
24
- .slice(atIdx + 1)
24
+ .slice(pipeIdx + 1)
25
25
  .split(",")
26
26
  .map((s) => s.trim())
27
27
  .filter(Boolean);