mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 02:31:22 +00:00
refactor(heartbeat): share reply payload picker
This commit is contained in:
22
src/auto-reply/heartbeat-reply-payload.ts
Normal file
22
src/auto-reply/heartbeat-reply-payload.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import type { ReplyPayload } from "./types.js";
|
||||
|
||||
export function resolveHeartbeatReplyPayload(
|
||||
replyResult: ReplyPayload | ReplyPayload[] | undefined,
|
||||
): ReplyPayload | undefined {
|
||||
if (!replyResult) {
|
||||
return undefined;
|
||||
}
|
||||
if (!Array.isArray(replyResult)) {
|
||||
return replyResult;
|
||||
}
|
||||
for (let idx = replyResult.length - 1; idx >= 0; idx -= 1) {
|
||||
const payload = replyResult[idx];
|
||||
if (!payload) {
|
||||
continue;
|
||||
}
|
||||
if (payload.text || payload.mediaUrl || (payload.mediaUrls && payload.mediaUrls.length > 0)) {
|
||||
return payload;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
Reference in New Issue
Block a user