mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 08:47:40 +00:00
refactor(web): dedupe heartbeat ok sender
This commit is contained in:
@@ -52,6 +52,28 @@ export async function runWebHeartbeatOnce(opts: {
|
|||||||
const visibility = resolveHeartbeatVisibility({ cfg, channel: "whatsapp" });
|
const visibility = resolveHeartbeatVisibility({ cfg, channel: "whatsapp" });
|
||||||
const heartbeatOkText = HEARTBEAT_TOKEN;
|
const heartbeatOkText = HEARTBEAT_TOKEN;
|
||||||
|
|
||||||
|
const maybeSendHeartbeatOk = async (): Promise<boolean> => {
|
||||||
|
if (!visibility.showOk) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (dryRun) {
|
||||||
|
whatsappHeartbeatLog.info(`[dry-run] heartbeat ok -> ${to}`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const sendResult = await sender(to, heartbeatOkText, { verbose });
|
||||||
|
heartbeatLogger.info(
|
||||||
|
{
|
||||||
|
to,
|
||||||
|
messageId: sendResult.messageId,
|
||||||
|
chars: heartbeatOkText.length,
|
||||||
|
reason: "heartbeat-ok",
|
||||||
|
},
|
||||||
|
"heartbeat ok sent",
|
||||||
|
);
|
||||||
|
whatsappHeartbeatLog.info(`heartbeat ok sent to ${to} (id ${sendResult.messageId})`);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
const sessionCfg = cfg.session;
|
const sessionCfg = cfg.session;
|
||||||
const sessionScope = sessionCfg?.scope ?? "per-sender";
|
const sessionScope = sessionCfg?.scope ?? "per-sender";
|
||||||
const mainKey = normalizeMainKey(sessionCfg?.mainKey);
|
const mainKey = normalizeMainKey(sessionCfg?.mainKey);
|
||||||
@@ -165,25 +187,7 @@ export async function runWebHeartbeatOnce(opts: {
|
|||||||
},
|
},
|
||||||
"heartbeat skipped",
|
"heartbeat skipped",
|
||||||
);
|
);
|
||||||
let okSent = false;
|
const okSent = await maybeSendHeartbeatOk();
|
||||||
if (visibility.showOk) {
|
|
||||||
if (dryRun) {
|
|
||||||
whatsappHeartbeatLog.info(`[dry-run] heartbeat ok -> ${to}`);
|
|
||||||
} else {
|
|
||||||
const sendResult = await sender(to, heartbeatOkText, { verbose });
|
|
||||||
okSent = true;
|
|
||||||
heartbeatLogger.info(
|
|
||||||
{
|
|
||||||
to,
|
|
||||||
messageId: sendResult.messageId,
|
|
||||||
chars: heartbeatOkText.length,
|
|
||||||
reason: "heartbeat-ok",
|
|
||||||
},
|
|
||||||
"heartbeat ok sent",
|
|
||||||
);
|
|
||||||
whatsappHeartbeatLog.info(`heartbeat ok sent to ${to} (id ${sendResult.messageId})`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
emitHeartbeatEvent({
|
emitHeartbeatEvent({
|
||||||
status: "ok-empty",
|
status: "ok-empty",
|
||||||
to,
|
to,
|
||||||
@@ -225,25 +229,7 @@ export async function runWebHeartbeatOnce(opts: {
|
|||||||
{ to, reason: "heartbeat-token", rawLength: replyPayload.text?.length },
|
{ to, reason: "heartbeat-token", rawLength: replyPayload.text?.length },
|
||||||
"heartbeat skipped",
|
"heartbeat skipped",
|
||||||
);
|
);
|
||||||
let okSent = false;
|
const okSent = await maybeSendHeartbeatOk();
|
||||||
if (visibility.showOk) {
|
|
||||||
if (dryRun) {
|
|
||||||
whatsappHeartbeatLog.info(`[dry-run] heartbeat ok -> ${to}`);
|
|
||||||
} else {
|
|
||||||
const sendResult = await sender(to, heartbeatOkText, { verbose });
|
|
||||||
okSent = true;
|
|
||||||
heartbeatLogger.info(
|
|
||||||
{
|
|
||||||
to,
|
|
||||||
messageId: sendResult.messageId,
|
|
||||||
chars: heartbeatOkText.length,
|
|
||||||
reason: "heartbeat-ok",
|
|
||||||
},
|
|
||||||
"heartbeat ok sent",
|
|
||||||
);
|
|
||||||
whatsappHeartbeatLog.info(`heartbeat ok sent to ${to} (id ${sendResult.messageId})`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
emitHeartbeatEvent({
|
emitHeartbeatEvent({
|
||||||
status: "ok-token",
|
status: "ok-token",
|
||||||
to,
|
to,
|
||||||
|
|||||||
Reference in New Issue
Block a user