diff --git a/src/messaging/inbound.test.ts b/src/messaging/inbound.test.ts index 8c507f7..df7d668 100644 --- a/src/messaging/inbound.test.ts +++ b/src/messaging/inbound.test.ts @@ -75,11 +75,21 @@ describe("weixinMessageToMsgContext", () => { expect(ctx.Timestamp).toBe(1700000000000); }); + it("populates SenderId from from_user_id so OpenClaw core can route per-sender peer state", () => { + // Without SenderId, downstream memory plugins (honcho, etc.) collapse all senders + // into a single peer because `buildInboundUserContextPrefix` reads `ctx.SenderId` + // when emitting the inbound `Conversation info` metadata block. Multi-user setups + // depend on this field being populated. + const ctx = weixinMessageToMsgContext(baseMsg, "account1"); + expect(ctx.SenderId).toBe("user123"); + }); + it("handles missing from_user_id", () => { const msg: WeixinMessage = { item_list: [] }; const ctx = weixinMessageToMsgContext(msg, "acc"); expect(ctx.From).toBe(""); expect(ctx.To).toBe(""); + expect(ctx.SenderId).toBe(""); }); it("handles empty item_list", () => { diff --git a/src/messaging/inbound.ts b/src/messaging/inbound.ts index fc25ab8..1632cee 100644 --- a/src/messaging/inbound.ts +++ b/src/messaging/inbound.ts @@ -147,6 +147,13 @@ export type WeixinMsgContext = { Timestamp?: number; Provider: "openclaw-weixin"; ChatType: "direct"; + /** + * The sender's wxid. Read by OpenClaw core's `buildInboundUserContextPrefix` to populate + * the `sender_id` field of the inbound `Conversation info` metadata block, which downstream + * memory plugins (e.g. honcho) use to route per-sender peer state. Without this, multi-user + * scenarios collapse all senders into a single peer. + */ + SenderId?: string; /** Set by monitor after resolveAgentRoute so dispatchReplyFromConfig uses the correct session. */ SessionKey?: string; context_token?: string; @@ -231,6 +238,7 @@ export function weixinMessageToMsgContext( OriginatingChannel: "openclaw-weixin", OriginatingTo: from_user_id, MessageSid: generateMessageSid(), + SenderId: from_user_id, Timestamp: msg.create_time_ms, Provider: "openclaw-weixin", ChatType: "direct",