private async Task <DialogTurnResult> finalStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { int days = (int)stepContext.Result; if (days >= 0) { stepContext.Values["AdminDuration"] = days; admin.AdminDuration = (int)stepContext.Values["AdminDuration"]; admin.MachineName = (string)stepContext.Values["MachineName"]; using (var db = new ContosoHelpdeskContext()) { db.LocalAdmins.Add(admin); db.SaveChanges(); } var ticketNumber = new Random().Next(0, 20000); await stepContext.Context.SendActivityAsync($"Thank you for using the Helpdesk Bot. Your ticket number is {ticketNumber}."); return(await stepContext.EndDialogAsync()); } else { await stepContext.Context.SendActivityAsync($"Invalid response provided. Ending dialog."); return(await stepContext.EndDialogAsync()); } }
private bool sendPassCode(WaterfallStepContext context) { bool result = false; //Recipient Id varies depending on channel //refer ChannelAccount class https://docs.botframework.com/en-us/csharp/builder/sdkreference/dd/def/class_microsoft_1_1_bot_1_1_connector_1_1_channel_account.html#a0b89cf01fdd73cbc00a524dce9e2ad1a //as well as Activity class https://docs.botframework.com/en-us/csharp/builder/sdkreference/dc/d2f/class_microsoft_1_1_bot_1_1_connector_1_1_activity.html var email = context.Context.Activity.From.Id; int passcode = new Random().Next(1000, 9999); Int64? smsNumber = 0; string smsMessage = "Your Contoso Pass Code is "; string countryDialPrefix = "+1"; //save PassCode to database using (var db = new ContosoHelpdeskContext()) { var reset = db.ResetPasswords.Where(r => r.EmailAddress == email).ToList(); if (reset.Count >= 1) { reset.First().PassCode = passcode; smsNumber = reset.First().MobileNumber; result = true; } db.SaveChanges(); } if (result) { result = Helper.SendSms($"{countryDialPrefix}{smsNumber.ToString()}", $"{smsMessage} {passcode}"); } return(result); }
private async Task ResumeAfterLocalAdminFormDialog(IDialogContext context, IAwaitable <LocalAdminPrompt> userReply) { using (var db = new ContosoHelpdeskContext()) { db.LocalAdmins.Add(admin); db.SaveChanges(); } context.Done <object>(null); }
private async Task <DialogTurnResult> multipleAppsStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { // Check to see if user selected app when there are multiple applications to pick from if (stepContext.Values.ContainsKey("AppSelected")) { names.Clear(); } else { names = await this.getAppsAsync(stepContext.Values["AppName"].ToString()); } // If multiple apps returned then need to prompt user for which one to select if (names.Count > 1) { int choice = (int)stepContext.Result; if (choice <= names.Count && choice > 0) { //minus because index zero base stepContext.Values["AppName"] = names[choice - 1]; stepContext.Values["AppSelected"] = true; return(await stepContext.PromptAsync("promptText", new PromptOptions { Prompt = MessageFactory.Text($"What is the name of the machine to install?") }, cancellationToken)); } else { return(await stepContext.PromptAsync("promptNumber", new PromptOptions { Prompt = MessageFactory.Text($"Invalid response. Please reply 1 - {names.Count()} to indicate your choice.") }, cancellationToken)); } } else { // Proceed with saving entry into database var machineName = (string)stepContext.Result; Models.InstallApp install = new InstallApp(); install.AppName = (string)stepContext.Values["AppName"]; install.MachineName = machineName; stepContext.Values["MachineName"] = machineName; //TODO: Save to database using (var db = new ContosoHelpdeskContext()) { db.InstallApps.Add(install); db.SaveChanges(); } logger.Info("InstallAppDialog: AppName = " + install.AppName + "; MachineName = " + install.MachineName); await stepContext.Context.SendActivityAsync($"Great, your request to install {install.AppName} on {install.MachineName} has been scheduled."); return(await stepContext.EndDialogAsync()); } }
private async Task <DialogTurnResult> PasscodeReceivedStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { int result; bool isNum = int.TryParse(stepContext.Context.Activity.Text, out result); if (isNum) { var email = stepContext.Context.Activity.From.Id; int?passcode; using (var db = new ContosoHelpdeskContext()) { passcode = db.ResetPasswords.Where(r => r.EmailAddress == email).First().PassCode; } if (result == passcode) { string temppwd = "TempPwd" + new Random().Next(0, 5000); using (var db = new ContosoHelpdeskContext()) { var reset = db.ResetPasswords.Where(r => r.EmailAddress == email).First(); reset.TempPassword = temppwd; db.SaveChanges(); } await stepContext.Context.SendActivityAsync($"Your temp password is {temppwd}"); return(await stepContext.EndDialogAsync()); } else { await stepContext.Context.SendActivityAsync($"Incorrect passcode."); return(await stepContext.EndDialogAsync()); } } else { await stepContext.Context.SendActivityAsync($"Invalid passcode."); return(await stepContext.EndDialogAsync()); } }
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 machineNameAsync(IDialogContext context, IAwaitable <IMessageActivity> userReply) { //this will trigger a wait for user's reply //finally we ask for the machine name on which to install the app var message = await userReply; var machinename = message.Text; this.install.MachineName = machinename; //TODO: Save to database using (var db = new ContosoHelpdeskContext()) { db.InstallApps.Add(install); db.SaveChanges(); } await context.PostAsync($"Great, your request to install {this.install.AppName} on {this.install.MachineName} has been scheduled."); context.Done <object>(null); }
public override async Task <DialogTurnResult> ContinueDialogAsync(DialogContext outerDc, CancellationToken cancellationToken = default(CancellationToken)) { var dialog = FindDialog(nameof(LocalAdminPrompt)); var dialogResult = await dialog.ContinueDialogAsync(outerDc, cancellationToken).ConfigureAwait(false); if (dialogResult.Status == DialogTurnStatus.Complete) { var result = dialogResult.Result as LocalAdminPrompt; LocalAdmin admin = new LocalAdmin() { AdminDuration = result.AdminDuration, MachineName = result.MachineName }; using (var db = new ContosoHelpdeskContext()) { db.LocalAdmins.Add(admin); db.SaveChanges(); } } return(dialogResult); }