mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 13:41:37 +00:00
fix(auto-reply): hide direct-chat metadata without sender-id sentinel (openclaw#24373) thanks @jd316
Co-authored-by: jd316 <138361777+jd316@users.noreply.github.com> Co-authored-by: obviyus <22031114+obviyus@users.noreply.github.com>
This commit is contained in:
@@ -83,6 +83,30 @@ describe("buildInboundUserContextPrefix", () => {
|
||||
expect(text).toBe("");
|
||||
});
|
||||
|
||||
it("hides message identifiers for direct chats", () => {
|
||||
const text = buildInboundUserContextPrefix({
|
||||
ChatType: "direct",
|
||||
MessageSid: "short-id",
|
||||
MessageSidFull: "provider-full-id",
|
||||
} as TemplateContext);
|
||||
|
||||
expect(text).toBe("");
|
||||
});
|
||||
|
||||
it("does not treat group chats as direct based on sender id", () => {
|
||||
const text = buildInboundUserContextPrefix({
|
||||
ChatType: "group",
|
||||
SenderId: "openclaw-control-ui",
|
||||
MessageSid: "123",
|
||||
ConversationLabel: "some-label",
|
||||
} as TemplateContext);
|
||||
|
||||
const conversationInfo = parseConversationInfoPayload(text);
|
||||
expect(conversationInfo["message_id"]).toBe("123");
|
||||
expect(conversationInfo["sender_id"]).toBe("openclaw-control-ui");
|
||||
expect(conversationInfo["conversation_label"]).toBe("some-label");
|
||||
});
|
||||
|
||||
it("keeps conversation label for group chats", () => {
|
||||
const text = buildInboundUserContextPrefix({
|
||||
ChatType: "group",
|
||||
@@ -95,7 +119,7 @@ describe("buildInboundUserContextPrefix", () => {
|
||||
|
||||
it("includes sender identifier in conversation info", () => {
|
||||
const text = buildInboundUserContextPrefix({
|
||||
ChatType: "direct",
|
||||
ChatType: "group",
|
||||
SenderE164: " +15551234567 ",
|
||||
} as TemplateContext);
|
||||
|
||||
@@ -105,7 +129,7 @@ describe("buildInboundUserContextPrefix", () => {
|
||||
|
||||
it("includes message_id in conversation info", () => {
|
||||
const text = buildInboundUserContextPrefix({
|
||||
ChatType: "direct",
|
||||
ChatType: "group",
|
||||
MessageSid: " msg-123 ",
|
||||
} as TemplateContext);
|
||||
|
||||
@@ -127,7 +151,7 @@ describe("buildInboundUserContextPrefix", () => {
|
||||
|
||||
it("omits message_id_full when it matches message_id", () => {
|
||||
const text = buildInboundUserContextPrefix({
|
||||
ChatType: "direct",
|
||||
ChatType: "group",
|
||||
MessageSid: "same-id",
|
||||
MessageSidFull: "same-id",
|
||||
} as TemplateContext);
|
||||
@@ -139,7 +163,7 @@ describe("buildInboundUserContextPrefix", () => {
|
||||
|
||||
it("includes reply_to_id in conversation info", () => {
|
||||
const text = buildInboundUserContextPrefix({
|
||||
ChatType: "direct",
|
||||
ChatType: "group",
|
||||
MessageSid: "msg-200",
|
||||
ReplyToId: "msg-199",
|
||||
} as TemplateContext);
|
||||
@@ -161,7 +185,7 @@ describe("buildInboundUserContextPrefix", () => {
|
||||
|
||||
it("trims sender_id in conversation info", () => {
|
||||
const text = buildInboundUserContextPrefix({
|
||||
ChatType: "direct",
|
||||
ChatType: "group",
|
||||
MessageSid: "msg-457",
|
||||
SenderId: " 289522496 ",
|
||||
} as TemplateContext);
|
||||
@@ -172,7 +196,7 @@ describe("buildInboundUserContextPrefix", () => {
|
||||
|
||||
it("falls back to SenderId when sender phone is missing", () => {
|
||||
const text = buildInboundUserContextPrefix({
|
||||
ChatType: "direct",
|
||||
ChatType: "group",
|
||||
SenderId: " user@example.com ",
|
||||
} as TemplateContext);
|
||||
|
||||
|
||||
@@ -75,12 +75,18 @@ export function buildInboundUserContextPrefix(ctx: TemplateContext): string {
|
||||
const messageId = safeTrim(ctx.MessageSid);
|
||||
const messageIdFull = safeTrim(ctx.MessageSidFull);
|
||||
const conversationInfo = {
|
||||
message_id: messageId,
|
||||
message_id_full: messageIdFull && messageIdFull !== messageId ? messageIdFull : undefined,
|
||||
reply_to_id: safeTrim(ctx.ReplyToId),
|
||||
sender_id: safeTrim(ctx.SenderId),
|
||||
message_id: isDirect ? undefined : messageId,
|
||||
message_id_full: isDirect
|
||||
? undefined
|
||||
: messageIdFull && messageIdFull !== messageId
|
||||
? messageIdFull
|
||||
: undefined,
|
||||
reply_to_id: isDirect ? undefined : safeTrim(ctx.ReplyToId),
|
||||
sender_id: isDirect ? undefined : safeTrim(ctx.SenderId),
|
||||
conversation_label: isDirect ? undefined : safeTrim(ctx.ConversationLabel),
|
||||
sender: safeTrim(ctx.SenderE164) ?? safeTrim(ctx.SenderId) ?? safeTrim(ctx.SenderUsername),
|
||||
sender: isDirect
|
||||
? undefined
|
||||
: (safeTrim(ctx.SenderE164) ?? safeTrim(ctx.SenderId) ?? safeTrim(ctx.SenderUsername)),
|
||||
group_subject: safeTrim(ctx.GroupSubject),
|
||||
group_channel: safeTrim(ctx.GroupChannel),
|
||||
group_space: safeTrim(ctx.GroupSpace),
|
||||
|
||||
Reference in New Issue
Block a user