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; } }
protected override async Task PostAsync(IActivity item, string state, CancellationToken token) { InterruptionDialog helpInterruptionDialog = new InterruptionDialog(TextProvider.Provide(TextCategory.INTERRUPTION_Help)); IDialog <IMessageActivity> helpInterruption = helpInterruptionDialog.Void <object, IMessageActivity>(); task.Call(helpInterruption, null); //await task.PollAsync(token); }
//ez reagál a felhasználónak, amennyiben a score alapján ez a dialógus veszi át az irányítást protected override async Task PostAsync(IActivity item, string state, CancellationToken token) { InterruptionDialog cancelInterruptionDialog = new InterruptionDialog(TextProvider.Provide(TextCategory.INTERRUPTION_Cancel)); IDialog <IMessageActivity> cancelInterruption = cancelInterruptionDialog.Void <object, IMessageActivity>(); task.Call(cancelInterruption, null); task.Reset(); }
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); } } }
/// <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 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); } }
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; } }