private async Task appNameAsync(DialogContext context) { //this will trigger a wait for user's reply //in this case we are waiting for an app name which will be used as keyword to search the AppMsi table var message = context.Context.Activity; var appname = message.Text; var names = await this.getAppsAsync(appname); if (names.Count == 1) { string name = names.First(); context.ActiveDialog.State["AppName"] = name; await context.PostAsync($"Found {name}. What is the name of the machine to install application?"); } else if (names.Count > 1) { string appnames = ""; for (int i = 0; i < names.Count; i++) { appnames += $"<br/> {i + 1}. " + names[i]; } await context.PostAsync($"I found {names.Count()} applications.<br/> {appnames}<br/> Please reply 1 - {names.Count()} to indicate your choice."); //at a conversation scope, store state data in ConversationData var data = await _accessors.ConversationData.GetAsync(context.Context, () => new BotDataBag()); data.SetValue("AppList", names); } else { await context.PostAsync($"Sorry, I did not find any application with the name \"{appname}\"."); } }
public override async Task <DialogTurnResult> ResumeDialogAsync(DialogContext outerDc, DialogReason reason, object result = null, CancellationToken cancellationToken = default(CancellationToken)) { var ticketNumber = new Random().Next(0, 20000); await outerDc.PostAsync($"Thank you for using the Helpdesk Bot. Your ticket number is {ticketNumber}."); return(new DialogTurnResult(DialogTurnStatus.Complete)); }
private async Task <DialogTurnResult> None(DialogContext context, LuisResult result) { string message = $"I'm the Notes bot. I can understand requests to create, delete, and read notes. \n\n Detected intent: " + string.Join(", ", result.Intents.Select(i => i.Intent)); await context.PostAsync(message); return(new DialogTurnResult(DialogTurnStatus.Complete)); }
private async Task OnOptionSelected(DialogContext context, IMessageActivity result) { try { if (result.Text.ToLower().Contains("help") || result.Text.ToLower().Contains("support") || result.Text.ToLower().Contains("problem")) { await context.Forward <int>(new SupportDialog(), this.ResumeAfterSupportDialog, result, CancellationToken.None); return; } var optionSelected = result; switch (optionSelected.Text) { case FlightsOption: context.Call <object>(new FlightsDialog(), this.ResumeAfterOptionDialog); break; case HotelsOption: context.Call <object>(new HotelsDialog(), this.ResumeAfterOptionDialog); break; } } catch (TooManyAttemptsException ex) { await context.PostAsync($"Ooops! Too many attempts :(. But don't worry, I'm handling that exception and you can try again!"); context.Wait(this.MessageReceivedAsync); } }
private async Task ResumeAfterSupportDialog(DialogContext context, IMessageActivity result) { var ticketNumber = result; await context.PostAsync($"Thanks for contacting our support team. Your ticket number is {ticketNumber.Text}."); context.Wait(this.MessageReceivedAsync); }
public override async Task StartAsync(DialogContext context) { await context.PostAsync("Welcome to the Hotels finder!"); var found = FindDialog("HotelsQuery"); await found.BeginDialogAsync(context); }
/// <summary> /// Executed after asking the user for the Title of the Note they wish to delete. /// </summary> /// <param name="context">Current dialog context</param> /// <param name="titleToDelete">The title of the note the user wants to delete</param> /// <returns>A DialogTurnResult</returns> private async Task <DialogTurnResult> After_DeleteTitlePrompt(DialogContext context, string titleToDelete) { Note note; bool foundNote = NoteByTitle.TryGetValue(titleToDelete, out note); if (foundNote) { NoteByTitle.Remove(note.Title); await context.PostAsync($"Note {note.Title} deleted"); } else { await context.PostAsync($"Did not find note named {titleToDelete}."); } return(new DialogTurnResult(DialogTurnStatus.Complete)); }
public virtual async Task MessageReceivedAsync(DialogContext context, IMessageActivity result) { var message = result; var ticketNumber = new Random().Next(0, 20000); await context.PostAsync($"Your message '{message.Text}' was registered. Once we resolve it; we will get back to you."); context.Done(ticketNumber); }
public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext outerDc, object options = null, CancellationToken cancellationToken = default(CancellationToken)) { await outerDc.PostAsync("Ok let's get started. What is the name of the application? "); //set default state values outerDc.ActiveDialog.State["AppName"] = string.Empty; var data = await _accessors.ConversationData.GetAsync(outerDc.Context, () => new BotDataBag()); data.Remove("AppList"); return(new DialogTurnResult(DialogTurnStatus.Waiting)); }
private async Task <DialogTurnResult> FindNote(DialogContext context, LuisResult result) { Note note; if (this.TryFindNote(result, out note)) { await context.PostAsync($"**{note.Title}**: {note.Text}."); } else { // Print out all the notes if no specific note name was detected string noteList = "Here's the list of all notes: \n\n"; foreach (KeyValuePair <string, Note> entry in NoteByTitle) { Note noteInList = entry.Value; noteList += $"**{noteInList.Title}**: {noteInList.Text}.\n\n"; } await context.PostAsync(noteList); } return(new DialogTurnResult(DialogTurnStatus.Complete)); }
/// <summary> /// Executed after asking the user for the Text of the Note they wish to create. /// </summary> /// <param name="context">Current dialog context</param> /// <param name="noteText">The Text of the note the user wants to create.</param> /// <returns>A DiaogTurnResult</returns> private async Task <DialogTurnResult> After_TextPrompt(DialogContext context, string noteText) { // Set the text of the note var note = await this.currentNote.GetAsync(context.Context, () => new Note()); note.Text = noteText; NoteByTitle[note.Title] = note; await context.PostAsync($"Created note **{note.Title}** that says \"{note.Text}\"."); await this.currentNote.DeleteAsync(context.Context); return(new DialogTurnResult(DialogTurnStatus.Complete)); }
public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext outerDc, object options = null, CancellationToken cancellationToken = default(CancellationToken)) { await outerDc.PostAsync("Alright I will help you create a temp password"); if (sendPassCode(outerDc)) { var dialog = FindDialog(nameof(ResetPasswordPrompt)); return(await outerDc.BeginDialogAsync(nameof(ResetPasswordPrompt))); } else { //here we can simply fail the current dialog because we have root dialog handling all exceptions throw new Exception("Failed to send SMS. Make sure email & phone number has been added to database."); } }
private async Task multipleAppsAsync(DialogContext context) { //here we ask the user which specific app to install when we found more than one var message = context.Context.Activity; int choice; var isNum = int.TryParse(message.Text, out choice); List <string> applist = new List <string>(); var data = await _accessors.ConversationData.GetAsync(context.Context, () => new BotDataBag()); data.TryGetValue("AppList", out applist); if (isNum && choice <= applist.Count && choice > 0) { //minus becoz index zero base context.ActiveDialog.State["AppName"] = applist[choice - 1]; await context.PostAsync($"What is the name of the machine to install?"); } else { await context.PostAsync($"Invalid response. Please reply 1 - {applist.Count()} to indicate your choice."); } }
private async Task ResumeAfterOptionDialog(DialogContext context, object result) { try { var message = result; } catch (Exception ex) { await context.PostAsync($"Failed with message: {ex.Message}"); } finally { context.Wait(this.MessageReceivedAsync); } }
public override async Task <DialogTurnResult> ResumeDialogAsync(DialogContext outerDc, DialogReason reason, object result = null, CancellationToken cancellationToken = default(CancellationToken)) { var prompt = result as ResetPasswordPrompt; var email = outerDc.Context.Activity.From.Id; int?passcode; using (var db = new ContosoHelpdeskContext()) { passcode = db.ResetPasswords.Where(r => r.EmailAddress == email).First().PassCode; } if (prompt.PassCode == passcode) { string temppwd = "TempPwd" + new Random().Next(0, 5000); await outerDc.PostAsync($"Your temp password is {temppwd}"); } return(new DialogTurnResult(DialogTurnStatus.Complete)); }
private async Task machineNameAsync(DialogContext context) { //finally we should have the machine name on which to install the app var message = context.Context.Activity; var machinename = message.Text; var install = new InstallApp() { AppName = context.ActiveDialog.State["AppName"] as string, MachineName = message.Text }; //TODO: Save to database using (var db = new ContosoHelpdeskContext()) { db.InstallApps.Add(install); db.SaveChanges(); } await context.PostAsync($"Great, your request to install {install.AppName} on {install.MachineName} has been scheduled."); }
private async Task <DialogTurnResult> DeleteNote(DialogContext context, LuisResult result) { Note note; if (this.TryFindNote(result, out note)) { NoteByTitle.Remove(note.Title); await context.PostAsync($"Note {note.Title} deleted"); return(new DialogTurnResult(DialogTurnStatus.Complete)); } else { // Prompt the user for a note title var options = new PromptDialogOptions() { Prompt = "What is the title of the note you want to delete?", ReturnMethod = PromptReturnMethods.After_DeleteTitlePrompt }; return(await context.BeginDialogAsync(nameof(PromptWaterfallDialog), options)); } }
public override async Task StartAsync(DialogContext context) { await context.PostAsync("what can i help you with"); //context.Wait(this.MessageReceivedAsync); }
private async Task ShowLuisResult(DialogContext context, LuisResult result) { await context.PostAsync($"You have reached {result.Intents[0].Intent}. You said: {result.Query}"); //context.Wait(MessageReceived); }
private async Task ResumeAfterHotelsFormDialog(DialogContext context, HotelsQuery result) { try { var searchQuery = result; var hotels = await this.GetHotelsAsync(searchQuery); await context.PostAsync($"I found in total {hotels.Count()} hotels for your dates:"); var resultMessage = context.MakeMessage(); resultMessage.AttachmentLayout = AttachmentLayoutTypes.Carousel; resultMessage.Attachments = new List <Attachment>(); foreach (var hotel in hotels) { HeroCard heroCard = new HeroCard() { Title = hotel.Name, Subtitle = $"{hotel.Rating} starts. {hotel.NumberOfReviews} reviews. From ${hotel.PriceStarting} per night.", Images = new List <CardImage>() { new CardImage() { Url = hotel.Image } }, Buttons = new List <CardAction>() { new CardAction() { Title = "More details", Type = ActionTypes.OpenUrl, Value = $"https://www.bing.com/search?q=hotels+in+" + HttpUtility.UrlEncode(hotel.Location) } } }; resultMessage.Attachments.Add(heroCard.ToAttachment()); } await context.PostAsync(resultMessage); } catch (FormCanceledException ex) { string reply; if (ex.InnerException == null) { reply = "You have canceled the operation. Quitting from the HotelsDialog"; } else { reply = $"Oops! Something went wrong :( Technical Details: {ex.InnerException.Message}"; } await context.PostAsync(reply); } finally { context.Done <object>(null); } }