protected async override Task PostAsync(IActivity item, string state, CancellationToken token) { // Gets called if evaluation of our score resulted in us handling the incoming message. // We can redirect to another dialog in here or output a message - up to us. var message = item as Activity; if (message == null) { return; } switch (state) { case Keywords.Exit: // React to exit request. Brings us back to the root dialog. await RootDialog.ForwardToRootDialogAsync(_task, clearStack : true); break; case Keywords.Repeat: { var response = ResponseUtterances.GetResponse("Repeat"); var reply = new CommonResponsesDialog(response); var interup = reply.Void <object, IMessageActivity>(); _task.Call(interup, null); await _task.PollAsync(token); trio.Clear(); } break; //case Keywords.Help: // var replyDialog = new CommonResponsesDialog($"Sometimes I also feel **{state}**..."); // // See: https://stackoverflow.com/questions/45282506/what-are-the-void-and-pollasync-methods-of-idialogtask-for/45283394#45283394 // var interruption = replyDialog.Void<object, IMessageActivity>(); // _task.Call(interruption, null); // await _task.PollAsync(token); // break; case Keywords.Swear: { var response = ResponseUtterances.GetResponse("Swear"); var reply = new CommonResponsesDialog(response); var interup = reply.Void <object, IMessageActivity>(); _task.Call(interup, null); await _task.PollAsync(token); } break; } }
public static async Task StartSurvey(ResumptionCookie cookie, CancellationToken token) { var container = WebApiApplication.FindContainer(); // the ResumptionCookie has the "key" necessary to resume the conversation var message = cookie.GetMessage(); ConnectorClient client = new ConnectorClient(new Uri(message.ServiceUrl)); try { var conversation = await client.Conversations.CreateDirectConversationAsync(message.Recipient, message.From); message.Conversation.Id = conversation.Id; } catch (HttpOperationException ex) { var reply = message.CreateReply(); reply.Text = ex.Message; await client.Conversations.SendToConversationAsync(reply); return; } // we instantiate our dependencies based on an IMessageActivity implementation using (var scope = DialogModule.BeginLifetimeScope(container, message)) { // find the bot data interface and load up the conversation dialog state var botData = scope.Resolve <IBotData>(); await botData.LoadAsync(token); // resolve the dialog task IDialogTask task = scope.Resolve <IDialogTask>(); // make a dialog to push on the top of the stack var child = scope.Resolve <SurveyDialog>(); // wrap it with an additional dialog that will restart the wait for // messages from the user once the child dialog has finished var interruption = child.Void <object, IMessageActivity>(); try { // put the interrupting dialog on the stack task.Call(interruption, null); // start running the interrupting dialog await task.PollAsync(token); } finally { // save out the conversation dialog state await botData.FlushAsync(token); } } }
protected override async Task PostAsync(IActivity item, string state, CancellationToken token) { CommonDialog.debugMessages = turnOn ?? false; var commonResponsesDialog = new CommonResponsesDialog(CommonDialog.debugMessages ? "debugging is on" : "debugging is off"); var interruption = commonResponsesDialog.Void <object, IMessageActivity>(); this.task.Call(interruption, null); await task.PollAsync(token); }
/// <summary> /// Load or create the dialog task from the store. /// </summary> /// <typeparam name="R">The type of the root dialog.</typeparam> /// <param name="task">The dialog task.</param> /// <param name="MakeRoot">The factory method for the root dialog.</param> /// <param name="token">An optional cancellation token.</param> /// <returns>A task representing the dialog task load operation.</returns> public static async Task LoadAsync <R>(this IDialogTask task, Func <IDialog <R> > MakeRoot, CancellationToken token = default(CancellationToken)) { if (task.Frames.Count == 0) { var root = MakeRoot(); var loop = root.Loop(); task.Call(loop, null); await task.PollAsync(); } }
protected async override Task PostAsync(Activity item, string state, CancellationToken token) { var message = item as IMessageActivity; if (message != null) { var root = new RootDialog(); await task.PollAsync(CancellationToken.None); } }
protected override async Task PostAsync(IActivity item, string state, CancellationToken token) { var message = item as IMessageActivity; if (message != null) { var settingsDialog = new FaqSettingsDialog(); var interruption = settingsDialog.Void <object, IMessageActivity>(); task.Call(interruption, null); await task.PollAsync(token); } }
/// <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); }
protected override async Task PostAsync(IActivity item, string state, CancellationToken token) { var message = item as IMessageActivity; if (message != null) { //var ticketForm = new FormDialog<TokenModel>(new TokenModel(), TokenModel.BuildForm, FormOptions.PromptInStart); var ticketForm = new RootDialog(); var interruption = ticketForm.Void <object, IMessageActivity>(); task.Call(interruption, null); await task.PollAsync(token); } }
public async Task PostAsync(IActivity item, object state, CancellationToken token) { var message = item as IMessageActivity; if (message != null) { var DebugDialog = dialogFactory.Create <DebugDialog>(); // wrap it with an additional dialog that will restart the wait for // messages from the user once the child dialog has finished var interruption = DebugDialog.Void <object, IMessageActivity>(); // put the interrupting dialog on the stack task.Call(interruption, null); // start running the interrupting dialog await task.PollAsync(token); } }
protected override async Task PostAsync(IActivity item, string state, CancellationToken token) { //this.task.Reset(); var message = item as IMessageActivity; if (message != null) { var root = new RootDialog(); //var ticketForm = new RaiseDialog(); var interruption = root.Void <object, IMessageActivity>(); task.Call(interruption, null); await task.PollAsync(token); this.task.Reset(); } }
protected override async Task PostAsync(IActivity item, string state, CancellationToken token) { var luisResult = luisResults[state]; if (luisResult != null) { string intent = luisResult.TopScoringIntent.Intent; IList <EntityRecommendation> entities = luisResult.Entities; string originalQuery = luisResult.Query; IDialog luisIntentDialog; if (luisIntentFactory.TryFindBestMatchingDialog(luisResult, out luisIntentDialog)) { var interruption = luisIntentDialog.Void <object, IMessageActivity>(); task.Call(interruption, null); await task.PollAsync(token); } return; } }
async Task IPostToBot.PostAsync <T>(T item, CancellationToken token) { try { if (dialogTask.Frames.Count == 0) { var root = this.makeRoot(); var loop = root.Loop(); dialogTask.Call(loop, null); await dialogTask.PollAsync(token); } await dialogTask.PostAsync(item, token); } catch { dialogTask.Reset(); throw; } }
/// <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); }
protected override async Task PostAsync(IActivity activity, string state, CancellationToken cancellationToken) { await _dialogTask.PollAsync(cancellationToken); }
/// <summary> /// Sends the notification(s). /// </summary> /// <param name="activity"></param> /// <param name="state">Should contain the notification as JSON string. /// We store it to the state in PrepareAsync method (see the return value).</param> /// <param name="cancellationToken"></param> /// <returns></returns> protected override async Task PostAsync(IActivity activity, string state, CancellationToken cancellationToken) { await NotificationsManager.SendNotificationAsync(state); await _dialogTask.PollAsync(cancellationToken); }
protected override async Task PostAsync(IActivity item, string state, CancellationToken token) { /*var message = item as IMessageActivity; * var dialog = new RaiseDialog(); * var interruption = dialog.Void(stack); * stack.Call(interruption, null); * return Task.CompletedTask;*/ var message = item as IMessageActivity; IDialog <IMessageActivity> interruption = null; if (message != null) { var incomingMessage = message.Text.ToLowerInvariant(); var messageToSend = String.Empty; if (incomingMessage.Contains("how are you")) { messageToSend = "I am good. How about you?"; var commonResponseDialog = new CommonnResponseDialog(messageToSend); interruption = commonResponseDialog.Void <object, IMessageActivity>(); } else if (incomingMessage.Contains("i am good") || incomingMessage.Contains(" i am fine") || incomingMessage.Contains(" i am fine") || incomingMessage.Contains("nice") || incomingMessage.Contains("good")) { messageToSend = "Nice to know that"; var commonResponseDialog = new CommonnResponseDialog(messageToSend); interruption = commonResponseDialog.Void <object, IMessageActivity>(); } else if (incomingMessage.Contains("help")) { messageToSend = Responses.HelpMessage; var commonResponseDialog = new CommonnResponseDialog(messageToSend); interruption = commonResponseDialog.Void <object, IMessageActivity>(); } else { if (incomingMessage.Contains("thank you")) { messageToSend = "You are welcome"; } if (incomingMessage.Contains("goodbye")) { messageToSend = "See you later"; } if (incomingMessage.Contains("ok") || incomingMessage.Contains("okay") || incomingMessage.Contains("fine") || incomingMessage.Contains("hmm")) { messageToSend = "Want to continue further"; } if (incomingMessage.Contains("no") || incomingMessage.Contains("nope")) { messageToSend = "Ok, bye hope to see you soon"; } if (incomingMessage.Contains("yup") || incomingMessage.Contains("yes") || incomingMessage.Contains("ya")) { messageToSend = "Ok, let's begin then"; } var commonResponseDialog = new CommonnResponseDialog(messageToSend); interruption = commonResponseDialog.Void <object, IMessageActivity>(); } this.task.Call(interruption, null); await task.PollAsync(token); } }