fix: correct channelId extraction and dormant check in hooks
message-received.ts:
- message_received ctx has channelId/accountId/conversationId (not
sessionKey). Add extraction from ctx.channelId and metadata.to
("channel:ID" format) before the conversation_info fallback.
agent-end.ts:
- When tail-match is interrupted, only call wakeFromDormant() if the
channel is actually dormant. For non-dormant interrupts (e.g. the
moderator bot's own trigger messages firing message_received on
other agents), fall through to normal advanceSpeaker() so the turn
cycle continues correctly instead of re-triggering the same speaker.
- Import isDormant from turn-manager.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -24,13 +24,27 @@ export function registerMessageReceivedHook(deps: Deps): void {
|
||||
const e = event as Record<string, unknown>;
|
||||
const c = ctx as Record<string, unknown>;
|
||||
|
||||
// Extract Discord channel ID from session key or event metadata
|
||||
// Extract Discord channel ID from ctx or event metadata
|
||||
let channelId: string | undefined;
|
||||
if (typeof c.sessionKey === "string") {
|
||||
|
||||
// ctx.channelId may be bare "1234567890" or "channel:1234567890"
|
||||
if (typeof c.channelId === "string") {
|
||||
const bare = c.channelId.match(/^(\d+)$/)?.[1] ?? c.channelId.match(/:(\d+)$/)?.[1];
|
||||
if (bare) channelId = bare;
|
||||
}
|
||||
// fallback: sessionKey (per-session api instances)
|
||||
if (!channelId && typeof c.sessionKey === "string") {
|
||||
channelId = parseDiscordChannelId(c.sessionKey);
|
||||
}
|
||||
// fallback: metadata.to / originatingTo = "channel:1234567890"
|
||||
if (!channelId) {
|
||||
const metadata = e.metadata as Record<string, unknown> | undefined;
|
||||
const to = String(metadata?.to ?? metadata?.originatingTo ?? "");
|
||||
const toMatch = to.match(/:(\d+)$/);
|
||||
if (toMatch) channelId = toMatch[1];
|
||||
}
|
||||
// fallback: conversation_info
|
||||
if (!channelId) {
|
||||
// Try from event metadata (conversation_info channel_id field)
|
||||
const metadata = e.metadata as Record<string, unknown> | undefined;
|
||||
const convInfo = metadata?.conversation_info as Record<string, unknown> | undefined;
|
||||
const raw = String(convInfo?.channel_id ?? metadata?.channelId ?? "");
|
||||
|
||||
Reference in New Issue
Block a user