@@ -3,7 +3,11 @@ import fs from "node:fs";
33import os from "node:os" ;
44import path from "node:path" ;
55import { extensionForMime } from "openclaw/plugin-sdk/media-mime" ;
6- import { parseStrictNonNegativeInteger } from "openclaw/plugin-sdk/number-runtime" ;
6+ import {
7+ asFiniteNumberInRange ,
8+ parseStrictFiniteNumber ,
9+ parseStrictNonNegativeInteger ,
10+ } from "openclaw/plugin-sdk/number-runtime" ;
711import { loadOutboundMediaFromUrl } from "openclaw/plugin-sdk/outbound-media" ;
812import {
913 privateFileStoreSync ,
@@ -53,6 +57,8 @@ const GROUP_CONTEXT_CACHE_TTL_MS = 5 * 60_000;
5357const GROUP_CONTEXT_CACHE_MAX_ENTRIES = 500 ;
5458const LISTENER_WATCHDOG_INTERVAL_MS = 30_000 ;
5559const LISTENER_WATCHDOG_MAX_GAP_MS = 35_000 ;
60+ const ZALO_TIMESTAMP_MS_THRESHOLD = 1_000_000_000_000 ;
61+ const MAX_SAFE_ZALO_TIMESTAMP_SECONDS = Number . MAX_SAFE_INTEGER / 1000 ;
5662
5763const apiByProfile = new Map < string , API > ( ) ;
5864const apiInitByProfile = new Map < string , Promise < API > > ( ) ;
@@ -261,17 +267,27 @@ function normalizeMessageContent(content: unknown): string {
261267}
262268
263269function resolveInboundTimestamp ( rawTs : unknown ) : number {
264- if ( typeof rawTs === "number" && Number . isFinite ( rawTs ) ) {
265- return rawTs > 1_000_000_000_000 ? rawTs : rawTs * 1000 ;
270+ const parsed =
271+ typeof rawTs === "number"
272+ ? rawTs
273+ : typeof rawTs === "string"
274+ ? parseStrictFiniteNumber ( rawTs )
275+ : undefined ;
276+ const timestamp = asFiniteNumberInRange ( parsed , {
277+ min : 0 ,
278+ minExclusive : true ,
279+ max : Number . MAX_SAFE_INTEGER ,
280+ } ) ;
281+ if ( timestamp === undefined ) {
282+ return Date . now ( ) ;
266283 }
267- const parsed = Number . parseInt (
268- typeof rawTs === "string" ? rawTs : typeof rawTs === "number" ? String ( rawTs ) : "" ,
269- 10 ,
270- ) ;
271- if ( ! Number . isFinite ( parsed ) || parsed <= 0 ) {
284+ if ( timestamp > ZALO_TIMESTAMP_MS_THRESHOLD ) {
285+ return Math . trunc ( timestamp ) ;
286+ }
287+ if ( timestamp > MAX_SAFE_ZALO_TIMESTAMP_SECONDS ) {
272288 return Date . now ( ) ;
273289 }
274- return parsed > 1_000_000_000_000 ? parsed : parsed * 1000 ;
290+ return Math . trunc ( timestamp * 1000 ) ;
275291}
276292
277293function extractMentionIds ( rawMentions : unknown ) : string [ ] {
0 commit comments