@@ -12,6 +12,7 @@ import { isDangerousNameMatchingEnabled } from "openclaw/plugin-sdk/dangerous-na
1212// Zalouser plugin module implements monitor behavior.
1313import { expectDefined } from "openclaw/plugin-sdk/expect-runtime" ;
1414import { createDeferred } from "openclaw/plugin-sdk/extension-shared" ;
15+ import { saveRemoteMedia } from "openclaw/plugin-sdk/media-runtime" ;
1516import {
1617 DEFAULT_GROUP_HISTORY_LIMIT ,
1718 type HistoryEntry ,
@@ -22,7 +23,6 @@ import {
2223 resolveSendableOutboundReplyParts ,
2324 type OutboundReplyPayload ,
2425} from "openclaw/plugin-sdk/reply-payload" ;
25- import { saveRemoteMedia } from "openclaw/plugin-sdk/media-runtime" ;
2626import type { RuntimeEnv } from "openclaw/plugin-sdk/runtime" ;
2727import {
2828 resolveDefaultGroupPolicy ,
@@ -39,6 +39,7 @@ import {
3939 findZalouserGroupEntry ,
4040 isZalouserGroupEntryAllowed ,
4141} from "./group-policy.js" ;
42+ import { resolveInboundImageContentType } from "./inbound-media.js" ;
4243import { createZalouserIngressMonitor , type ZalouserIngressLifecycle } from "./ingress.js" ;
4344import { formatZalouserMessageSidFull , resolveZalouserMessageSid } from "./message-sid.js" ;
4445import { getZalouserRuntime } from "./runtime.js" ;
@@ -982,39 +983,6 @@ export async function monitorZalouserProvider(
982983 return { stop } ;
983984}
984985
985- export const testing = {
986- processMessage : async ( params : {
987- message : ZaloInboundMessage ;
988- account : ResolvedZalouserAccount ;
989- config : OpenClawConfig ;
990- runtime : RuntimeEnv ;
991- historyState ?: {
992- historyLimit ?: number ;
993- groupHistories ?: Map < string , HistoryEntry [ ] > ;
994- } ;
995- statusSink ?: ( patch : { lastInboundAt ?: number ; lastOutboundAt ?: number } ) => void ;
996- } ) => {
997- const historyLimit = Math . max (
998- 0 ,
999- params . historyState ?. historyLimit ??
1000- params . account . config . historyLimit ??
1001- params . config . messages ?. groupChat ?. historyLimit ??
1002- DEFAULT_GROUP_HISTORY_LIMIT ,
1003- ) ;
1004- const groupHistories = params . historyState ?. groupHistories ?? new Map < string , HistoryEntry [ ] > ( ) ;
1005- await processMessage (
1006- params . message ,
1007- params . account ,
1008- params . config ,
1009- getZalouserRuntime ( ) ,
1010- params . runtime ,
1011- { historyLimit, groupHistories } ,
1012- params . statusSink ,
1013- ) ;
1014- } ,
1015- } ;
1016- export { testing as __testing } ;
1017-
1018986/**
1019987 * Download an inbound Zalo photo attachment to a local file via
1020988 * `saveRemoteMedia` so the kernel media pipeline can build the standard
@@ -1065,32 +1033,6 @@ async function resolveInboundMediaFacts(params: {
10651033 }
10661034}
10671035
1068- /**
1069- * Resolve a real `image/*` MIME for an inbound Zalo photo even when the CDN
1070- * returns `application/octet-stream`. Picks from the URL extension first,
1071- * falls back to `image/jpeg` (most common Zalo photo format).
1072- *
1073- * Exported via __testing only; not part of the public plugin surface.
1074- */
1075- export function resolveInboundImageContentType ( detected : string | undefined , url : string ) : string {
1076- if ( detected && detected . startsWith ( "image/" ) ) {
1077- return detected ;
1078- }
1079- const match = url . match ( / \. ( [ a - z ] + ) (?: \? | $ ) / i) ;
1080- const ext = ( match ?. [ 1 ] ?? "jpg" ) . toLowerCase ( ) ;
1081- const extMap : Record < string , string > = {
1082- jpg : "image/jpeg" ,
1083- jpeg : "image/jpeg" ,
1084- png : "image/png" ,
1085- gif : "image/gif" ,
1086- webp : "image/webp" ,
1087- bmp : "image/bmp" ,
1088- } ;
1089- return extMap [ ext ] ?? "image/jpeg" ;
1090- }
1091-
1092- // Re-export internal helper for unit tests only - keep out of public surface
1093- // by attaching to the testing namespace.
10941036type InboundMediaFact = ReturnType < typeof toInboundMediaFacts > [ number ] ;
10951037
10961038/* oxlint-disable max-lines -- TODO: split this grandfathered oversized file. */
0 commit comments