fix: make before_message_write synchronous
- Remove async/await from before_message_write hook - Use fire-and-forget for sendModeratorMessage (void ... .catch()) - OpenClaw's before_message_write is synchronous, not async
This commit is contained in:
@@ -805,7 +805,8 @@ export default {
|
||||
|
||||
// Handle NO_REPLY detection before message write
|
||||
// This is where we detect if agent output is NO_REPLY and handle turn advancement
|
||||
api.on("before_message_write", async (event, ctx) => {
|
||||
// NOTE: This hook is synchronous, do not use async/await
|
||||
api.on("before_message_write", (event, ctx) => {
|
||||
try {
|
||||
const key = ctx.sessionKey;
|
||||
const channelId = ctx.channelId as string | undefined;
|
||||
@@ -859,12 +860,14 @@ export default {
|
||||
return;
|
||||
}
|
||||
|
||||
// Trigger moderator handoff message
|
||||
// Trigger moderator handoff message (fire-and-forget, don't await)
|
||||
if (live.moderatorBotToken) {
|
||||
const nextUserId = resolveDiscordUserId(api, nextSpeaker);
|
||||
if (nextUserId) {
|
||||
const handoffMsg = `轮到(<@${nextUserId}>)了,如果没有想说的请直接回复NO_REPLY`;
|
||||
sendModeratorMessage(live.moderatorBotToken, channelId, handoffMsg, api.logger);
|
||||
void sendModeratorMessage(live.moderatorBotToken, channelId, handoffMsg, api.logger).catch((err) => {
|
||||
api.logger.warn(`whispergate: before_message_write handoff failed: ${String(err)}`);
|
||||
});
|
||||
} else {
|
||||
api.logger.warn(`whispergate: cannot resolve Discord userId for next speaker accountId=${nextSpeaker}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user