/// <summary> /// Helper to quickly go to root dialog and optionally reset the dialog stack. /// </summary> /// <param name="dialogTask">context/stack</param> /// <param name="clearStack">TRUE to clear stack, FALSE to leave it unchanged</param> internal async static Task ForwardToRootDialogAsync(IDialogTask dialogTask, bool clearStack) { if (clearStack) { dialogTask.Reset(); } var newActivity = Activity.CreateEventActivity(); newActivity.Value = "INIT_DIALOG"; await dialogTask.Forward(new RootDialog(), null, newActivity, CancellationToken.None); }
/// <summary> /// Post to user. /// </summary> /// <param name="item">Item activity</param> /// <param name="state">State string</param> /// <param name="token">Cancellation token</param> /// <returns>Awaitable task.</returns> protected override async Task PostAsync(IActivity item, string state, CancellationToken token) { var dialog = new AuthDialog(this.authProvider, this.authOptions); _botData.PrivateConversationData.SetValue("AuthenticationStarted", true); #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously var interruption = dialog .Do(async(context, result) => context.PrivateConversationData.RemoveValue("AuthenticationStarted")) .ContinueWith(async(context, result) => Chain.Return(item)); #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously await _dialogTask.Forward(interruption, null, item, token); await _dialogTask.PollAsync(token); }
/// <summary> /// Interrupt the waiting dialog with a new dialog /// </summary> /// <typeparam name="T">The type of result expected from the dialog.</typeparam> /// <typeparam name="R">The type of the item posted to dialog.</typeparam> /// <param name="task">The dialog task.</param> /// <param name="dialog">The new interrupting dialog.</param> /// <param name="item">The item to forward to the new interrupting dialog.</param> /// <param name="token">The cancellation token.</param> /// <returns>A task that represents the interruption operation.</returns> public static async Task InterruptAsync <T, R>(this IDialogTask task, IDialog <T> dialog, R item, CancellationToken token) { await task.Forward(dialog.Void <T, R>(), null, item, token); await task.PollAsync(token); }