protected override async Task OnMembersAddedAsync(IList<ChannelAccount> membersAdded, ITurnContext<IConversationUpdateActivity> turnContext, CancellationToken cancellationToken) { foreach (var member in membersAdded) { // Greet anyone that was not the target (recipient) of this message. // To learn more about Adaptive Cards, see https://aka.ms/msbot-adaptivecards for morBe details. if (member.Id != turnContext.Activity.Recipient.Id) { var user = new List<User>(); var rpaService = new RPAService(); var result = rpaService.GetUser(turnContext.Activity.Conversation.Id); if (result.IsSuccess) user = JsonConvert.DeserializeObject<List<User>>(result.Content); //var _user = user.GetUser(); var msg = string.Empty; if (user.Count > 0) { if (!string.IsNullOrWhiteSpace(user[0].u_user)) { msg = "Hello " + user[0].Name + ", welcome to Bayview ChatBot!"; } } else { msg = "Welcome to Bayview ChatBot!"; } await turnContext.SendActivityAsync(MessageFactory.Text(msg + Environment.NewLine + "What can I help you with today? You could type "+'"'+ "Menu" + '"' + " for available options."), cancellationToken); } } }
private async Task <DialogTurnResult> GetRunningProcessStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var processDetails = (ProcessDetails)stepContext.Options; var processes = processDetails.Processes; var text = "Here are your running processes."; if (processDetails.LoadMore) { text = string.Empty; processDetails.LoadMore = false; } if (processes.Count > 0) { var rpaService = new RPAService(); //var _user = await _userAccessor.GetAsync(stepContext.Context, () => new User(), cancellationToken); var response = rpaService.GetUser(stepContext.Context.Activity.Conversation.Id); var user = new List <User>(); if (response.IsSuccess) { user = JsonConvert.DeserializeObject <List <User> >(response.Content); } var result = rpaService.GetListOfProcess(processes, Convert.ToInt32(user[0].u_last_index)); var choices = result.Choices; //var rpaSupportChoice = rpaService.GetRPASupportOption(); var menuValue = JsonConvert.SerializeObject(new PromptOption { Id = "menu", Value = "menu" }); var mainMenu = new Choice { Value = "menu", //[email protected] Action = new CardAction(ActionTypes.PostBack, "**Main Menu**", null, "**Main Menu**", "**Main Menu**", value: menuValue, null) }; //choices.Add(rpaSupportChoice); choices.Add(mainMenu); //save index user[0].u_last_index = result.LastIndex.ToString(); rpaService.UpdateUser(user[0], stepContext.Context.Activity.Conversation.Id); //_user.u_last_index = result.LastIndex; //await this._userAccessor.SetAsync(stepContext.Context, _user, cancellationToken); return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = (Activity)ChoiceFactory.HeroCard(choices, text + Environment.NewLine + "Click the process you would like to get the status for.") /*Prompt = MessageFactory.Text(text + Environment.NewLine + "Click the process you would like to get the status for."), * Choices = choices, * Style = ListStyle.Auto*/ }, cancellationToken)); } else { processDetails.Action = "error"; return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), processDetails, cancellationToken)); } }
private async Task <DialogTurnResult> ShowProcessStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var processDetails = (ProcessDetails)stepContext.Options; var processes = processDetails.Processes; var text = "Here are your processes in progress. "; if (processDetails.LoadMore) { text = string.Empty; processDetails.LoadMore = false; } if (processes.Count > 0) { var rpaService = new RPAService(); //var _user = await _userAccessor.GetAsync(stepContext.Context, () => new User(), cancellationToken); //get last index var response = rpaService.GetUser(stepContext.Context.Activity.Conversation.Id); var user = new List <User>(); if (response.IsSuccess) { user = JsonConvert.DeserializeObject <List <User> >(response.Content); } var result = rpaService.GetListOfProcess(processes, Convert.ToInt32(user[0].u_last_index)); var choices = result.Choices; //add one choice for rpa support var rpaSupportChoice = rpaService.GetRPASupportOption(); choices.Add(rpaSupportChoice); //save index user[0].u_last_index = result.LastIndex.ToString(); rpaService.UpdateUser(user[0], stepContext.Context.Activity.Conversation.Id); //_user.u_last_index = result.LastIndex; //await this._userAccessor.SetAsync(stepContext.Context, _user, cancellationToken); return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = (Activity)ChoiceFactory.HeroCard(choices, text + "Which one would you like to stop?") /*Prompt = MessageFactory.Text(text+ "Which one would you like to stop?"), * Choices = choices, * Style = ListStyle.Auto*/ }, cancellationToken)); } else { processDetails.Action = "error"; return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), processDetails, cancellationToken)); } }
private async Task <DialogTurnResult> ShowRunningProcessStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var rpaService = new RPAService(); var processDetails = (ProcessDetails)stepContext.Options; var result = stepContext.Result.ToString(); var promptOption = new PromptOption(); try { promptOption = JsonConvert.DeserializeObject <PromptOption>(stepContext.Result.ToString()); } catch (Exception) { } if (!string.IsNullOrEmpty(promptOption.Id)) { if (promptOption.Id != "availableProcesses" && promptOption.Id != "menu") { processDetails.Action = "pastMenu"; return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), processDetails, cancellationToken)); } result = promptOption.Value; } var _response = rpaService.GetUser(stepContext.Context.Activity.Conversation.Id); var user = new List <User>(); if (_response.IsSuccess) { user = JsonConvert.DeserializeObject <List <User> >(_response.Content); } if (result.ToLower() == "menu" || result.ToLower() == "m" /*"*****@*****.**"*/) { //save index user[0].u_last_index = "0"; rpaService.UpdateUser(user[0], stepContext.Context.Activity.Conversation.Id); //_user.u_last_index = 0; //await _userAccessor.SetAsync(stepContext.Context, _user, cancellationToken); processDetails.Action = string.Empty; return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), null, cancellationToken)); } else if (result.ToLower() == "load_more") { processDetails.LoadMore = true; return(await stepContext.ReplaceDialogAsync(nameof(StatusDialog), processDetails, cancellationToken)); } else { processDetails.ProcessSelected = rpaService.GetSelectedProcess(processDetails.Processes, result); //check if a process was selected, or something was written if (!string.IsNullOrEmpty(processDetails.ProcessSelected.Sys_id)) { //save index user[0].u_last_index = "0"; rpaService.UpdateUser(user[0], stepContext.Context.Activity.Conversation.Id); //_user.u_last_index = 0; //await _userAccessor.SetAsync(stepContext.Context, _user, cancellationToken); var apiRequest = new APIRequest { ProcessId = processDetails.ProcessSelected.Sys_id }; if (!string.IsNullOrEmpty(processDetails.ProcessSelected.queuedId)) { apiRequest.Queued = true; } var jobIds = new List <string>(); var releaseIds = new List <string>(); //if there was a process started if (processDetails.Jobs.Count > 0) { foreach (var job in processDetails.Jobs) { foreach (var item in job.Result.Body.Value) { jobIds.Add(item.Id); } } apiRequest.Ids = jobIds; apiRequest.IsJob = true; } else { foreach (var release in processDetails.ProcessSelected.Releases) { releaseIds.Add(release.sys_id); } apiRequest.Ids = releaseIds; apiRequest.IsJob = false; } var response = rpaService.ProcessStatus(apiRequest); var text = string.Empty; if (response.IsSuccess) { var processSatus = JsonConvert.DeserializeObject <List <ProcessStatus> >(response.Content); text = processSatus.Count > 1 ? "Here are the status for " : "Here is the latest status for "; text += processDetails.ProcessSelected.Name + " process." + Environment.NewLine; foreach (var item in processSatus) { var include = "Total Transactions Processed: " + item.TotalTransactions + Environment.NewLine; /* + * "Run Time: " + item.Runtime + Environment.NewLine;*/ if (item.ProcessType == "procedural") { include = string.Empty; } var endTime = item.End != null ? "End Time: " + item.End + Environment.NewLine : string.Empty; var startTime = item.Start != null ? "Start Time: " + item.Start + Environment.NewLine : string.Empty; text += "Status: " + item.State.label + Environment.NewLine + startTime + endTime + include + "Total Transactions Successful: " + Convert.ToInt32(item.TotalTransSuccessful) + Environment.NewLine + "Total Exceptions: " + Convert.ToInt32(item.TotalExceptions) + Environment.NewLine + "Bot Name: " + item.Robot + Environment.NewLine + "Started By: " + item.startedBy; } } else { text = response.Content; } var choices = rpaService.GetConfirmChoices(); return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = (Activity)ChoiceFactory.SuggestedAction(choices, text + Environment.NewLine + "Do you want to check the status of another process?") /*Prompt = MessageFactory.Text(text + Environment.NewLine + "Do you want to check the status of another process?"), * Choices = ChoiceFactory.ToChoices(new List<string> { "Yes", "No" })*/ }, cancellationToken)); } else { return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), null, cancellationToken)); } } }
private async Task <DialogTurnResult> ConfirmStopProcessStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var rpaService = new RPAService(); var processDetails = (ProcessDetails)stepContext.Options; var result = stepContext.Result.ToString(); var promptOption = new PromptOption(); try { promptOption = JsonConvert.DeserializeObject <PromptOption>(stepContext.Result.ToString()); } catch (Exception) { } if (!string.IsNullOrEmpty(promptOption.Id)) { if (promptOption.Id != "availableProcesses" && promptOption.Id != "rpaSuport") { processDetails.Action = "pastMenu"; return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), processDetails, cancellationToken)); } result = promptOption.Value; } var response = rpaService.GetUser(stepContext.Context.Activity.Conversation.Id); var user = new List <User>(); if (response.IsSuccess) { user = JsonConvert.DeserializeObject <List <User> >(response.Content); } //var _user = await _userAccessor.GetAsync(stepContext.Context, () => new User(), cancellationToken); switch (result.ToLower()) { case "load_more": processDetails.LoadMore = true; return(await stepContext.ReplaceDialogAsync(nameof(StopProcessDialog), processDetails, cancellationToken)); case "*****@*****.**": //save index user[0].u_last_index = "0"; rpaService.UpdateUser(user[0], stepContext.Context.Activity.Conversation.Id); //_user.u_last_index = 0; //await _userAccessor.SetAsync(stepContext.Context, _user, cancellationToken); processDetails.Action = string.Empty; return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), processDetails, cancellationToken)); default: processDetails.ProcessSelected = rpaService.GetSelectedProcess(processDetails.Processes, result); if (!string.IsNullOrEmpty(processDetails.ProcessSelected.Sys_id)) { //save index user[0].u_last_index = "0"; rpaService.UpdateUser(user[0], stepContext.Context.Activity.Conversation.Id); //_user.u_last_index = 0; //await _userAccessor.SetAsync(stepContext.Context, _user, cancellationToken); var choices = rpaService.GetConfirmChoices(); return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = (Activity)ChoiceFactory.SuggestedAction(choices, "You have selected " + processDetails.ProcessSelected.Name + ". Stop this process?") /*Prompt = MessageFactory.Text("You have selected " + processDetails.ProcessSelected.Name + ". Stop this process?"), * Choices = ChoiceFactory.ToChoices(new List<string> { "Yes", "No" })*/ }, cancellationToken)); } else { return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), null, cancellationToken)); } } }
private async Task <DialogTurnResult> FinalStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var user = new List <User>(); var rpaService = new RPAService(); var option = string.Empty; try { this.processDetails = (ProcessDetails)stepContext.Result; } catch (Exception) { option = stepContext.Result.ToString(); } var promptOption = new PromptOption(); try { promptOption = JsonConvert.DeserializeObject <PromptOption>(stepContext.Result.ToString()); processDetails.PromptOption = promptOption; } catch (Exception) { } if (!string.IsNullOrEmpty(promptOption.Id)) { if (promptOption.Id != "rpaSuport" && promptOption.Id != "RPAOptions") { processDetails.Action = "pastMenu"; return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), processDetails, cancellationToken)); } option = promptOption.Value; } var result = rpaService.GetUser(stepContext.Context.Activity.Conversation.Id); if (result.IsSuccess) { user = JsonConvert.DeserializeObject <List <User> >(result.Content); } //var _user = await _userAccessor.GetAsync(stepContext.Context, () => new User(), cancellationToken); if (this.processDetails.User != null) { this.processDetails.User.UserId = user[0].u_user; } else { this.processDetails.User = new User { UserId = user[0].u_user }; } if (!string.IsNullOrEmpty(option)) { switch (option.ToLower()) { case "start process": case "start": case "restart bot": case "start bot": processDetails.Action = "start"; return(await stepContext.BeginDialogAsync(nameof(StartProcessDialog), processDetails, cancellationToken)); case "process status": case "status": case "metrics": processDetails.Action = "check status"; return(await stepContext.BeginDialogAsync(nameof(StatusDialog), processDetails, cancellationToken)); case "stop a process": case "stop": case "stop process": case "stop bot": processDetails.Action = "stop"; return(await stepContext.BeginDialogAsync(nameof(StopProcessDialog), processDetails, cancellationToken)); case "report an issue": case "issue": case "report": case "report issue": case "bot failed": case "bot not working": case "bam?id=rpa_new_request&type=incident": processDetails.Action = string.IsNullOrEmpty(promptOption.Id)? "typed" : string.Empty; return(await stepContext.ReplaceDialogAsync(nameof(OpenURLDialog), processDetails, cancellationToken)); /*var value = JsonConvert.SerializeObject(new PromptOption { Id = "FinalStep", Value = "bam?id=rpa_new_request&type=incident" }); * var choices = new List<Choice> { new Choice * { * Value = "bam?id=rpa_new_request&type=incident", * Action = new CardAction(ActionTypes.PostBack, "Click Here", null, "Click Here", "openUrl", value: value, null) * } * }; * choices.Add(rpaService.GetMainMenuOption()); * return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions * { * Prompt = (Activity)ChoiceFactory.SuggestedAction(choices, "To Report an Issue, click Button below") * }, cancellationToken);*/ case "**contact rpa support**": case "contact rpa support": case "rpa support": case "support": case "contact support": case "help": case "need help": case "help needed": return(await stepContext.BeginDialogAsync(nameof(SupportDialog), processDetails, cancellationToken)); case "request an enhancement": case "enhancement": case "request": case "new request": case "bam?id=rpa_new_request&type=enhancement": processDetails.Action = string.IsNullOrEmpty(promptOption.Id) ? "typed" : string.Empty; return(await stepContext.ReplaceDialogAsync(nameof(OpenURLDialog), processDetails, cancellationToken)); /*var enhancementValue = JsonConvert.SerializeObject(new PromptOption { Id = "FinalStep", Value = "bam?id=rpa_new_request&type=enhancement" }); * var options = new List<Choice> { new Choice * { * Value = "bam?id=rpa_new_request&type=enhancement", * Action = new CardAction(ActionTypes.PostBack, "Click Here", null, "Click Here", "openUrl", value: enhancementValue, null) * } }; * options.Add(rpaService.GetMainMenuOption()); * return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions * { * Prompt = (Activity)ChoiceFactory.SuggestedAction(options, "To Request an Enhancement, click Button below") * }, cancellationToken);*/ case "submit a new idea": case "new idea": case "idea": case "new project": case "new process": case "project request": case "bam?id=sc_cat_item&sys_id=a41ac289db7c6f0004b27709af9619a3": processDetails.Action = string.IsNullOrEmpty(promptOption.Id) ? "typed" : string.Empty; return(await stepContext.ReplaceDialogAsync(nameof(OpenURLDialog), processDetails, cancellationToken)); /*var ideaValue = JsonConvert.SerializeObject(new PromptOption { Id = "FinalStep", Value = "bam?id=sc_cat_item&sys_id=a41ac289db7c6f0004b27709af9619a3" }); * return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions * { * Prompt = (Activity)ChoiceFactory.SuggestedAction(new List<Choice> { new Choice * { * Value = "bam?id=sc_cat_item&sys_id=a41ac289db7c6f0004b27709af9619a3", * Action = new CardAction(ActionTypes.PostBack, "Click Here", null, "Click Here", "openUrl", value: ideaValue, null) * } ,rpaService.GetMainMenuOption()}, "To Submit an Idea, click Button below") * * }, cancellationToken);*/ case "Bot Portal": case "bot portal": case "bam?id=rpa_processes": processDetails.Action = string.IsNullOrEmpty(promptOption.Id) ? "typed" : string.Empty; return(await stepContext.ReplaceDialogAsync(nameof(OpenURLDialog), processDetails, cancellationToken)); /*var rpaProcessValue = JsonConvert.SerializeObject(new PromptOption { Id = "FinalStep", Value = "bam?id=rpa_processes" }); * options = new List<Choice> { new Choice * { * Value = "bam?id=rpa_processes", * Action = new CardAction(ActionTypes.PostBack, "Click Here", null, "Click Here", "openUrl", value: rpaProcessValue, null) * } }; * options.Add(rpaService.GetMainMenuOption()); * return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions * { * Prompt = (Activity)ChoiceFactory.SuggestedAction(options, "To go to Bot Portal, click Button below") * }, cancellationToken);*/ case "RPA Process Schedules": case "rpa process schedules": case "bam?id=rpa_process_scheduler": processDetails.Action = string.IsNullOrEmpty(promptOption.Id) ? "typed" : string.Empty; return(await stepContext.ReplaceDialogAsync(nameof(OpenURLDialog), processDetails, cancellationToken)); /*var rpaProcessSchValue = JsonConvert.SerializeObject(new PromptOption { Id = "FinalStep", Value = "bam?id=rpa_process_scheduler" }); * options = new List<Choice> { new Choice * { * Value = "bam?id=rpa_processes", * Action = new CardAction(ActionTypes.PostBack, "Click Here", null, "Click Here", "openUrl", value: rpaProcessSchValue, null) * } }; * options.Add(rpaService.GetMainMenuOption()); * return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions * { * Prompt = (Activity)ChoiceFactory.SuggestedAction(options, "To go to RPA Process Schedules, click Button below") * }, cancellationToken);*/ case "end chat": case "exit": case "exit chat": case "close": case "close chat": case "end": //processDetails.Action = "done"; return(await stepContext.ReplaceDialogAsync(nameof(EndConversationDialog), processDetails, cancellationToken)); //this happen if an exception case "*****@*****.**": processDetails.Action = string.Empty; return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), processDetails, cancellationToken)); //if type something instead of clicking an option default: return(await stepContext.ReplaceDialogAsync(InitialDialogId, null, cancellationToken)); } } else { //if luis not recognize what the user enter return(await stepContext.ReplaceDialogAsync(InitialDialogId, processDetails, cancellationToken)); } }
private async Task BotCallback(ITurnContext turnContext, CancellationToken cancellationToken) { var serviceUrl = turnContext.Activity.ServiceUrl; // If you encounter permission-related errors when sending this message, see // https://aka.ms/BotTrustServiceUrl MicrosoftAppCredentials.TrustServiceUrl(serviceUrl); //var user = await((DialogBot<MainDialog>)_bot)._userAccessor.GetAsync(turnContext, () => new User()); var rpaService = new RPAService(); var response = rpaService.GetUser(turnContext.Activity.Conversation.Id); var user = new List <User>(); if (response.IsSuccess) { user = JsonConvert.DeserializeObject <List <User> >(response.Content); } if (user[0].u_user == _processStatus.ChatbotUser) // && turnContext.Activity.Conversation.Id == _processStatus.ConversationId) { var endTime = _processStatus.End != null ? "End Time: " + _processStatus.End + Environment.NewLine : string.Empty; var startTime = _processStatus.Start != null ? "Start Time: " + _processStatus.Start + Environment.NewLine : string.Empty; var include = "Total Transactions Processed: " + _processStatus.TotalTransactions + Environment.NewLine + startTime + endTime; //"Run Time: " + _processStatus.Runtime + Environment.NewLine; if (_processStatus.ProcessType == "procedural") { include = string.Empty; } var message = string.Empty; if (_processStatus.IsCompletation) { var reason = string.Empty; if (_processStatus.State.value == "Faulted") { reason = "Reason: " + _processStatus.Info + Environment.NewLine; } message = "Process " + _processStatus.Process + " has finished with the following updates:" + Environment.NewLine + "Status: " + _processStatus.State.label + Environment.NewLine + reason + "Bot Name: " + _processStatus.Robot + Environment.NewLine + startTime + endTime + "Successful Executions: " + _processStatus.SuccessfulExecutions + Environment.NewLine + "Exceptions: " + _processStatus.Exceptions; } else { message = "Here is the status for " + _processStatus.Process + " process." + Environment.NewLine + //"Status: " + _processStatus.State + Environment.NewLine + include + "Total Transactions Successful: " + Convert.ToInt32(_processStatus.TotalTransSuccessful) + Environment.NewLine + "Total Exceptions: " + Convert.ToInt32(_processStatus.TotalExceptions) + Environment.NewLine + "Bot Name: " + _processStatus.Robot; } var noti = MessageFactory.Text(message); noti.SuggestedActions = new SuggestedActions { Actions = new List <CardAction> { new CardAction() { Value = "ProcessCompletionDone", Type = ActionTypes.PostBack, Title = "Click Here to continue", Text = "Click Here to continue", DisplayText = "Click Here to continue" } } }; await turnContext.SendActivityAsync(noti); } }