openclaw-channel-dmwork 0.2.30 → 0.2.32

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/inbound.ts +27 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclaw-channel-dmwork",
3
- "version": "0.2.30",
3
+ "version": "0.2.32",
4
4
  "description": "DMWork channel plugin for OpenClaw via WuKongIM WebSocket",
5
5
  "main": "index.ts",
6
6
  "type": "module",
package/src/inbound.ts CHANGED
@@ -218,9 +218,34 @@ export async function handleInboundMessage(params: {
218
218
  message.channel_id.length > 0 &&
219
219
  message.channel_type === ChannelType.Group;
220
220
 
221
+ // Parse space_id from channel_id (format: s{spaceId}_{peerId})
222
+ // For DM, channel_id is a fake channel: s{spaceId}_{uid1}@s{spaceId}_{uid2}
223
+ // Use LastIndex approach: spaceId is everything between 's' and the last '_' before peerId
224
+ let spaceId = "";
225
+ const effectiveChannelId = isGroup ? message.channel_id! : message.from_uid;
226
+ if (effectiveChannelId.startsWith("s")) {
227
+ const lastUnderscore = effectiveChannelId.lastIndexOf("_");
228
+ if (lastUnderscore > 0) {
229
+ spaceId = effectiveChannelId.substring(1, lastUnderscore);
230
+ }
231
+ }
232
+ // Also try to extract spaceId from the WS channel_id (compound DM format)
233
+ if (!spaceId && message.channel_id && message.channel_id.startsWith("s")) {
234
+ // DM compound: s{spaceId}_{uid1}@s{spaceId}_{uid2}
235
+ const atIdx = message.channel_id.indexOf("@");
236
+ const firstPart = atIdx > 0 ? message.channel_id.substring(0, atIdx) : message.channel_id;
237
+ if (firstPart.startsWith("s")) {
238
+ const lastUnderscore = firstPart.lastIndexOf("_");
239
+ if (lastUnderscore > 0) {
240
+ spaceId = firstPart.substring(1, lastUnderscore);
241
+ }
242
+ }
243
+ }
244
+
245
+ // Session ID: include spaceId for Space isolation (same user in different Spaces = different sessions)
221
246
  const sessionId = isGroup
222
247
  ? message.channel_id!
223
- : message.from_uid;
248
+ : spaceId ? `${spaceId}:${message.from_uid}` : message.from_uid;
224
249
 
225
250
  const resolved = resolveContent(message.payload);
226
251
  const rawBody = resolved.text;
@@ -409,7 +434,7 @@ export async function handleInboundMessage(params: {
409
434
 
410
435
  const fromLabel = isGroup
411
436
  ? `group:${message.channel_id}`
412
- : `user:${message.from_uid}`;
437
+ : spaceId ? `space:${spaceId}:user:${message.from_uid}` : `user:${message.from_uid}`;
413
438
 
414
439
  const storePath = core.channel.session.resolveStorePath(config.session?.store, {
415
440
  agentId: route.agentId,