@@ -120,14 +120,6 @@ public override async Task<DialogTurnResult> ContinueDialogAsync(DialogContext d
120
120
return await PromptUserAsync ( dc , cancellationToken ) . ConfigureAwait ( false ) ;
121
121
}
122
122
123
- //Handle case where we timed out
124
- var activity = dc . Context . Activity ;
125
- if ( ! wasInterrupted && activity . Type != ActivityTypes . Message && activity . Name == ActivityEventNames . ContinueConversation )
126
- {
127
- await SendActivityAsync ( dc , cancellationToken ) . ConfigureAwait ( false ) ;
128
- return await dc . EndDialogAsync ( cancellationToken : cancellationToken ) . ConfigureAwait ( false ) ;
129
- }
130
-
131
123
//Get value of termination string from expression
132
124
string regexPattern = this . TerminationConditionRegexPattern ? . GetValue ( dc . State ) ;
133
125
@@ -198,6 +190,19 @@ protected override async Task<bool> OnPreBubbleEventAsync(DialogContext dc, Dial
198
190
return false ;
199
191
}
200
192
193
+ protected async Task CheckForTimeoutAsync ( DialogContext dc , CancellationToken cancellationToken )
194
+ {
195
+ //Handle case where we timed out
196
+ var interrupted = dc . State . GetValue < bool > ( TurnPath . Interrupted , ( ) => false ) ;
197
+ var activity = dc . Context . Activity ;
198
+ if ( ! interrupted && activity . Type != ActivityTypes . Message && activity . Name == ActivityEventNames . ContinueConversation )
199
+ {
200
+ //Send the default message to the user and end the dialog
201
+ await SendActivityAsync ( dc , cancellationToken ) . ConfigureAwait ( false ) ;
202
+ await dc . EndDialogAsync ( cancellationToken : cancellationToken ) . ConfigureAwait ( false ) ;
203
+ }
204
+ }
205
+
201
206
private async Task < DialogTurnResult > PromptUserAsync ( DialogContext dc , CancellationToken cancellationToken = default ( CancellationToken ) )
202
207
{
203
208
//Do we already have a value stored? This would happen in the interruption case, a case in which we are looping over ourselves, or maybe we had a fatal error and had to restart the dialog tree
@@ -256,15 +261,11 @@ protected override async Task<bool> OnPreBubbleEventAsync(DialogContext dc, Dial
256
261
return new DialogTurnResult ( DialogTurnStatus . Complete ) ;
257
262
}
258
263
259
- private void CreateTimerForConversation ( DialogContext dc , string timerId , CancellationToken cancellationToken )
264
+ private void CreateTimerForConversation ( DialogContext dc , int timeout , string timerId , CancellationToken cancellationToken )
260
265
{
261
266
BotAdapter adapter = dc . Context . Adapter ;
262
- var identity = dc . Context . TurnState . Get < ClaimsIdentity > ( "BotIdentity" ) ;
263
-
264
267
ConversationReference conversationReference = dc . Context . Activity . GetConversationReference ( ) ;
265
- var timeoutExpression = this . TimeOutInMilliseconds ?? throw new InvalidOperationException ( $ "Value for TimeOutInMilliseconds property is not defined.") ;
266
- int timeout = timeoutExpression . GetValue ( dc . State ) ;
267
-
268
+ var identity = dc . Context . TurnState . Get < ClaimsIdentity > ( "BotIdentity" ) ;
268
269
var audience = dc . Context . TurnState . Get < string > ( BotAdapter . OAuthScopeKey ) ;
269
270
270
271
//Question remaining to be answered: Will this task get garbage collected? If so, we need to maintain a handle for it.
@@ -287,10 +288,15 @@ await adapter.ContinueConversationAsync(
287
288
288
289
private async Task InitTimeoutTimerAsync ( DialogContext dc , CancellationToken cancellationToken )
289
290
{
290
- var timerId = Guid . NewGuid ( ) . ToString ( ) ;
291
- CreateTimerForConversation ( dc , timerId , cancellationToken ) ;
292
- await stateMatrix . StartAsync ( timerId ) . ConfigureAwait ( false ) ;
293
- dc . State . SetValue ( "this.TimerId" , timerId ) ;
291
+ var timeout = this . TimeOutInMilliseconds ? . GetValue ( dc . State ) ?? 0 ;
292
+
293
+ if ( timeout > 0 )
294
+ {
295
+ var timerId = Guid . NewGuid ( ) . ToString ( ) ;
296
+ CreateTimerForConversation ( dc , timeout , timerId , cancellationToken ) ;
297
+ await stateMatrix . StartAsync ( timerId ) . ConfigureAwait ( false ) ;
298
+ dc . State . SetValue ( "this.TimerId" , timerId ) ;
299
+ }
294
300
}
295
301
}
296
302
}
0 commit comments