mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-02 21:01:51 +00:00
fix(tlon): restore DM partner ship extraction for proper routing
- Add extractDmPartnerShip() to extract partner from 'whom' field - Use partner ship for routing (more reliable than essay.author) - Explicitly ignore bot's own outbound DM events - Log mismatch between author and partner for debugging
This commit is contained in:
committed by
Josh Lehman
parent
c7901587e9
commit
85cb714407
@@ -791,6 +791,23 @@ export async function monitorTlonProvider(opts: MonitorTlonOpts = {}): Promise<v
|
||||
return normalizeShip(ship) === effectiveOwnerShip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the DM partner ship from the 'whom' field.
|
||||
* This is the canonical source for DM routing (more reliable than essay.author).
|
||||
* Returns empty string if whom doesn't contain a valid patp-like value.
|
||||
*/
|
||||
function extractDmPartnerShip(whom: unknown): string {
|
||||
const raw =
|
||||
typeof whom === "string"
|
||||
? whom
|
||||
: whom && typeof whom === "object" && "ship" in whom && typeof whom.ship === "string"
|
||||
? whom.ship
|
||||
: "";
|
||||
const normalized = normalizeShip(raw);
|
||||
// Keep DM routing strict: accept only patp-like values.
|
||||
return /^~?[a-z-]+$/i.test(normalized) ? normalized : "";
|
||||
}
|
||||
|
||||
const processMessage = async (params: {
|
||||
messageId: string;
|
||||
senderShip: string;
|
||||
@@ -1281,7 +1298,7 @@ export async function monitorTlonProvider(opts: MonitorTlonOpts = {}): Promise<v
|
||||
return;
|
||||
}
|
||||
|
||||
const _whom = event.whom; // DM partner ship or club ID
|
||||
const whom = event.whom; // DM partner ship or club ID
|
||||
const messageId = event.id;
|
||||
const response = event.response;
|
||||
|
||||
@@ -1295,11 +1312,25 @@ export async function monitorTlonProvider(opts: MonitorTlonOpts = {}): Promise<v
|
||||
return;
|
||||
}
|
||||
|
||||
const senderShip = normalizeShip(essay.author ?? "");
|
||||
const authorShip = normalizeShip(essay.author ?? "");
|
||||
const partnerShip = extractDmPartnerShip(whom);
|
||||
const senderShip = partnerShip || authorShip;
|
||||
|
||||
// Ignore the bot's own outbound DM events.
|
||||
if (authorShip === botShipName) {
|
||||
return;
|
||||
}
|
||||
if (!senderShip || senderShip === botShipName) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Log mismatch between author and partner for debugging
|
||||
if (authorShip && partnerShip && authorShip !== partnerShip) {
|
||||
runtime.log?.(
|
||||
`[tlon] DM ship mismatch (author=${authorShip}, partner=${partnerShip}) - routing to partner`,
|
||||
);
|
||||
}
|
||||
|
||||
// Resolve any cited/quoted messages first
|
||||
const citedContent = await resolveAllCites(essay.content);
|
||||
const rawText = extractMessageText(essay.content);
|
||||
|
||||
Reference in New Issue
Block a user