private async void StartNewQuestionaire() { try { questionaire = new Questionaire { Name = sQuestionaire.Name, CreatedBy = User.Key, IsSystem = sQuestionaire.IsSystem, Categories = sQuestionaire.Categories, Regions = sQuestionaire.Regions, TableName = sQuestionaire.TableName, Sections = sQuestionaire.Sections, Template = sQuestionaire.Key }; questionaire.Sections.SelectMany(s => s.Questions).ForEach(q => q.Answers.Clear()); if (questionaire.Categories.Count > 0) { PromptCategorySelection(); } else { canPressBackButton = true; locationDialog = new LocationDialog(this); await PopupNavigation.Instance.PushAsync(locationDialog); } } catch (Exception ex) { } }
private static async Task Respond(IDialogContext context, IMessageActivity message = null) { var userLocation = String.Empty; context.UserData.TryGetValue <string>("Location", out userLocation); if (String.IsNullOrEmpty(userLocation)) { await context.PostAsync("Where are you located?"); context.UserData.SetValue <bool>("GetLocation", true); } else { // Store in App Secrets later var apiKey = AzureMapsKey; var prompt = $"We found this location for {userLocation}, is this right?."; var locationDialog = new LocationDialog(apiKey, message.ChannelId, prompt); context.Call(locationDialog, (dialogContext, result) => { return(null); }); // Find Location and verify using Locatioon, prompt for "is this correct?" //await context.PostAsync($"We found this location for {userLocation}, is this right?."); // show embedded map with Location results. } }
public async Task Should_Post_To_User_Passed_Prompt_When_Start_Called() { // Arrange string prompt = "Where do you want to ship your widget?"; var dialog = new LocationDialog(string.Empty, "facebook", prompt, LocationOptions.None); var context = this.GetSetupMockObject(); context .Setup(c => c.MakeMessage()) .Returns(() => new Activity()); context .Setup(c => c.PostAsync(It.IsAny <IMessageActivity>(), It.IsAny <CancellationToken>())) .Returns(() => Task.CompletedTask); context .Setup(c => c.Call(It.IsAny <IDialog <LocationDialogResponse> >(), It.IsAny <ResumeAfter <LocationDialogResponse> >())) .Callback <IDialog <LocationDialogResponse>, ResumeAfter <LocationDialogResponse> >(async(d, c) => await d.StartAsync(context.Object)); // Act await dialog.StartAsync(context.Object); // Assert var locationResourceManager = new LocationResourceManager(); context.Verify(c => c.Call(It.IsAny <FacebookNativeLocationRetrieverDialog>(), It.IsAny <ResumeAfter <LocationDialogResponse> >()), Times.Never); context.Verify(c => c.PostAsync(It.Is <IMessageActivity>(a => a.Text == prompt + locationResourceManager.TitleSuffix), It.IsAny <CancellationToken>()), Times.Once); }
public async Task DisplayLocationDialog(IDialogContext context, IAwaitable <IMessageActivity> result) { try { var message = await result; var messageText = message.Text; var apiKey = WebConfigurationManager.AppSettings["BingMapsApiKey"]; var options = LocationOptions.UseNativeControl | LocationOptions.ReverseGeocode; var requiredFields = LocationRequiredFields.StreetAddress | LocationRequiredFields.Locality | LocationRequiredFields.Region | LocationRequiredFields.Country | LocationRequiredFields.PostalCode; var prompt = "Where should I ship your bacon?"; var locationDialog = new LocationDialog(apiKey, context.Activity.ChannelId, prompt, options, requiredFields); context.Call(new LocationDialog(apiKey, context.Activity.ChannelId, prompt, options, requiredFields), ResumeAfterLocationDialog); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); await context.PostAsync($"Failed with message: {ex.Message}"); context.Wait(this.MessageReceivedAsync); } }
public async Task CheckCurrentIncidents(IDialogContext context, LuisResult result) { var apiKey = WebConfigurationManager.AppSettings["BingMapsApiKey"]; var prompt = "To check for current incidents I will just need your post code."; var locationDialog = new LocationDialog(apiKey, context.Activity.ChannelId, prompt, LocationOptions.None, LocationRequiredFields.PostalCode); context.Call(locationDialog, AfterLocationCollected); }
private async Task GetLocation(IDialogContext context) { var apiKey = WebConfigurationManager.AppSettings["BingMapsApiKey"]; var prompt = "Where are you? We need you location to find resources nearby."; var locationDialog = new LocationDialog(apiKey, string.Empty, prompt, LocationOptions.UseNativeControl, LocationRequiredFields.None); context.Call(locationDialog, this.ResumeAfterLocationDialogAsync); }
public async Task MessageReceivedStart(IDialogContext context, IAwaitable <IMessageActivity> argument) { var message = await argument; var apiKey = Keys.bingMapsKey; var prompt = "Where should I ship your order? Type or say an address."; var locationDialog = new LocationDialog(apiKey, message.ChannelId, prompt, LocationOptions.None, LocationRequiredFields.StreetAddress | LocationRequiredFields.PostalCode); context.Call(locationDialog, AfterLocationProvided); }
public async void OnEnableLocation() { new GeolocationManager(this).TurnOnLocation(); //Subscribe to geolocation again if (locationDialog == null) { locationDialog = new LocationDialog(this); } await PopupNavigation.Instance.PushAsync(locationDialog, true); }
public async Task If_FacebookChannel_And_NativeControlOption_Call_FacebookLocationDialog() { // Arrange var dialog = new LocationDialog(string.Empty, "facebook", string.Empty, LocationOptions.UseNativeControl); var context = this.GetSetupMockObject(); // Act await dialog.StartAsync(context.Object); // Assert context.Verify(c => c.Call(It.IsAny <FacebookNativeLocationRetrieverDialog>(), It.IsAny <ResumeAfter <LocationDialogResponse> >()), Times.Once()); }
public async Task Where(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result) { var message = await activity; var apiKey = "As5j3FKfU0PQ1mGpartrpxN_qwggIehOx1oj-mI7_3hv17WpaQIAwK6jPWo5AG5q"; var prompt = "告訴我你在哪裡"; var options = LocationOptions.UseNativeControl | LocationOptions.ReverseGeocode; var locationDialog = new LocationDialog(apiKey, message.ChannelId, prompt, options); context.Call(locationDialog, ResumeAfterLocationDialogAsync); }
public async void OnCategorySelectedAsync(Category category) { try { questionaire.Category = category; canPressBackButton = true; locationDialog = new LocationDialog(this); await PopupNavigation.Instance.PushAsync(locationDialog); } catch (Exception ex) { } }
public async Task If_Cancel_Command_Call_Context_Done() { // Arrange var dialog = new LocationDialog(string.Empty, "facebook", string.Empty, LocationOptions.UseNativeControl); var context = this.GetSetupMockObject(); // Act await dialog.MessageReceivedAsync(context.Object, TestHelper.CreateAwaitableMessage("cancel")); // Assert context.Verify(c => c.Done(It.Is <Place>(v => v == null))); }
public virtual async Task CreateLocationMessage(IDialogContext context, IAwaitable <IMessageActivity> argument) { //var message = await argument; var apiKey = WebConfigurationManager.AppSettings["BingMapsApiKey"]; var options = LocationOptions.UseNativeControl | LocationOptions.ReverseGeocode; var requiredFields = LocationRequiredFields.StreetAddress | LocationRequiredFields.Locality | LocationRequiredFields.Region | LocationRequiredFields.Country | LocationRequiredFields.PostalCode; var prompt = "Where should I ship your bacon?"; var locationDialog = new LocationDialog(apiKey, context.Activity.ChannelId, prompt, options, requiredFields); context.Call(new LocationDialog(apiKey, context.Activity.ChannelId, prompt, options, requiredFields), ResumeAfterLocationDialog); //await context.Forward(new LocationDialog(apiKey, context.Activity.ChannelId, prompt, options, requiredFields), ResumeAfterLocationDialog, message, System.Threading.CancellationToken.None); }
protected override async Task MessageReceived(IDialogContext context, IAwaitable <IMessageActivity> item) { var message = await item; if (message.Text.Equals("help", StringComparison.CurrentCultureIgnoreCase)) { var helptext = "I'm able to return room availability based on your office 365 calendar. Based on date and time I'll check for available meeting rooms. \n\n" + "Intents are parsed using luis.ai resolving date input, current version does not support booking a room but is on my very unoffical roadmap ;) \n\n" + "**Examples:**\n\n" + "* **login** - for logging in to office 365\n\n" + "* **logout** - logout of current microsoft account.\n\n" + "* **location** - selecting current location to get accurate timezone settings.\n\n" + "* **available rooms** - checks for available rooms right now in 30min blocks\n\n" + "* **rooms available at 9am** - checks for available 1 hours meeting slots at 9am today, or tomorrow depending on time of day.\n\n" + "* **available rooms tomorrow between 10am and 12am** - looks for a 2 hour block starting at 10am\n\n"; var msg = context.MakeMessage(); msg.TextFormat = "markdown"; msg.Text = helptext; await context.PostAsync(msg); context.Wait(this.MessageReceived); } else if (string.IsNullOrEmpty(await context.GetAccessToken(AuthSettings.Scopes))) { // Start authentication dialog await context.PostAsync($"Please sign in below."); await context.Forward(new AzureAuthDialog(AuthSettings.Scopes), this.ResumeAfterAuth, message, CancellationToken.None); } else if (message.Text == "logout") { // Process logout message await context.Logout(); context.Wait(this.MessageReceived); } else if (!context.UserTimeZoneSet() || message.Text.Equals("location", StringComparison.CurrentCultureIgnoreCase)) { var prompt = "I need to know your locations timezone to accurately provide meeting times, please let me know your location."; var apiKey = WebConfigurationManager.AppSettings["BingMapsApiKey"]; var locationDialog = new LocationDialog(apiKey, message.ChannelId, prompt, LocationOptions.ReverseGeocode | LocationOptions.SkipFavorites | LocationOptions.SkipFinalConfirmation, LocationRequiredFields.Country | LocationRequiredFields.Region, new DibsLocationResourceManager()); context.Call(locationDialog, this.ResumeAfterLocationDialogAsync); } else { // Process incoming message await base.MessageReceived(context, item); } }
public async Task If_Help_Command_Post_Help_Message() { // Arrange var dialog = new LocationDialog(string.Empty, "facebook", string.Empty, LocationOptions.UseNativeControl); var context = new Mock <IDialogContext>(MockBehavior.Loose); context.Setup(c => c.MakeMessage()).Returns(() => new Activity()); // Act await dialog.MessageReceivedAsync(context.Object, TestHelper.CreateAwaitableMessage("help")); // Assert context.Verify(c => c.PostAsync(It.Is <IMessageActivity>(a => a.Text == "The help message"), It.IsAny <CancellationToken>()), Times.Once); }
public async Task If_Help_Command_Post_Help_Message() { // Arrange var dialog = new LocationDialog(string.Empty, "facebook", string.Empty, LocationOptions.UseNativeControl); var context = this.GetSetupMockObject(); // Act await dialog.MessageReceivedAsync(context.Object, TestHelper.CreateAwaitableMessage("help")); // Assert var locationResourceManager = new LocationResourceManager(); context.Verify(c => c.PostAsync(It.Is <IMessageActivity>(a => a.Text == locationResourceManager.HelpMessage), It.IsAny <CancellationToken>()), Times.Once); }
public async Task If_Cancel_Command_Call_Context_Done() { // Arrange var dialog = new LocationDialog(string.Empty, "facebook", string.Empty, LocationOptions.UseNativeControl); var context = new Mock <IDialogContext>(MockBehavior.Loose); context.Setup(c => c.MakeMessage()).Returns(() => new Activity()); // Act await dialog.MessageReceivedAsync(context.Object, TestHelper.CreateAwaitableMessage("cancel")); // Assert context.Verify(c => c.Done(It.Is <Place>(v => v == null))); }
public async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> argument) { var apiKey = WebConfigurationManager.AppSettings["BingMapsApiKey"]; var options = LocationOptions.UseNativeControl | LocationOptions.ReverseGeocode; var requiredFields = LocationRequiredFields.StreetAddress | LocationRequiredFields.Locality | LocationRequiredFields.Region | LocationRequiredFields.Country | LocationRequiredFields.PostalCode; var prompt = "Where should I ship your order?"; var locationDialog = new LocationDialog(apiKey, this.channelId, prompt, options, requiredFields); context.Call(locationDialog, this.ResumeAfterLocationDialogAsync); }
public async Task If_Reset_Command_Call_StartAsync() { // Arrange string prompt = "Where do you want to ship your widget?"; var dialog = new LocationDialog(string.Empty, "facebook", prompt, LocationOptions.None); var context = new Mock <IDialogContext>(MockBehavior.Loose); context.Setup(c => c.MakeMessage()).Returns(() => new Activity()); // Act await dialog.MessageReceivedAsync(context.Object, TestHelper.CreateAwaitableMessage("reset")); // Assert context.Verify(c => c.PostAsync(It.Is <IMessageActivity>(a => a.Text == prompt), It.IsAny <CancellationToken>()), Times.Once); }
public async Task If_Reset_Command_Call_StartAsync() { // Arrange string prompt = "Where do you want to ship your widget?"; var dialog = new LocationDialog(string.Empty, "facebook", prompt, LocationOptions.None); var context = this.GetSetupMockObject(); // Act await dialog.MessageReceivedAsync(context.Object, TestHelper.CreateAwaitableMessage("reset")); // Assert var locationResourceManager = new LocationResourceManager(); context.Verify(c => c.PostAsync(It.Is <IMessageActivity>(a => a.Text == locationResourceManager.ResetPrompt), It.IsAny <CancellationToken>()), Times.Once); }
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> argument) #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously { var apiKey = WebConfigurationManager.AppSettings["BingMapsApiKey"]; var options = LocationOptions.UseNativeControl | LocationOptions.ReverseGeocode; var requiredFields = LocationRequiredFields.StreetAddress | LocationRequiredFields.Locality | LocationRequiredFields.Region | LocationRequiredFields.Country | LocationRequiredFields.PostalCode; var prompt = "Where should I ship your order?"; var locationDialog = new LocationDialog(apiKey, this.channelId, prompt, options, requiredFields); context.Call(locationDialog, this.ResumeAfterLocationDialogAsync); }
private async Task OnOptionSelected(IDialogContext context, IAwaitable <IMessageActivity> result) { var message = await result; if (this.resumptionCookie == null) { this.resumptionCookie = new ResumptionCookie(message); } // User if (message.Text == Resources.RootDialog_Welcome_SeeMenu) { var menuDialog = this.dialogFactory.Create <MenuDialog>(); context.Call(menuDialog, this.AfterMenuItemSelected); } else if (message.Text == Resources.RootDialog_Welcome_Hours) { var r = context.MakeMessage(); r.Text = CheckOpenClosed() ? "Currently Open! " : "Sorry, we're closed "; r.Text += "Were open everyday from 11AM-9PM"; await context.PostAsync(r); await this.StartOverAsync(context, Resources.RootDialog_Welcome_Menu); } else if (message.Text == Resources.RootDialog_Welcome_Directions) { var apiKey = ConfigurationManager.AppSettings["BingLocationAPIKey"]; var options = LocationOptions.UseNativeControl | LocationOptions.ReverseGeocode; var requiredFields = LocationRequiredFields.StreetAddress | LocationRequiredFields.Locality | LocationRequiredFields.Region | LocationRequiredFields.Country | LocationRequiredFields.PostalCode; var prompt = "Please tell me your location"; var locationDialog = new LocationDialog(apiKey, message.ChannelId, prompt, options, requiredFields, null, true, ConfigurationManager.AppSettings["TacoAddress"]); context.Call(locationDialog, this.ResumeAfterLocationDialogAsync); } else { await this.StartOverAsync(context, Resources.RootDialog_Welcome_Error); } }
public async Task If_FacebookChannel_And_NotNativeControlOption_Do_Not_Call_FacebookLocationDialog() { // Arrange var dialog = new LocationDialog(string.Empty, "facebook", string.Empty, LocationOptions.None); var context = this.GetSetupMockObject(); context .Setup(c => c.MakeMessage()) .Returns(() => new Activity()); context .Setup(c => c.PostAsync(It.IsAny <IMessageActivity>(), It.IsAny <CancellationToken>())) .Returns(() => Task.CompletedTask); // Act await dialog.StartAsync(context.Object); // Assert context.Verify(c => c.Call(It.IsAny <FacebookNativeLocationRetrieverDialog>(), It.IsAny <ResumeAfter <LocationDialogResponse> >()), Times.Never); }
public async Task Should_Post_To_User_Passed_Prompt_When_Start_Called() { // Arrange string prompt = "Where do you want to ship your widget?"; var dialog = new LocationDialog(string.Empty, "facebook", prompt, LocationOptions.None); var context = new Mock <IDialogContext>(MockBehavior.Loose); context .Setup(c => c.MakeMessage()) .Returns(() => new Activity()); context .Setup(c => c.PostAsync(It.IsAny <IMessageActivity>(), It.IsAny <CancellationToken>())) .Returns(() => Task.CompletedTask); // Act await dialog.StartAsync(context.Object); // Assert context.Verify(c => c.PostAsync(It.Is <IMessageActivity>(a => a.Text == prompt), It.IsAny <CancellationToken>()), Times.Once); }
public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> argument) { var message = await argument as Activity; if (message.Text == "location") { await context.PostAsync("開始詢問地點,請稍後.."); var apiKey = "As5j3FKfU0PQ1mGpartrpxN_qwggIehOx1oj-mI7_3hv17WpaQIAwK6jPWo5AG5q"; var prompt = "告訴我你在哪裡"; var options = LocationOptions.UseNativeControl | LocationOptions.ReverseGeocode; var locationDialog = new LocationDialog(apiKey, message.ChannelId, prompt, options); context.Call(locationDialog, ResumeAfterLocationDialogAsync); return; } else if (message.Attachments?.Count > 0 && message.Attachments.First().ContentType.StartsWith("image")) { await context.PostAsync("收到圖片,開始辨識,請稍後.."); VisionServiceClient client = new VisionServiceClient("809703eae3894ddf9e2e9b9d33b6cab1"); var url = message.Attachments.First().ContentUrl; var result = await client.AnalyzeImageAsync(url, new VisualFeature[] { VisualFeature.Description }); var reply = context.MakeMessage(); reply.Text = result.Description.Captions.First().Text; await context.PostAsync(reply); await context.PostAsync("complete vision"); } else { await context.PostAsync("Hi there! I'm a bot created to show you how I can receive message attachments, but no attachment was sent to me. Please, try again sending a new message including an attachment."); } context.Wait(this.MessageReceivedAsync); }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (!string.IsNullOrWhiteSpace(m_PLCAddressClick) & Enabled && PLCAddressClick != null) { try { switch (OutputType) { case OutputType.MomentarySet: WCFChannelFactory.Write(m_PLCAddressClick, "1"); break; case OutputType.MomentaryReset: WCFChannelFactory.Write(m_PLCAddressClick, "0"); break; case OutputType.SetTrue: WCFChannelFactory.Write(m_PLCAddressClick, "1"); break; case OutputType.SetFalse: WCFChannelFactory.Write(m_PLCAddressClick, "0"); break; case OutputType.Toggle: var CurrentValue = Value; if (CurrentValue) { WCFChannelFactory.Write(m_PLCAddressClick, "0"); } else { WCFChannelFactory.Write(m_PLCAddressClick, "1"); } break; case OutputType.ValveWeiCtriDialog: var objValveWeiCtriDialog = new ValveWeiCtriDialog(m_PLCAddressClick); var LocationDialogArrays = LocationDialog.Split(';'); objValveWeiCtriDialog.SetDesktopLocation(int.Parse(LocationDialogArrays[0]), int.Parse(LocationDialogArrays[1])); objValveWeiCtriDialog.TopMost = true; objValveWeiCtriDialog.Show(); break; default: break; } } catch (Exception ex) { DisplayError("WRITE FAILED!" + ex.Message); } Invalidate(); } }