Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/messaging/inbound.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
8 changes: 8 additions & 0 deletions src/messaging/inbound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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",
Expand Down