public async Task AcaoIntent(IDialogContext context, LuisResult result) { var subscription = ObterSubscription(context); if (string.IsNullOrEmpty(subscription)) { return; } var applicationId = ObterApplicationId(context); if (string.IsNullOrEmpty(applicationId)) { return; } var secretKey = ObterSecretKey(context); if (string.IsNullOrEmpty(secretKey)) { return; } var activity = context.Activity; var stateClient = activity.GetStateClient(); var userData = stateClient.BotState.GetUserData(activity.ChannelId, activity.From.Id); ProcessadorResult processadorResult = null; if (result.Intents.Any(i => i.Intent.ToUpper() == "ACAO")) { if (result.Entities.Any(v => v.Type.ToUpper() == "LISTAR")) { processadorResult = await ProcessarListagem(result, userData); } if (result.Entities.Any(i => i.Type.ToUpper() == "OPERACOES" && i.Entity.ToUpper() != "CRIAR")) { processadorResult = await ProcessarAcao(result, userData); } if (result.Entities.Any(i => i.Type.ToUpper() == "OPERACOES" && i.Entity.ToUpper() == "CRIAR")) { var resourceGroups = await ActionBuilder.ListResourceGroups(subscription, applicationId, secretKey); var dialog = new PromptDialog.PromptChoice <string>(resourceGroups.Select(r => r.Name), "Em qual resource group deseja criar?", "Desculpa opção inválida", 3); context.Call(dialog, ResourceGroupPromptResultAsync); return; } } await stateClient.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, userData); await context.PostAsync(processadorResult?.Mensagem); context.Wait(MessageReceived); }
private static async Task <ProcessadorResult> ProcessarListagem(LuisResult result, BotData userData) { List <IAzureItem> resources; var subscriptionId = userData.GetProperty <string>("SUBSCRIPTION"); var applicationId = userData.GetProperty <string>("APPLICATIONID"); var secretKey = userData.GetProperty <string>("SECRETKEY"); if (result.Entities.Any(v => v.Type.ToUpper() == "TODOSRECURSOS")) { resources = await ActionBuilder.ListResources(subscriptionId, applicationId, secretKey); userData.SetProperty("RESOURCES", resources); } else { resources = await ActionBuilder.ListResourceGroups(subscriptionId, applicationId, secretKey); userData.SetProperty("RESOURCEGROUPS", resources); } var mensagemResult = new StringBuilder(); if (resources.Any()) { mensagemResult.AppendLine(resources[0].GetType().Name); } foreach (var azureResource in resources) { mensagemResult.AppendLine($"* {azureResource}"); } return(new ProcessadorResult { Processado = true, Mensagem = mensagemResult.ToString() }); }