private async Task LogIn(IDialogContext context) { await context.PostAsync(context.CreateTypingActivity()); var ticket = await SitecoreAuthenticationAPI.Instance().GetTicket(new ConversationReference( user: new ChannelAccount(id: context.Activity.From.Id), conversation: new ConversationAccount(id: context.Activity.Conversation.Id), bot: new ChannelAccount(id: context.Activity.Recipient.Id), channelId: context.Activity.ChannelId, serviceUrl: context.Activity.ServiceUrl)); var sitecoreLoginUrl = SitecoreAuthenticationAPI.Instance().GetSitecoreLoginURL(ticket); var reply = context.MakeMessage(); reply.Attachments = new List <Attachment>(); List <CardAction> cardButtons = new List <CardAction>(); CardAction loginButton = new CardAction() { Value = sitecoreLoginUrl, Type = "openUrl", Title = "login" }; cardButtons.Add(loginButton); SigninCard plCard = new SigninCard(text: "Trust me, I'm not standing here with Bobby Hack!!", buttons: cardButtons); reply.Attachments.Add(plCard.ToAttachment()); await context.PostAsync(reply); }
public async Task Status(IDialogContext context, LuisResult result) { await context.PostAsync("Peace man! If I aint't talking to you I sure was having a problem. Let me just check some stuff to make sure everything is set up correct."); await context.PostAsync(context.CreateTypingActivity()); Thread.Sleep(4000); await context.PostAsync("I haven't found any problems so far! Now that we're all set, what would you like to do now?"); }
public async Task Greeting(IDialogContext context, LuisResult result) { var isAuthenticated = await context.IsAuthenticated(); if (isAuthenticated) { var profile = context.GetProfile(); await context.PostAsync($"{profile.FullName}, want some coffee? Hold on!"); await context.PostAsync(context.CreateTypingActivity()); Thread.Sleep(1500); } int random = new Random(DateTime.Now.Second).Next(0, 4); switch (random) { case 1: await context.PostAsync($"Yes, tell me! What are you looking for?"); break; case 2: await context.PostAsync($"Hello from the other side!"); break; case 3: await context.PostAsync($"Bots are just \"fake\" technology!"); break; case 4: await context.PostAsync($"Peace man!"); break; default: await context.PostAsync($"Yes, I'm listening..."); break; } }
public async Task AppInsightsTraces(IDialogContext context, LuisResult result) { var isAuthenticated = await context.IsAuthenticated(); if (!isAuthenticated) { context.SetUnauthorizedMessageText(result.Query); await context.Forward(new AuthenticationDialog(), this.ResumeAfterAuth, context.MakeMessage(), CancellationToken.None); } else if (context.IsAdministrator() || context.IsInRole(RoleNames.BotAnalytics)) { int top = 25; EntityRecommendation entity; if (result.TryFindEntity(Constants.Entities.Top, out entity)) { int.TryParse(entity.Entity, out top); } await context.PostAsync($"Hold on! I'm pulling the last {top} traces from the cloud!"); await context.PostAsync(context.CreateTypingActivity()); var profile = context.GetProfile(); var service = new Connector.AppInsights.ApplicationInsightsService(profile.ApplicationInsights.ApplicationId, profile.ApplicationInsights.ApiKey); var traces = service.GetTraces(new TimeSpan(1, 0, 0), top).ToList(); StringBuilder sb = new StringBuilder(); traces.ForEach(trace => { sb.AppendLine($"{trace.timestamp} {trace.trace.message} \n"); }); await context.PostAsync(sb.ToString()); } }
public async Task ListUser(IDialogContext context, LuisResult result) { var isAuthenticated = await context.IsAuthenticated(); if (!isAuthenticated) { context.SetUnauthorizedMessageText(result.Query); await context.Forward(new AuthenticationDialog(), this.ResumeAfterAuth, context.MakeMessage(), CancellationToken.None); } else if (context.IsAdministrator()) { EntityRecommendation domain; EntityRecommendation role; result.TryFindEntity(Entities.Domain, out domain); result.TryFindEntity(Entities.Role, out role); await context.PostAsync(context.CreateTypingActivity()); var users = await SitecoreUserManagementAPI.Instance(context.AccessToken()).GetUsers(domain == null ? null : domain.Entity, role == null ? null : role.Entity); StringBuilder sb = new StringBuilder(); if (users.Count == 0) { if (domain != null && role != null) { sb.AppendLine($"I'm sorry, we don't have {role.Entity} users in the {domain.Entity} domain \n \n"); } else if (domain != null && role == null) { sb.AppendLine($"I'm sorry, we don't have {domain.Entity} domain \n \n"); } else { sb.AppendLine($"I'm sorry, I haven't found any Sitecore users \n \n"); } } else { if (domain != null && role != null) { sb.AppendLine($"Here is the list of {role.Entity} users in the {domain.Entity} domain \n \n"); } else if (domain != null && role == null) { sb.AppendLine($"Here is the list of users in the {domain.Entity} domain \n \n"); } else { sb.AppendLine($"Here is the list of Sitecore users \n \n"); } users.ForEach(user => { if (user.IsOnline) { sb.AppendLine($"{user.FullName} ({user.UserName}) is currently online! \n"); } else { sb.AppendLine( user.LastActivity.HasValue ? $"{user.FullName} ({user.UserName}) last activity {user.LastActivity.Value} \n" : $"{user.FullName} ({user.UserName}) \n"); } }); } await context.PostAsync(sb.ToString()); } }