@@ -64,6 +64,7 @@ const ZALO_TEXT_LIMIT = 2000;
6464const DEFAULT_MEDIA_MAX_MB = 5 ;
6565const WEBHOOK_CLEANUP_TIMEOUT_MS = 5_000 ;
6666const ZALO_TYPING_TIMEOUT_MS = 5_000 ;
67+ const UNIX_MILLISECONDS_THRESHOLD = 1_000_000_000_000 ;
6768
6869type ZaloCoreRuntime = ReturnType < typeof getZaloRuntime > ;
6970type ZaloStatusSink = ( patch : { lastInboundAt ?: number ; lastOutboundAt ?: number } ) => void ;
@@ -93,6 +94,13 @@ type ZaloUpdateProcessingParams = ZaloProcessingContext & {
9394let zaloWebhookModulePromise : Promise < ZaloWebhookModule > | undefined ;
9495const hostedMediaRouteRefs = new Map < string , { count : number ; unregisters : Array < ( ) => void > } > ( ) ;
9596
97+ function resolveZaloTimestampMs ( date : number | undefined ) : number | undefined {
98+ if ( ! date ) {
99+ return undefined ;
100+ }
101+ return date >= UNIX_MILLISECONDS_THRESHOLD ? date : date * 1000 ;
102+ }
103+
96104function loadZaloWebhookModule ( ) : Promise < ZaloWebhookModule > {
97105 zaloWebhookModulePromise ??= import ( "./monitor.webhook.js" ) ;
98106 return zaloWebhookModulePromise ;
@@ -564,18 +572,19 @@ async function processMessageWithPipeline(params: ZaloMessagePipelineParams): Pr
564572 }
565573
566574 const fromLabel = isGroup ? `group:${ chatId } ` : senderName || `user:${ senderId } ` ;
575+ const timestamp = resolveZaloTimestampMs ( date ) ;
567576 const { storePath, body } = buildEnvelope ( {
568577 channel : "Zalo" ,
569578 from : fromLabel ,
570- timestamp : date ? date * 1000 : undefined ,
579+ timestamp,
571580 body : rawBody ,
572581 } ) ;
573582
574583 const ctxPayload = core . channel . inbound . buildContext ( {
575584 channel : "zalo" ,
576585 accountId : route . accountId ,
577586 messageId : message_id ,
578- timestamp : date ? date * 1000 : undefined ,
587+ timestamp,
579588 from : isGroup ? `zalo:group:${ chatId } ` : `zalo:${ senderId } ` ,
580589 sender : {
581590 id : senderId ,
0 commit comments