1+ using BotSharp . Abstraction . Options ;
12using BotSharp . Abstraction . Routing ;
23
34namespace BotSharp . OpenAPI . Controllers ;
@@ -8,12 +9,16 @@ public class ConversationController : ControllerBase
89{
910 private readonly IServiceProvider _services ;
1011 private readonly IUserIdentity _user ;
12+ private readonly JsonSerializerOptions _jsonOptions ;
1113
1214 public ConversationController ( IServiceProvider services ,
13- IUserIdentity user )
15+ IUserIdentity user ,
16+ BotSharpOptions options )
1417 {
1518 _services = services ;
1619 _user = user ;
20+ _jsonOptions = InitJsonOptions ( options ) ;
21+
1722 }
1823
1924 [ HttpPost ( "/conversation/{agentId}" ) ]
@@ -312,10 +317,7 @@ await conv.SendMessage(agentId, inputMsg,
312317
313318 private async Task OnChunkReceived ( HttpResponse response , ChatResponseModel message )
314319 {
315- var json = JsonSerializer . Serialize ( message , new JsonSerializerOptions
316- {
317- PropertyNamingPolicy = JsonNamingPolicy . CamelCase ,
318- } ) ;
320+ var json = JsonSerializer . Serialize ( message , _jsonOptions ) ;
319321
320322 var buffer = Encoding . UTF8 . GetBytes ( $ "data:{ json } \n ") ;
321323 await response . Body . WriteAsync ( buffer , 0 , buffer . Length ) ;
@@ -333,4 +335,24 @@ private async Task OnEventCompleted(HttpResponse response)
333335 buffer = Encoding . UTF8 . GetBytes ( "\n " ) ;
334336 await response . Body . WriteAsync ( buffer , 0 , buffer . Length ) ;
335337 }
338+
339+ private JsonSerializerOptions InitJsonOptions ( BotSharpOptions options )
340+ {
341+ var jsonOption = new JsonSerializerOptions
342+ {
343+ PropertyNameCaseInsensitive = true ,
344+ PropertyNamingPolicy = JsonNamingPolicy . CamelCase ,
345+ AllowTrailingCommas = true
346+ } ;
347+
348+ if ( options ? . JsonSerializerOptions != null )
349+ {
350+ foreach ( var option in options . JsonSerializerOptions . Converters )
351+ {
352+ jsonOption . Converters . Add ( option ) ;
353+ }
354+ }
355+
356+ return jsonOption ;
357+ }
336358}
0 commit comments