@@ -4,6 +4,33 @@ function assertFunction(name, value) {
44 }
55}
66
7+ function normalizeBotImageEntries ( { imageEntries, imageUrls } = { } ) {
8+ const normalized = [ ] ;
9+ const seen = new Map ( ) ;
10+ const sourceEntries = Array . isArray ( imageEntries ) && imageEntries . length > 0
11+ ? imageEntries
12+ : Array . isArray ( imageUrls )
13+ ? imageUrls . map ( ( url ) => ( { url } ) )
14+ : [ ] ;
15+ for ( const rawEntry of sourceEntries ) {
16+ if ( rawEntry == null ) continue ;
17+ const entry = typeof rawEntry === "string" ? { url : rawEntry } : rawEntry ;
18+ const url = String ( entry ?. url ?? "" ) . trim ( ) ;
19+ if ( ! url ) continue ;
20+ const aesKey = String ( entry ?. aesKey ?? "" ) . trim ( ) ;
21+ const existingIndex = seen . get ( url ) ;
22+ if ( existingIndex == null ) {
23+ seen . set ( url , normalized . length ) ;
24+ normalized . push ( { url, aesKey } ) ;
25+ continue ;
26+ }
27+ if ( ! normalized [ existingIndex ] . aesKey && aesKey ) {
28+ normalized [ existingIndex ] = { url, aesKey } ;
29+ }
30+ }
31+ return normalized ;
32+ }
33+
734const UNSUPPORTED_BOT_GROUP_TRIGGER_WARNED = new Set ( ) ;
835
936function warnUnsupportedBotGroupTriggerOnce ( triggerMode , logger ) {
@@ -91,9 +118,11 @@ export function createWecomBotInboundFlowState({
91118 accountId = "default" ,
92119 fromUser,
93120 content,
121+ imageEntries,
94122 imageUrls,
95123 fileUrl,
96124 fileName,
125+ fileAesKey,
97126 voiceUrl,
98127 voiceMediaId,
99128 voiceContentType,
@@ -109,6 +138,7 @@ export function createWecomBotInboundFlowState({
109138 const normalizedAccountId = String ( accountId ?? "default" ) . trim ( ) . toLowerCase ( ) || "default" ;
110139 const normalizedFromUser = String ( fromUser ?? "" ) . trim ( ) . toLowerCase ( ) ;
111140 const baseSessionId = buildWecomBotSessionId ( fromUser , normalizedAccountId ) ;
141+ const normalizedImageEntries = normalizeBotImageEntries ( { imageEntries, imageUrls } ) ;
112142 const state = {
113143 runtime,
114144 cfg,
@@ -127,8 +157,11 @@ export function createWecomBotInboundFlowState({
127157 tempPathsToCleanup : [ ] ,
128158 botModeConfig : resolveWecomBotConfig ( api , normalizedAccountId ) ,
129159 botProxyUrl : resolveWecomBotProxyConfig ( api , normalizedAccountId ) ,
160+ normalizedImageEntries,
161+ normalizedImageUrls : normalizedImageEntries . map ( ( entry ) => entry . url ) ,
130162 normalizedFileUrl : String ( fileUrl ?? "" ) . trim ( ) ,
131163 normalizedFileName : String ( fileName ?? "" ) . trim ( ) ,
164+ normalizedFileAesKey : String ( fileAesKey ?? "" ) . trim ( ) ,
132165 normalizedVoiceUrl : String ( voiceUrl ?? "" ) . trim ( ) ,
133166 normalizedVoiceMediaId : String ( voiceMediaId ?? "" ) . trim ( ) ,
134167 normalizedVoiceContentType : String ( voiceContentType ?? "" ) . trim ( ) ,
@@ -139,13 +172,6 @@ export function createWecomBotInboundFlowState({
139172 content : String ( quote . content ?? "" ) . trim ( ) ,
140173 }
141174 : null ,
142- normalizedImageUrls : Array . from (
143- new Set (
144- ( Array . isArray ( imageUrls ) ? imageUrls : [ ] )
145- . map ( ( item ) => String ( item ?? "" ) . trim ( ) )
146- . filter ( Boolean ) ,
147- ) ,
148- ) ,
149175 groupChatPolicy : normalizeWecomBotGroupChatPolicy ( resolveWecomGroupChatPolicy ( api ) , api ?. logger ) ,
150176 dynamicAgentPolicy : resolveWecomDynamicAgentPolicy ( api ) ,
151177 isAdminUser : false ,
0 commit comments