@@ -12,13 +12,13 @@ namespace Botticelli.Framework.Commands.Processors;
1212/// </summary>
1313/// <typeparam name="TInputCommand"></typeparam>
1414public abstract class WaitForClientResponseCommandChainProcessor < TInputCommand > : CommandProcessor < TInputCommand > ,
15- ICommandChainProcessor < TInputCommand >
16- where TInputCommand : class , ICommand
15+ ICommandChainProcessor < TInputCommand >
16+ where TInputCommand : class , ICommand
1717{
1818 protected WaitForClientResponseCommandChainProcessor ( ILogger < CommandChainProcessor < TInputCommand > > logger ,
19- ICommandValidator < TInputCommand > commandValidator ,
20- MetricsProcessor metricsProcessor ,
21- IValidator < Message > messageValidator )
19+ ICommandValidator < TInputCommand > commandValidator ,
20+ MetricsProcessor metricsProcessor ,
21+ IValidator < Message > messageValidator )
2222 : base ( logger , commandValidator , metricsProcessor , messageValidator )
2323 {
2424 }
@@ -32,31 +32,41 @@ public override async Task ProcessAsync(Message message, CancellationToken token
3232 // filters 'not our' chains
3333 if ( message . ChainId != null && ! ChainIds . Contains ( message . ChainId . Value ) )
3434 return ;
35-
35+
36+ message . ChainId ??= Guid . NewGuid ( ) ;
3637 Classify ( ref message ) ;
37- message . ChainId = Guid . NewGuid ( ) ;
3838 ChainIds . Add ( message . ChainId . Value ) ;
3939
4040 if ( message . Type != Message . MessageType . Messaging )
4141 {
42+ // sets input state to true
43+ ChainStateKeeper . SetState ( message . ChatIds . Single ( ) , true ) ;
4244 await base . ProcessAsync ( message , token ) ;
43-
45+
4446 return ;
4547 }
4648
4749 if ( DateTime . UtcNow - message . LastModifiedAt > Timeout )
4850 return ;
4951
52+ var chatId = message . ChatIds . Single ( ) ;
53+
54+ // checks if input state = true
55+ if ( ! ChainStateKeeper . GetState ( chatId ) )
56+ return ;
57+
5058 message . ProcessingArgs ??= new List < string > ( ) ;
51- message . ProcessingArgs . Add ( message . Body ) ;
59+ message . ProcessingArgs . Add ( message . Body ! ) ;
5260
5361 if ( Next != null )
5462 {
5563 Next . ChainIds . Add ( message . ChainId . Value ) ;
5664 await Next . ProcessAsync ( message , token ) ;
5765 }
5866 else
67+ {
5968 Logger . LogInformation ( "No Next command for message {uid}" , message . Uid ) ;
69+ }
6070 }
6171
6272 public HashSet < Guid > ChainIds { get ; } = new ( 1000 ) ;
0 commit comments