private async Task AfterUrlProvided(IDialogContext context, IAwaitable <CreateSiteCollectionQuery> result) { var formResults = await result; context.UserData.TryGetValue("ResourceId", out _resourceId); var tenantUrl = $"https://{_resourceId}-admin.sharepoint.com"; WebApiApplication.Telemetry.TrackTrace(context.CreateTraceTelemetry(nameof(AfterUrlProvided), new Dictionary <string, string> { { "Getting admin site:", tenantUrl } })); await context.GetAccessToken(tenantUrl); context.UserData.TryGetValue(ContextConstants.AuthResultKey, out _authResult); var success = Create.CreateSiteColleciton(_authResult, formResults, tenantUrl, _resourceId); if (success) { string message = $"Site Collection creation request send. What's next?"; await context.PostAsync(message); } else { WebApiApplication.Telemetry.TrackTrace(context.CreateTraceTelemetry(nameof(AfterUrlProvided), new Dictionary <string, string> { { "Site Collection creation error:", JsonConvert.SerializeObject(result) } })); string message = $"Sorry something went wrong. Please try again later."; await context.PostAsync(message); } context.Wait(MessageReceived); }
public async Task ReIndex(IDialogContext context, LuisResult result) { WebApiApplication.Telemetry.TrackTrace(context.CreateTraceTelemetry(nameof(ReIndex), new Dictionary <string, string> { { "ReIndex found by LUIS:", JsonConvert.SerializeObject(result) } })); var createUrlDialog = FormDialog.FromForm(_formBuilder.AskForUrl, FormOptions.PromptInStart); context.Call(createUrlDialog, ReindexSite); }
public async Task CreateSiteCollection(IDialogContext context, LuisResult result) { WebApiApplication.Telemetry.TrackTrace(context.CreateTraceTelemetry(nameof(CreateSiteCollection), new Dictionary <string, string> { { "Create found by LUIS:", JsonConvert.SerializeObject(result) } })); var createSiteColFormDialog = FormDialog.FromForm(_formBuilder.BuildCreateSiteColForm, FormOptions.PromptInStart); context.Call(createSiteColFormDialog, AfterUrlProvided); }
public async Task Logout(IDialogContext context, LuisResult result) { WebApiApplication.Telemetry.TrackTrace(context.CreateTraceTelemetry(nameof(Logout), new Dictionary <string, string> { { "Logout found by LUIS:", JsonConvert.SerializeObject(result) } })); context.UserData.RemoveValue("ResourceId"); _resourceId = ConfigurationManager.AppSettings["ActiveDirectory.ResourceId"]; await context.Logout(); context.Wait(MessageReceived); }
public async Task None(IDialogContext context, LuisResult result) { string message = $"Sorry I did not understand: " + string.Join(", ", result.Intents.Select(i => i.Intent)); WebApiApplication.Telemetry.TrackTrace(context.CreateTraceTelemetry(nameof(None), new Dictionary <string, string> { { "No intent found by luis", JsonConvert.SerializeObject(result) } })); await context.PostAsync(message); context.Wait(MessageReceived); }
public async Task GetSiteInfo(IDialogContext context, LuisResult result) { WebApiApplication.Telemetry.TrackTrace(context.CreateTraceTelemetry(nameof(GetSiteInfo), new Dictionary <string, string> { { "GetInfo found by LUIS:", JsonConvert.SerializeObject(result) } })); var createUrlDialog = FormDialog.FromForm(_formBuilder.AskForUrl, FormOptions.PromptInStart); EntityRecommendation entity; if (result.TryFindEntity("SiteCollection", out entity)) { context.Call(createUrlDialog, GetSiteCollectionInfo); } else { context.Call(createUrlDialog, GetWebInfo); } }
public async Task StartAsync(IDialogContext context) { var telemetry = context.CreateTraceTelemetry(nameof(StartAsync), new Dictionary <string, string> { { @"SetDefault", bool.FalseString } }); string defaultCity; if (!context.ConversationData.TryGetValue(ContextConstants.CityKey, out defaultCity)) { defaultCity = "Seattle"; context.ConversationData.SetValue(ContextConstants.CityKey, defaultCity); telemetry.Properties[@"SetDefault"] = bool.TrueString; } await context.PostAsync($"Welcome to the Search City bot. I'm currently configured to search for things in {defaultCity}"); WebApiApplication.Telemetry.TrackTrace(telemetry); context.Wait(this.MessageReceivedAsync); }
private async Task ResumeAfterPrompt(IDialogContext context, IAwaitable <string> result) { try { var userName = await result; this.userWelcomed = true; await context.PostAsync($"Welcome {userName}! {HelpMessage}"); context.UserData.SetValue(ContextConstants.UserNameKey, userName); } catch (TooManyAttemptsException ex) { WebApiApplication.Telemetry.TrackException(context.CreateExceptionTelemetry(ex)); } finally { // It's a good idea to log telemetry in finally {} blocks so you don't end up with gaps of execution // as you follow a conversation WebApiApplication.Telemetry.TrackTrace(context.CreateTraceTelemetry(nameof(ResumeAfterPrompt))); } context.Wait(this.MessageReceivedAsync); }
public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> result) { var message = await result; // Here's how we can serialize an entire object to an App Insights event WebApiApplication.Telemetry.TrackTrace(context.CreateTraceTelemetry( nameof(MessageReceivedAsync), new Dictionary <string, string> { { "message", JsonConvert.SerializeObject(message) } })); string userName; if (!context.UserData.TryGetValue(ContextConstants.UserNameKey, out userName)) { var t = context.CreateEventTelemetry(@"new user"); t.Properties.Add("userName", userName); // You can add properties after-the-fact as well WebApiApplication.Telemetry.TrackEvent(t); PromptDialog.Text(context, this.ResumeAfterPrompt, "Before get started, please tell me your name?"); return; } if (!this.userWelcomed) { this.userWelcomed = true; await context.PostAsync($"Welcome back {userName}! Remember the rules: {HelpMessage}"); context.Wait(this.MessageReceivedAsync); return; } if (message.Text.Equals("current city", StringComparison.InvariantCultureIgnoreCase)) { WebApiApplication.Telemetry.TrackEvent(context.CreateEventTelemetry(@"current city")); string userCity; var city = context.ConversationData.Get <string>(ContextConstants.CityKey); if (context.PrivateConversationData.TryGetValue(ContextConstants.CityKey, out userCity)) { await context.PostAsync($"{userName}, you have overridden the city. Your searches are for things in {userCity}. The default conversation city is {city}."); } else { await context.PostAsync($"Hey {userName}, I'm currently configured to search for things in {city}."); } } else if (message.Text.StartsWith("change city to", StringComparison.InvariantCultureIgnoreCase)) { WebApiApplication.Telemetry.TrackEvent(context.CreateEventTelemetry(@"change city to")); var newCity = message.Text.Substring("change city to".Length).Trim(); context.ConversationData.SetValue(ContextConstants.CityKey, newCity); await context.PostAsync($"All set {userName}. From now on, all my searches will be for things in {newCity}."); } else if (message.Text.StartsWith("change my city to", StringComparison.InvariantCultureIgnoreCase)) { WebApiApplication.Telemetry.TrackEvent(context.CreateEventTelemetry(@"change my city to")); var newCity = message.Text.Substring("change my city to".Length).Trim(); context.PrivateConversationData.SetValue(ContextConstants.CityKey, newCity); await context.PostAsync($"All set {userName}. I have overridden the city to {newCity} just for you."); } else { var measuredEvent = context.CreateEventTelemetry(@"search"); var timer = new System.Diagnostics.Stopwatch(); timer.Start(); try { string city; if (!context.PrivateConversationData.TryGetValue(ContextConstants.CityKey, out city)) { city = context.ConversationData.Get <string>(ContextConstants.CityKey); } await context.PostAsync($"{userName}, wait a few seconds. Searching for '{message.Text}' in '{city}'..."); await context.PostAsync($"https://www.bing.com/search?q={HttpUtility.UrlEncode(message.Text)}+in+{HttpUtility.UrlEncode(city)}"); } catch (Exception ex) { measuredEvent.Properties.Add("exception", ex.ToString()); WebApiApplication.Telemetry.TrackException(context.CreateExceptionTelemetry(ex)); } finally { timer.Stop(); measuredEvent.Metrics.Add(@"timeTakenMs", timer.ElapsedMilliseconds); WebApiApplication.Telemetry.TrackEvent(measuredEvent); } } context.Wait(this.MessageReceivedAsync); }
public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> item) { var message = await item; WebApiApplication.Telemetry.TrackTrace(context.CreateTraceTelemetry( nameof(MessageReceivedAsync), new Dictionary <string, string> { { "message", JsonConvert.SerializeObject(message) } })); if (message.Text == "logout" || message.Text == "reset") { context.UserData.RemoveValue("ResourceId"); _resourceId = ConfigurationManager.AppSettings["ActiveDirectory.ResourceId"]; await context.Logout(); context.Wait(MessageReceivedAsync); } else { if (string.IsNullOrEmpty(await context.GetAccessToken(ConfigurationManager.AppSettings["ActiveDirectory.ResourceId"]))) { var measuredEvent = context.CreateEventTelemetry(@"Login with Graph URL"); var timer = new System.Diagnostics.Stopwatch(); timer.Start(); try { string reply = $"First we need to authenticate you"; await context.PostAsync(reply); await context.Forward( new AzureAuthDialog(ConfigurationManager.AppSettings["ActiveDirectory.ResourceId"]), ResumeAfterAuth, message, CancellationToken.None); } catch (Exception ex) { measuredEvent.Properties.Add("exception", ex.ToString()); WebApiApplication.Telemetry.TrackException(context.CreateExceptionTelemetry(ex)); } finally { timer.Stop(); measuredEvent.Metrics.Add(@"timeTakenMs", timer.ElapsedMilliseconds); WebApiApplication.Telemetry.TrackEvent(measuredEvent); } } else { try { var spUrl = $"https://{_resourceId}.sharepoint.com"; WebApiApplication.Telemetry.TrackEvent(context.CreateEventTelemetry($"SPUrl: {spUrl}")); if (string.IsNullOrEmpty(await context.GetAccessToken(spUrl))) { await context.Forward( new AzureAuthDialog(ConfigurationManager.AppSettings["ActiveDirectory.ResourceId"]), ResumeAfterAuth, message, CancellationToken.None); } else { WebApiApplication.Telemetry.TrackEvent(context.CreateEventTelemetry(@"Calling RootLuisDialog")); await context.Forward(new RootLuisDialog(), null, message, CancellationToken.None); } } catch (Exception ex) { WebApiApplication.Telemetry.TrackException(context.CreateExceptionTelemetry(ex)); WebApiApplication.Telemetry.TrackEvent(context.CreateEventTelemetry(@"Error in masterdialog forwarding to Luis")); string reply = $"Sorry something went wrong"; await context.PostAsync(reply); context.Wait(MessageReceivedAsync); } } } }