1+ using  BotSharp . Abstraction . Files . Enums ; 
12using  BotSharp . Abstraction . Options ; 
23using  BotSharp . Abstraction . Routing ; 
34using  BotSharp . Abstraction . Users . Enums ; 
@@ -142,7 +143,7 @@ public async Task<IEnumerable<ChatResponseModel>> GetDialogs([FromRoute] string
142143        { 
143144            return  null ; 
144145        } 
145-          
146+ 
146147        var  result  =  ConversationViewModel . FromSession ( conversations . Items . First ( ) ) ; 
147148        var  state  =  _services . GetRequiredService < IConversationStateService > ( ) ; 
148149        result . States  =  state . Load ( conversationId ,  isReadOnly :  true ) ; 
@@ -211,11 +212,12 @@ public async Task<bool> DeleteConversation([FromRoute] string conversationId)
211212    } 
212213
213214    [ HttpDelete ( "/conversation/{conversationId}/message/{messageId}" ) ] 
214-     public  async  Task < bool >  DeleteConversationMessage ( [ FromRoute ]  string  conversationId ,  [ FromRoute ]  string  messageId ) 
215+     public  async  Task < string ? >  DeleteConversationMessage ( [ FromRoute ]  string  conversationId ,  [ FromRoute ]  string  messageId ,   [ FromBody ]   TruncateMessageRequest   request ) 
215216    { 
216217        var  conversationService  =  _services . GetRequiredService < IConversationService > ( ) ; 
217-         var  response  =  await  conversationService . TruncateConversation ( conversationId ,  messageId ) ; 
218-         return  response ; 
218+         var  newMessageId  =  request . isNewMessage  ?  Guid . NewGuid ( ) . ToString ( )  :  null ; 
219+         var  isSuccess  =  await  conversationService . TruncateConversation ( conversationId ,  messageId ,  newMessageId ) ; 
220+         return  isSuccess  ?  newMessageId  :  string . Empty ; 
219221    } 
220222
221223    #region Send message
@@ -227,23 +229,18 @@ public async Task<ChatResponseModel> SendMessage([FromRoute] string agentId,
227229        var  conv  =  _services . GetRequiredService < IConversationService > ( ) ; 
228230        var  inputMsg  =  new  RoleDialogModel ( AgentRole . User ,  input . Text ) 
229231        { 
230-             Files  =  input . Files , 
232+             MessageId  =  ! string . IsNullOrWhiteSpace ( input . InputMessageId )   ?   input . InputMessageId   :   Guid . NewGuid ( ) . ToString ( ) , 
231233            CreatedAt  =  DateTime . UtcNow 
232234        } ; 
233235
234-         if  ( ! string . IsNullOrEmpty ( input . TruncateMessageId ) ) 
235-         { 
236-             await  conv . TruncateConversation ( conversationId ,  input . TruncateMessageId ,  inputMsg . MessageId ) ; 
237-         } 
238- 
239236        var  routing  =  _services . GetRequiredService < IRoutingService > ( ) ; 
240237        routing . Context . SetMessageId ( conversationId ,  inputMsg . MessageId ) ; 
241238
242239        conv . SetConversationId ( conversationId ,  input . States ) ; 
243240        SetStates ( conv ,  input ) ; 
244241
245242        var  response  =  new  ChatResponseModel ( ) ; 
246-          
243+ 
247244        await  conv . SendMessage ( agentId ,  inputMsg , 
248245            replyMessage :  input . Postback , 
249246            async  msg => 
@@ -273,15 +270,10 @@ public async Task SendMessageSse([FromRoute] string agentId,
273270        var  conv  =  _services . GetRequiredService < IConversationService > ( ) ; 
274271        var  inputMsg  =  new  RoleDialogModel ( AgentRole . User ,  input . Text ) 
275272        { 
276-             Files  =  input . Files , 
273+             MessageId  =  ! string . IsNullOrWhiteSpace ( input . InputMessageId )   ?   input . InputMessageId   :   Guid . NewGuid ( ) . ToString ( ) , 
277274            CreatedAt  =  DateTime . UtcNow 
278275        } ; 
279276
280-         if  ( ! string . IsNullOrEmpty ( input . TruncateMessageId ) ) 
281-         { 
282-             await  conv . TruncateConversation ( conversationId ,  input . TruncateMessageId ,  inputMsg . MessageId ) ; 
283-         } 
284- 
285277        var  state  =  _services . GetRequiredService < IConversationStateService > ( ) ; 
286278
287279        var  routing  =  _services . GetRequiredService < IRoutingService > ( ) ; 
@@ -322,7 +314,7 @@ await conv.SendMessage(agentId, inputMsg,
322314                { 
323315                    ConversationId  =  conversationId , 
324316                    MessageId  =  msg . MessageId , 
325-                     Text  =  msg . Indication ,   
317+                     Text  =  msg . Indication , 
326318                    Function  =  "indicating" , 
327319                    Instruction  =  msg . Instruction , 
328320                    States  =  new  Dictionary < string ,  string > ( ) 
@@ -370,8 +362,20 @@ public IActionResult UploadAttachments([FromRoute] string conversationId,
370362        return  BadRequest ( new  {  message  =  "Invalid file."  } ) ; 
371363    } 
372364
365+     [ HttpPost ( "/agent/{agentId}/conversation/{conversationId}/upload" ) ] 
366+     public  async  Task < string >  UploadConversationMessageFiles ( [ FromRoute ]  string  agentId ,  [ FromRoute ]  string  conversationId ,  [ FromBody ]  NewMessageModel  input ) 
367+     { 
368+         var  convService  =  _services . GetRequiredService < IConversationService > ( ) ; 
369+         convService . SetConversationId ( conversationId ,  input . States ) ; 
370+         var  conv  =  await  convService . GetConversationRecordOrCreateNew ( agentId ) ; 
371+         var  fileService  =  _services . GetRequiredService < IBotSharpFileService > ( ) ; 
372+         var  messageId  =  Guid . NewGuid ( ) . ToString ( ) ; 
373+         var  isSaved  =  fileService . SaveMessageFiles ( conv . Id ,  messageId ,  FileSourceType . User ,  input . Files ) ; 
374+         return  isSaved  ?  messageId  :  string . Empty ; 
375+     } 
376+ 
373377    [ HttpGet ( "/conversation/{conversationId}/files/{messageId}/{source}" ) ] 
374-     public  IEnumerable < MessageFileViewModel >  GetMessageFiles ( [ FromRoute ]  string  conversationId ,  [ FromRoute ]  string  messageId ,  [ FromRoute ]  string  source ) 
378+     public  IEnumerable < MessageFileViewModel >  GetConversationMessageFiles ( [ FromRoute ]  string  conversationId ,  [ FromRoute ]  string  messageId ,  [ FromRoute ]  string  source ) 
375379    { 
376380        var  fileService  =  _services . GetRequiredService < IBotSharpFileService > ( ) ; 
377381        var  files  =  fileService . GetMessageFiles ( conversationId ,  new  List < string >  {  messageId  } ,  source ,  imageOnly :  false ) ; 
0 commit comments