Discord: fix PK sender identity context

This commit is contained in:
Shadow
2026-01-31 20:20:17 -06:00
parent 73c405f74a
commit abcca0f9bd
4 changed files with 52 additions and 43 deletions

View File

@@ -9,68 +9,68 @@
"openclaw": "openclaw.mjs"
},
"files": [
"CHANGELOG.md",
"LICENSE",
"openclaw.mjs",
"README-header.png",
"README.md",
"assets/**",
"dist/*.js",
"dist/*.json",
"docs/**",
"extensions/**",
"git-hooks/**",
"patches/**",
"scripts/format-staged.js",
"scripts/postinstall.js",
"scripts/setup-git-hooks.js",
"skills/**",
"dist/acp/**",
"dist/agents/**",
"dist/auto-reply/**",
"dist/browser/**",
"dist/canvas-host/**",
"dist/channels/**",
"dist/cli/**",
"dist/commands/**",
"dist/config/**",
"dist/compat/**",
"dist/config/**",
"dist/control-ui/**",
"dist/cron/**",
"dist/channels/**",
"dist/daemon/**",
"dist/discord/**",
"dist/gateway/**",
"dist/hooks/**",
"dist/imessage/**",
"dist/infra/**",
"dist/macos/**",
"dist/media/**",
"dist/media-understanding/**",
"dist/line/**",
"dist/link-understanding/**",
"dist/process/**",
"dist/plugins/**",
"dist/logging/**",
"dist/macos/**",
"dist/markdown/**",
"dist/media-understanding/**",
"dist/media/**",
"dist/memory/**",
"dist/node-host/**",
"dist/pairing/**",
"dist/plugin-sdk/**",
"dist/plugins/**",
"dist/process/**",
"dist/providers/**",
"dist/routing/**",
"dist/security/**",
"dist/sessions/**",
"dist/providers/**",
"dist/shared/**",
"dist/signal/**",
"dist/slack/**",
"dist/telegram/**",
"dist/line/**",
"dist/tui/**",
"dist/tts/**",
"dist/web/**",
"dist/wizard/**",
"dist/*.js",
"dist/*.json",
"docs/**",
"extensions/**",
"assets/**",
"openclaw.mjs",
"skills/**",
"patches/**",
"README.md",
"README-header.png",
"CHANGELOG.md",
"LICENSE",
"scripts/postinstall.js",
"scripts/format-staged.js",
"scripts/setup-git-hooks.js",
"git-hooks/**",
"dist/terminal/**",
"dist/routing/**",
"dist/shared/**",
"dist/tts/**",
"dist/tui/**",
"dist/utils/**",
"dist/logging/**",
"dist/memory/**",
"dist/markdown/**",
"dist/node-host/**",
"dist/pairing/**",
"dist/whatsapp/**"
"dist/web/**",
"dist/whatsapp/**",
"dist/wizard/**"
],
"type": "module",
"main": "dist/index.js",

View File

@@ -67,7 +67,7 @@ export async function preflightDiscordMessage(
}
const allowBots = params.discordConfig?.allowBots ?? false;
if (author.bot && params.botUserId && author.id === params.botUserId) {
if (params.botUserId && author.id === params.botUserId) {
// Always ignore own messages to prevent self-reply loops
return null;
}

View File

@@ -5,6 +5,8 @@ import type { resolveAgentRoute } from "../../routing/resolve-route.js";
import type { DiscordChannelConfigResolved, DiscordGuildEntryResolved } from "./allow-list.js";
import type { DiscordChannelInfo } from "./message-utils.js";
import type { DiscordSenderIdentity } from "./sender-identity.js";
export type { DiscordSenderIdentity } from "./sender-identity.js";
import type { DiscordThreadChannel } from "./threading.js";
export type LoadedConfig = ReturnType<typeof import("../../config/config.js").loadConfig>;

View File

@@ -31,7 +31,7 @@ import { resolveThreadSessionKeys } from "../../routing/session-key.js";
import { truncateUtf16Safe } from "../../utils.js";
import { reactMessageDiscord, removeReactionDiscord } from "../send.js";
import { normalizeDiscordSlug } from "./allow-list.js";
import { formatDiscordUserTag, resolveTimestampMs } from "./format.js";
import { resolveTimestampMs } from "./format.js";
import {
buildDiscordMediaPayload,
resolveDiscordMessageText,
@@ -138,6 +138,13 @@ export async function processDiscordMessage(ctx: DiscordMessagePreflightContext)
const groupChannel = isGuildMessage && displayChannelSlug ? `#${displayChannelSlug}` : undefined;
const groupSubject = isDirectMessage ? undefined : groupChannel;
const channelDescription = channelInfo?.topic?.trim();
const senderName = sender.isPluralKit
? (sender.name ?? author.username)
: (data.member?.nickname ?? author.globalName ?? author.username);
const senderUsername = sender.isPluralKit
? (sender.tag ?? sender.name ?? author.username)
: author.username;
const senderTag = sender.tag;
const systemPromptParts = [
channelDescription ? `Channel topic: ${channelDescription}` : null,
channelConfig?.systemPrompt?.trim() || null,
@@ -268,10 +275,10 @@ export async function processDiscordMessage(ctx: DiscordMessagePreflightContext)
AccountId: route.accountId,
ChatType: isDirectMessage ? "direct" : "channel",
ConversationLabel: fromLabel,
SenderName: data.member?.nickname ?? author.globalName ?? author.username,
SenderId: author.id,
SenderUsername: author.username,
SenderTag: formatDiscordUserTag(author),
SenderName: senderName,
SenderId: sender.id,
SenderUsername: senderUsername,
SenderTag: senderTag,
GroupSubject: groupSubject,
GroupChannel: groupChannel,
GroupSystemPrompt: isGuildMessage ? groupSystemPrompt : undefined,