@@ -125,6 +125,47 @@ describe("Synology Chat user_list loopback", () => {
125125 }
126126 } ) ;
127127
128+ it ( "chunks long text before the Synology payload limit for every text adapter" , async ( ) => {
129+ const receivedPayloads : Array < { text : string ; user_ids ?: number [ ] } > = [ ] ;
130+ const port = await listenLoopback ( ( req , res ) => {
131+ let formBody = "" ;
132+ req . setEncoding ( "utf8" ) ;
133+ req . on ( "data" , ( chunk : string ) => {
134+ formBody += chunk ;
135+ } ) ;
136+ req . on ( "end" , ( ) => {
137+ const payload = JSON . parse ( new URLSearchParams ( formBody ) . get ( "payload" ) ?? "{}" ) as {
138+ text ?: string ;
139+ user_ids ?: number [ ] ;
140+ } ;
141+ receivedPayloads . push ( { text : payload . text ?? "" , user_ids : payload . user_ids } ) ;
142+ const accepted = ( payload . text ?. length ?? 0 ) <= 2_000 ;
143+ res . writeHead ( accepted ? 200 : 413 , { "Content-Type" : "application/json" } ) ;
144+ res . end ( JSON . stringify ( { success : accepted } ) ) ;
145+ } ) ;
146+ } ) ;
147+ const incomingUrl = `http://127.0.0.1:${ port } /webapi/entry.cgi` ;
148+ const cfg = {
149+ channels : {
150+ "synology-chat" : {
151+ enabled : true ,
152+ token : "loopback-token" ,
153+ incomingUrl,
154+ } ,
155+ } ,
156+ } ;
157+ const text = "x" . repeat ( 2_001 ) ;
158+
159+ await synologyChatPlugin . outbound . sendText ( { cfg, text, to : "42" } ) ;
160+ await synologyChatPlugin . message . send ?. text ?.( { cfg, text, to : "42" } ) ;
161+ await sendMessage ( incomingUrl , text , "42" ) ;
162+
163+ expect ( receivedPayloads ) . toHaveLength ( 6 ) ;
164+ expect ( receivedPayloads . map ( ( { text : chunk } ) => chunk ) . join ( "" ) ) . toBe ( text + text + text ) ;
165+ expect ( receivedPayloads . every ( ( { text : chunk } ) => chunk . length <= 2_000 ) ) . toBe ( true ) ;
166+ expect ( receivedPayloads . every ( ( { user_ids } ) => user_ids ?. [ 0 ] === 42 ) ) . toBe ( true ) ;
167+ } ) ;
168+
128169 it ( "rejects unauthenticated webhook sends without fabricating delivery receipts" , async ( ) => {
129170 let rejectedRequests = 0 ;
130171 const port = await listenLoopback ( ( _req , res ) => {
0 commit comments