mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 00:13:28 +00:00
fix(discord): preserve channel session keys via channel_id fallbacks (#17622)
* fix(discord): preserve channel session keys via channel_id fallbacks * docs(changelog): add discord session continuity note * Tests: cover discord channel_id fallback --------- Co-authored-by: Shadow <hi@shadowing.dev>
This commit is contained in:
@@ -18,6 +18,11 @@ export type DiscordChannelInfo = {
|
||||
ownerId?: string;
|
||||
};
|
||||
|
||||
type DiscordMessageWithChannelId = Message & {
|
||||
channel_id?: unknown;
|
||||
rawData?: { channel_id?: unknown };
|
||||
};
|
||||
|
||||
type DiscordSnapshotAuthor = {
|
||||
id?: string | null;
|
||||
username?: string | null;
|
||||
@@ -48,6 +53,29 @@ export function __resetDiscordChannelInfoCacheForTest() {
|
||||
DISCORD_CHANNEL_INFO_CACHE.clear();
|
||||
}
|
||||
|
||||
function normalizeDiscordChannelId(value: unknown): string {
|
||||
if (typeof value === "string") {
|
||||
return value.trim();
|
||||
}
|
||||
if (typeof value === "number" || typeof value === "bigint") {
|
||||
return String(value).trim();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
export function resolveDiscordMessageChannelId(params: {
|
||||
message: Message;
|
||||
eventChannelId?: string | number | null;
|
||||
}): string {
|
||||
const message = params.message as DiscordMessageWithChannelId;
|
||||
return (
|
||||
normalizeDiscordChannelId(message.channelId) ||
|
||||
normalizeDiscordChannelId(message.channel_id) ||
|
||||
normalizeDiscordChannelId(message.rawData?.channel_id) ||
|
||||
normalizeDiscordChannelId(params.eventChannelId)
|
||||
);
|
||||
}
|
||||
|
||||
export async function resolveDiscordChannelInfo(
|
||||
client: Client,
|
||||
channelId: string,
|
||||
|
||||
Reference in New Issue
Block a user