public async void Execute(object parameter) { if (parameter is Button button) { switch (button.ButtonType) { case ButtonTypeEnum.PostText: if (!button.Hidden) { ButtonActionHelper.HandlePostTextToThread(button.ButtonText); } break; case ButtonTypeEnum.OpenUrl: ButtonActionHelper.HandleOpenUrl(button.Url); break; case ButtonTypeEnum.GetText: if (string.IsNullOrWhiteSpace(button.VariableValue)) { return; } ButtonActionHelper.HandleSaveTextInput(button.VariableName, button.VariableValue); if (!button.Hidden) { ButtonActionHelper.HandlePostTextToThread(button.PrefixText + button.VariableValue + button.PostfixText); } break; case ButtonTypeEnum.GetEmail: if (string.IsNullOrWhiteSpace(button.VariableValue)) { return; } if (!Utils.IsValidEmail(button.VariableValue)) { Utils.ShowDialog("Invalid format"); return; } ButtonActionHelper.HandleSaveTextInput(button.VariableName, button.VariableValue); if (!button.Hidden) { ButtonActionHelper.HandlePostTextToThread(button.PrefixText + button.VariableValue + button.PostfixText); } break; case ButtonTypeEnum.GetNumber: if (string.IsNullOrWhiteSpace(button.VariableValue)) { return; } double d; if (!double.TryParse(button.VariableValue, out d)) { Utils.ShowDialog("Invalid format"); return; } ButtonActionHelper.HandleSaveTextInput(button.VariableName, d.ToString()); if (!button.Hidden) { ButtonActionHelper.HandlePostTextToThread(button.PrefixText + d.ToString() + button.PostfixText); } break; case ButtonTypeEnum.GetPhoneNumber: if (string.IsNullOrWhiteSpace(button.VariableValue)) { return; } if (!Utils.IsValidPhoneNumber(button.VariableValue)) { Utils.ShowDialog("Invalid format"); return; } ButtonActionHelper.HandleSaveTextInput(button.VariableName, button.VariableValue); if (!button.Hidden) { ButtonActionHelper.HandlePostTextToThread(button.PrefixText + button.VariableValue + button.PostfixText); } break; case ButtonTypeEnum.GetItemFromSource: var valueToSave = button.Items.FirstOrDefault(x => x.Value == button.VariableValue); if (valueToSave.Key == null && valueToSave.Value == null) { Utils.ShowDialog("Invalid value"); return; } ButtonActionHelper.HandleSaveTextInput(button.VariableName, valueToSave.Key); if (!button.Hidden) { ButtonActionHelper.HandlePostTextToThread(button.PrefixText + button.VariableValue + button.PostfixText); } break; case ButtonTypeEnum.GetAddress: { bool done = false; while (!done) { var ad = new AddressDialog(); var res = await ad.ShowAsync(); switch (res) { case Windows.UI.Xaml.Controls.ContentDialogResult.Primary: if (Utils.ValidateStrings(ad.City, ad.PinCode, ad.Country, ad.Latitude == 0 ? "" : ad.Latitude.ToString(), ad.Longitude == 0 ? "" : ad.Longitude.ToString(), ad.StreetAddress)) { ButtonActionHelper.HandleSaveTextInput("CITY", ad.City); ButtonActionHelper.HandleSaveTextInput("COUNTRY", ad.Country); ButtonActionHelper.HandleSaveTextInput("PINCODE", ad.PinCode); ButtonActionHelper.HandleSaveTextInput("LAT", ad.Latitude.ToString()); ButtonActionHelper.HandleSaveTextInput("LNG", ad.Longitude.ToString()); ButtonActionHelper.HandleSaveTextInput("STREET_ADDRESS", ad.StreetAddress); if (!button.Hidden) { ButtonActionHelper.HandlePostTextToThread($"{ad.StreetAddress}\r\n\r\nCity: {ad.City}\r\nCountry: {ad.Country}\r\nPin: {ad.PinCode}"); } done = true; } break; default: break; } if (!done) { await Utils.ShowDialogAsync("All fields in address are mandatory!"); } } } break; case ButtonTypeEnum.GetImage: case ButtonTypeEnum.GetAudio: case ButtonTypeEnum.GetVideo: var image = await ButtonActionHelper.HandleSaveMediaInputAsync(button.VariableName, button.ButtonType); ButtonActionHelper.HandlePostMediaToThread(image, button.ButtonType); break; case ButtonTypeEnum.NextNode: if (!button.Hidden) { ButtonActionHelper.HandlePostTextToThread(button.ButtonText); } if (!string.IsNullOrWhiteSpace(button.VariableName) && button.VariableValue != null) //VariableValue should be != null only { ButtonActionHelper.HandleSaveTextInput(button.VariableName, button.VariableValue); } break; case ButtonTypeEnum.DeepLink: await ButtonActionHelper.HandleDeepLinkAsync(button.DeepLinkUrl); if (!button.Hidden) { ButtonActionHelper.HandlePostTextToThread(button.ButtonText); } break; default: Utils.ShowDialog($"Button type: {button.ButtonType} not supported"); break; } ButtonActionHelper.NavigateToNode(button.NextNodeId); } }
public ServiceSchedulingPageViewModel(INavigationService navigationService, IEventAggregator eventAggregator, ILocationService locationService, IServiceDetailService serviceDetailService, ISupplierService supplierService, ITaskService taskService) { this._navigationService = navigationService; this._serviceDetailService = serviceDetailService; this._taskService = taskService; this._eventAggregator = eventAggregator; this._locationService = locationService; this._supplierService = supplierService; this.Model = new ServiceSchedulingDetail(); _busyIndicator = new BusyIndicator(); IsEnabledDesType = true; this.Address = new BusinessLogic.Portable.SSModels.Address(); this.applicationTheme = Application.Current.RequestedTheme; this.SpBorderBrush = this.applicationTheme == ApplicationTheme.Dark ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Colors.Black); this.LtBorderBrush = this.applicationTheme == ApplicationTheme.Dark ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Colors.Black); this.DtBorderBrush = this.applicationTheme == ApplicationTheme.Dark ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Colors.Black); this.StBorderBrush = this.applicationTheme == ApplicationTheme.Dark ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Colors.Black); this.IsLiftRequired = false; this.AddVisibility = Visibility.Collapsed; BoundWidth = Window.Current.Bounds.Width - 30; BoundMinWidth = Window.Current.Bounds.Width - 80; this.NextPageCommand = DelegateCommand.FromAsyncHandler( async() => { try { if (this.Validate()) { _busyIndicator.Open("Please wait, Saving ..."); this.Model.ServiceDateOption1 = this.Model.ServiceDateOpt1.ToString("MM/dd/yyyy HH:mm"); this.Model.ServiceDateOption2 = this.Model.ServiceDateOpt2.ToString("MM/dd/yyyy HH:mm"); this.Model.ODOReadingDate = this.Model.ODOReadingDt.ToString("MM/dd/yyyy HH:mm"); bool response = await _serviceDetailService.InsertServiceDetailsAsync(this.Model, this.Address, this.UserInfo); if (response) { var caseStatus = await this._taskService.UpdateStatusListAsync(this.SelectedTask, this.UserInfo); var supplier = new SupplierSelection() { CaseNumber = this.SelectedTask.CaseNumber, CaseServiceRecID = this.SelectedTask.CaseServiceRecID, SelectedSupplier = this.SelectedSupplier }; var res = await this._supplierService.InsertSelectedSupplierAsync(supplier, this.UserInfo); if (res) { this.SelectedTask.Status = caseStatus.Status; await this._taskService.UpdateStatusListAsync(this.SelectedTask, this.UserInfo); PersistentData.RefreshInstance(); navigationService.Navigate("Main", string.Empty); } } _busyIndicator.Close(); } } catch (Exception ex) { _busyIndicator.Close(); } finally { } }, () => { return(this.Model != null); }); this.TakePictureCommand = DelegateCommand <ImageCapture> .FromAsyncHandler(async (param) => { FileOpenPicker openPicker = new FileOpenPicker(); openPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail; openPicker.FileTypeFilter.Add(".bmp"); openPicker.FileTypeFilter.Add(".png"); openPicker.FileTypeFilter.Add(".jpeg"); openPicker.FileTypeFilter.Add(".jpg"); PersistentData.Instance.ServiceSchedulingDetail = this.Model; openPicker.PickSingleFileAndContinue(); this._eventAggregator.GetEvent <ServiceSchedulingDetailEvent>().Subscribe(model => { this.Model = model; }); this._eventAggregator.GetEvent <ImageCaptureEvent>().Subscribe(imageCapture => { this.Model.OdoReadingImageCapture = imageCapture; }); }); this.OpenImageViewerCommand = new DelegateCommand( async() => { if (_imageViewer == null) { _imageViewer = new ImageViewerPopup(this._eventAggregator, this.Model); } else { _imageViewer = null; this._imageViewer = new ImageViewerPopup(this._eventAggregator, this.Model); } _imageViewer.DataContext = this.Model.OdoReadingImageCapture; await _imageViewer.ShowAsync(); }); this.VoiceCommand = new DelegateCommand(async() => { try { SpeechRecognizer recognizer = new SpeechRecognizer(); SpeechRecognitionTopicConstraint topicConstraint = new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.Dictation, "Development"); recognizer.Constraints.Add(topicConstraint); await recognizer.CompileConstraintsAsync(); var results = await recognizer.RecognizeWithUIAsync(); if (results != null & (results.Confidence != SpeechRecognitionConfidence.Rejected)) { this.Model.AdditionalWork = results.Text; } else { await new MessageDialog("Sorry, I did not get that.").ShowAsync(); } } catch (Exception) { } }); this.AddCommand = new DelegateCommand(async() => { _addressDialog = new AddressDialog(this._locationService, this._eventAggregator, this.Address); this.Model.SelectedDestinationType = new DestinationType(); await _addressDialog.ShowAsync(); }); this.DetailCommand = new DelegateCommand(async() => { moreInfo = new DetailsDialog(); moreInfo.DataContext = this.SelectedTask; await moreInfo.ShowAsync(); }); this.SupplierFilterCommand = new DelegateCommand(async() => { sp = new SearchSupplierDialog(this._locationService, this._eventAggregator, this._supplierService); await sp.ShowAsync(); }); this._eventAggregator.GetEvent <AddressFilterEvent>().Subscribe((address) => { if (address != null) { this.Address = address; StringBuilder sb = new StringBuilder(); sb.Append(address.Street).Append(",").Append(Environment.NewLine); if ((address.SelectedSuburb != null) && !String.IsNullOrEmpty(address.SelectedSuburb.Name)) { sb.Append(address.SelectedSuburb.Name).Append(",").Append(Environment.NewLine); } if (address.SelectedRegion != null) { sb.Append(address.SelectedRegion.Name).Append(",").Append(Environment.NewLine); } if ((address.SelectedCity != null) && !String.IsNullOrEmpty(address.SelectedCity.Name)) { sb.Append(address.SelectedCity.Name).Append(",").Append(Environment.NewLine); } if ((address.Selectedprovince != null) && !String.IsNullOrEmpty(address.Selectedprovince.Name)) { sb.Append(address.Selectedprovince.Name).Append(",").Append(Environment.NewLine); } if ((address.SelectedCountry != null) && !String.IsNullOrEmpty(address.SelectedCountry.Name)) { sb.Append(address.SelectedCountry.Name).Append(",").Append(Environment.NewLine); } sb.Append(address.SelectedZip); this.Model.Address = sb.ToString(); } }); _eventAggregator.GetEvent <SupplierFilterEvent>().Subscribe(poolofSupplier => { this.PoolofSupplier = poolofSupplier; }); }
public async void Execute(object parameter) { if (parameter is Button button) { var parentNode = MainPageViewModel.CurrentInstance.GetNodeById(button.NodeId); var parsedParentNode = parentNode?.ToObject <ChatNode>(); //Special Case: Print OTP Section if (Utils.IsSectionTypePresentInNode(parentNode, SectionTypeEnum.PrintOTP)) { button.VariableValue = PrintOTPSection.OTP; } if (string.IsNullOrWhiteSpace(button.ButtonText)) { button.ButtonText = button.ButtonName; } var userData = new Dictionary <string, string>(); switch (button.ButtonType) { case ButtonTypeEnum.PostText: if (!button.Hidden && button.PostToChat) { ButtonActionHelper.HandlePostTextToThread(button.ButtonText); } break; case ButtonTypeEnum.OpenUrl: ButtonActionHelper.HandleOpenUrl(button.Url); break; case ButtonTypeEnum.GetText: if (string.IsNullOrWhiteSpace(button.VariableValue)) { return; } if (!Utils.IsValidTextButton(button)) { Utils.ShowDialog($"The text should not be empty and it should be between {button.MinLength} and {button.MaxLength}"); return; } ButtonActionHelper.HandleSaveTextInput(button.VariableName, button.VariableValue); userData[button.VariableName] = button.VariableValue; if (!button.Hidden && button.PostToChat) { ButtonActionHelper.HandlePostTextToThread(button.PrefixText + button.VariableValue + button.PostfixText); } break; case ButtonTypeEnum.GetEmail: if (string.IsNullOrWhiteSpace(button.VariableValue)) { return; } if (!Utils.IsValidEmail(button.VariableValue)) { Utils.ShowDialog("Invalid format"); return; } ButtonActionHelper.HandleSaveTextInput(button.VariableName, button.VariableValue); userData[button.VariableName] = button.VariableValue; if (!button.Hidden && button.PostToChat) { ButtonActionHelper.HandlePostTextToThread(button.PrefixText + button.VariableValue + button.PostfixText); } break; case ButtonTypeEnum.GetNumber: if (string.IsNullOrWhiteSpace(button.VariableValue)) { return; } double d; if (!double.TryParse(button.VariableValue, out d)) { Utils.ShowDialog("Invalid format"); return; } ButtonActionHelper.HandleSaveTextInput(button.VariableName, d.ToString()); userData[button.VariableName] = d.ToString(); if (!button.Hidden && button.PostToChat) { ButtonActionHelper.HandlePostTextToThread(button.PrefixText + d.ToString() + button.PostfixText); } break; case ButtonTypeEnum.GetPhoneNumber: if (string.IsNullOrWhiteSpace(button.VariableValue)) { return; } if (!Utils.IsValidPhoneNumber(button.VariableValue)) { Utils.ShowDialog("Invalid format"); return; } ButtonActionHelper.HandleSaveTextInput(button.VariableName, button.VariableValue); userData[button.VariableName] = button.VariableValue; if (!button.Hidden && button.PostToChat) { ButtonActionHelper.HandlePostTextToThread(button.PrefixText + button.VariableValue + button.PostfixText); } break; case ButtonTypeEnum.GetItemFromSource: var valueToSave = button.Items?.FirstOrDefault(x => x.Value == button.VariableValue); if (valueToSave?.Key == null && valueToSave?.Value == null) { Utils.ShowDialog("Invalid value"); return; } ButtonActionHelper.HandleSaveTextInput(button.VariableName, valueToSave?.Key); userData[button.VariableName] = valueToSave?.Key; if (!button.Hidden && button.PostToChat) { ButtonActionHelper.HandlePostTextToThread(button.PrefixText + button.VariableValue + button.PostfixText); } break; case ButtonTypeEnum.GetAddress: { bool done = false; while (!done) { var ad = new AddressDialog(); var res = await ad.ShowAsync(); switch (res) { case Windows.UI.Xaml.Controls.ContentDialogResult.Primary: if (Utils.ValidateStrings(ad.City, ad.PinCode, ad.Country, ad.Latitude == 0 ? "" : ad.Latitude.ToString(), ad.Longitude == 0 ? "" : ad.Longitude.ToString(), ad.StreetAddress)) { ButtonActionHelper.HandleSaveTextInput("CITY", ad.City); ButtonActionHelper.HandleSaveTextInput("COUNTRY", ad.Country); ButtonActionHelper.HandleSaveTextInput("PINCODE", ad.PinCode); ButtonActionHelper.HandleSaveTextInput("LAT", ad.Latitude.ToString()); ButtonActionHelper.HandleSaveTextInput("LNG", ad.Longitude.ToString()); ButtonActionHelper.HandleSaveTextInput("STREET_ADDRESS", ad.StreetAddress); #region User Data Fill userData["CITY"] = ad.City; userData["COUNTRY"] = ad.Country; userData["PINCODE"] = ad.PinCode; userData["LAT"] = ad.Latitude.ToString(); userData["LNG"] = ad.Longitude.ToString(); userData["STREET_ADDRESS"] = ad.StreetAddress; #endregion if (!button.Hidden && button.PostToChat) { ButtonActionHelper.HandlePostTextToThread($"{ad.StreetAddress}\r\n\r\nCity: {ad.City}\r\nCountry: {ad.Country}\r\nPin: {ad.PinCode}"); } done = true; } break; default: break; } if (!done) { await Utils.ShowDialogAsync("All fields in address are mandatory!"); } } } break; case ButtonTypeEnum.GetImage: case ButtonTypeEnum.GetFile: case ButtonTypeEnum.GetAudio: case ButtonTypeEnum.GetVideo: var mediaUrl = await ButtonActionHelper.HandleSaveMediaInputAsync(button.VariableName, button.ButtonType); if (string.IsNullOrWhiteSpace(mediaUrl)) { return; } userData[button.VariableName] = mediaUrl; ButtonActionHelper.HandlePostMediaToThread(mediaUrl, button.ButtonType); break; case ButtonTypeEnum.NextNode: if (!button.Hidden && button.PostToChat) { ButtonActionHelper.HandlePostTextToThread(button.ButtonText); } if (!string.IsNullOrWhiteSpace(button.VariableName) && button.VariableValue != null) //VariableValue should be != null only { ButtonActionHelper.HandleSaveTextInput(button.VariableName, button.VariableValue); } break; case ButtonTypeEnum.DeepLink: await ButtonActionHelper.HandleDeepLinkAsync(button.DeepLinkUrl); if (!button.Hidden && button.PostToChat) { ButtonActionHelper.HandlePostTextToThread(button.ButtonText); } break; case ButtonTypeEnum.GetAgent: await Utils.ShowDialogAsync("Agent chat not supported in simulator"); if (!button.Hidden && button.PostToChat) { ButtonActionHelper.HandlePostTextToThread(button.ButtonText); } break; case ButtonTypeEnum.FetchChatFlow: if (!button.Hidden && button.PostToChat) { ButtonActionHelper.HandlePostTextToThread(button.ButtonText); } if (!string.IsNullOrWhiteSpace(button.VariableName) && button.VariableValue != null) //VariableValue should be != null only { ButtonActionHelper.HandleSaveTextInput(button.VariableName, button.VariableValue); } await ButtonActionHelper.HandleFetchChatFlowAsync(button.Url); break; case ButtonTypeEnum.GetDate: { var cd = new DateTimePickerDialog() { IsDateVisible = true }; cd.Title = "Pick a date"; var res = await cd.ShowAsync(); if (res == UWPControls.ContentDialogResult.Primary) { button.VariableValue = cd.ChoosenDate.ToString("yyyy-MM-dd"); ButtonActionHelper.HandleSaveTextInput(button.VariableName, button.VariableValue); ButtonActionHelper.HandleSaveTextInput(button.VariableName + "_DISPLAY", cd.ChoosenDate.ToString("dd MMM, yyyy")); userData[button.VariableName] = button.VariableValue; if (!button.Hidden && button.PostToChat) { ButtonActionHelper.HandlePostTextToThread(button.VariableValue); } } else { return; } } break; case ButtonTypeEnum.GetDateTime: { var cd = new DateTimePickerDialog() { IsDateVisible = true, IsTimeVisible = true }; cd.Title = "Pick date time"; var res = await cd.ShowAsync(); if (res == UWPControls.ContentDialogResult.Primary) { DateTimeOffset dtLocal = cd.ChoosenDate.Date + cd.ChoosenTime; DateTime dtUTC = DateTime.Parse(dtLocal.ToString(), null, DateTimeStyles.AdjustToUniversal); button.VariableValue = JsonConvert.SerializeObject(dtUTC).Trim('"'); var display = dtLocal.ToString("dd MMM, yyyy hh:mm:ss tt"); ButtonActionHelper.HandleSaveTextInput(button.VariableName, button.VariableValue); ButtonActionHelper.HandleSaveTextInput(button.VariableName + "_DISPLAY", display); ButtonActionHelper.HandleSaveTextInput(button.VariableName + "_DISPLAY2", dtUTC.ToString("dd MMM, yyyy hh:mm:ss tt")); ButtonActionHelper.HandleSaveTextInput(button.VariableName + "_DISPLAY3", JsonConvert.SerializeObject(dtUTC).Trim('"')); userData[button.VariableName] = button.VariableValue; if (!button.Hidden && button.PostToChat) { ButtonActionHelper.HandlePostTextToThread(display); } } else { return; } } break; case ButtonTypeEnum.GetTime: { var cd = new DateTimePickerDialog() { IsTimeVisible = true }; cd.Title = "Pick time"; var res = await cd.ShowAsync(); if (res == UWPControls.ContentDialogResult.Primary) { button.VariableValue = JsonConvert.SerializeObject(cd.ChoosenTime).Trim('"'); var display = new DateTime(cd.ChoosenTime.Ticks).ToString("hh:mm tt"); ButtonActionHelper.HandleSaveTextInput(button.VariableName, button.VariableValue); ButtonActionHelper.HandleSaveTextInput(button.VariableName + "_DISPLAY", display); ButtonActionHelper.HandleSaveTextInput(button.VariableName + "_DISPLAY2", new DateTime(cd.ChoosenTime.Ticks).ToString("HH:mm")); userData[button.VariableName] = button.VariableValue; if (!button.Hidden && button.PostToChat) { ButtonActionHelper.HandlePostTextToThread(display); } } else { return; } } break; case ButtonTypeEnum.GetLocation: { var loc = await Utils.GetCurrentGeoLocation(); button.VariableValue = $"{(float)loc.Coordinate.Point.Position.Latitude},{(float)loc.Coordinate.Point.Position.Longitude}"; ButtonActionHelper.HandleSaveTextInput(button.VariableName, button.VariableValue); userData[button.VariableName] = button.VariableValue; if (!button.Hidden && button.PostToChat) { var mapUrl = $"https://maps.googleapis.com/maps/api/staticmap?center={button.VariableValue}&zoom=15&size=300x150&markers=color:red|label:A|{button.VariableValue}&key=" + Utils.Config.GoogleMapsAPIKey; ButtonActionHelper.HandlePostMediaToThread(mapUrl, ButtonTypeEnum.GetImage, button.VariableValue); } } break; default: Utils.ShowDialog($"Button type: {button.ButtonType} not supported"); break; } trackViewEvent(button, userData); ButtonActionHelper.NavigateToNode(button.NextNodeId); } else if (parameter is CarouselButton cButton) { var userData = new Dictionary <string, string>(); switch (cButton.Type) { case CardButtonType.NextNode: if (!string.IsNullOrWhiteSpace(cButton.VariableName) && cButton.VariableValue != null) //VariableValue should be != null only { ButtonActionHelper.HandleSaveTextInput(cButton.VariableName, cButton.VariableValue); userData[cButton.VariableName] = cButton.VariableValue; } break; case CardButtonType.DeepLink: await ButtonActionHelper.HandleDeepLinkAsync(cButton.Url); break; case CardButtonType.OpenUrl: ButtonActionHelper.HandleOpenUrl(cButton.Url); break; default: Utils.ShowDialog($"Button type: {cButton.Type} not supported"); break; } trackViewEvent(cButton, userData); ButtonActionHelper.NavigateToNode(cButton.NextNodeId); } }
public async void Execute(object parameter) { if (parameter is Button button) { var parentNode = MainPageViewModel.CurrentInstance.GetNodeById(button.NodeId); var parsedParentNode = parentNode?.ToObject <ChatNode>(); //Special Case: Print OTP Section if (Utils.IsSectionTypePresentInNode(parentNode, SectionTypeEnum.PrintOTP)) { button.VariableValue = PrintOTPSection.OTP; } var userData = new Dictionary <string, string>(); switch (button.ButtonType) { case ButtonTypeEnum.PostText: if (!button.Hidden && button.PostToChat) { ButtonActionHelper.HandlePostTextToThread(button.ButtonText); } break; case ButtonTypeEnum.OpenUrl: ButtonActionHelper.HandleOpenUrl(button.Url); break; case ButtonTypeEnum.GetText: if (string.IsNullOrWhiteSpace(button.VariableValue)) { return; } ButtonActionHelper.HandleSaveTextInput(button.VariableName, button.VariableValue); userData[button.VariableName] = button.VariableValue; if (!button.Hidden && button.PostToChat) { ButtonActionHelper.HandlePostTextToThread(button.PrefixText + button.VariableValue + button.PostfixText); } break; case ButtonTypeEnum.GetEmail: if (string.IsNullOrWhiteSpace(button.VariableValue)) { return; } if (!Utils.IsValidEmail(button.VariableValue)) { Utils.ShowDialog("Invalid format"); return; } ButtonActionHelper.HandleSaveTextInput(button.VariableName, button.VariableValue); userData[button.VariableName] = button.VariableValue; if (!button.Hidden && button.PostToChat) { ButtonActionHelper.HandlePostTextToThread(button.PrefixText + button.VariableValue + button.PostfixText); } break; case ButtonTypeEnum.GetNumber: if (string.IsNullOrWhiteSpace(button.VariableValue)) { return; } double d; if (!double.TryParse(button.VariableValue, out d)) { Utils.ShowDialog("Invalid format"); return; } ButtonActionHelper.HandleSaveTextInput(button.VariableName, d.ToString()); userData[button.VariableName] = d.ToString(); if (!button.Hidden && button.PostToChat) { ButtonActionHelper.HandlePostTextToThread(button.PrefixText + d.ToString() + button.PostfixText); } break; case ButtonTypeEnum.GetPhoneNumber: if (string.IsNullOrWhiteSpace(button.VariableValue)) { return; } if (!Utils.IsValidPhoneNumber(button.VariableValue)) { Utils.ShowDialog("Invalid format"); return; } ButtonActionHelper.HandleSaveTextInput(button.VariableName, button.VariableValue); userData[button.VariableName] = button.VariableValue; if (!button.Hidden && button.PostToChat) { ButtonActionHelper.HandlePostTextToThread(button.PrefixText + button.VariableValue + button.PostfixText); } break; case ButtonTypeEnum.GetItemFromSource: var valueToSave = button.Items?.FirstOrDefault(x => x.Value == button.VariableValue); if (valueToSave?.Key == null && valueToSave?.Value == null) { Utils.ShowDialog("Invalid value"); return; } ButtonActionHelper.HandleSaveTextInput(button.VariableName, valueToSave?.Key); userData[button.VariableName] = valueToSave?.Key; if (!button.Hidden && button.PostToChat) { ButtonActionHelper.HandlePostTextToThread(button.PrefixText + button.VariableValue + button.PostfixText); } break; case ButtonTypeEnum.GetAddress: { bool done = false; while (!done) { var ad = new AddressDialog(); var res = await ad.ShowAsync(); switch (res) { case Windows.UI.Xaml.Controls.ContentDialogResult.Primary: if (Utils.ValidateStrings(ad.City, ad.PinCode, ad.Country, ad.Latitude == 0 ? "" : ad.Latitude.ToString(), ad.Longitude == 0 ? "" : ad.Longitude.ToString(), ad.StreetAddress)) { ButtonActionHelper.HandleSaveTextInput("CITY", ad.City); ButtonActionHelper.HandleSaveTextInput("COUNTRY", ad.Country); ButtonActionHelper.HandleSaveTextInput("PINCODE", ad.PinCode); ButtonActionHelper.HandleSaveTextInput("LAT", ad.Latitude.ToString()); ButtonActionHelper.HandleSaveTextInput("LNG", ad.Longitude.ToString()); ButtonActionHelper.HandleSaveTextInput("STREET_ADDRESS", ad.StreetAddress); #region User Data Fill userData["CITY"] = ad.City; userData["COUNTRY"] = ad.Country; userData["PINCODE"] = ad.PinCode; userData["LAT"] = ad.Latitude.ToString(); userData["LNG"] = ad.Longitude.ToString(); userData["STREET_ADDRESS"] = ad.StreetAddress; #endregion if (!button.Hidden && button.PostToChat) { ButtonActionHelper.HandlePostTextToThread($"{ad.StreetAddress}\r\n\r\nCity: {ad.City}\r\nCountry: {ad.Country}\r\nPin: {ad.PinCode}"); } done = true; } break; default: break; } if (!done) { await Utils.ShowDialogAsync("All fields in address are mandatory!"); } } } break; case ButtonTypeEnum.GetImage: case ButtonTypeEnum.GetAudio: case ButtonTypeEnum.GetVideo: var mediaUrl = await ButtonActionHelper.HandleSaveMediaInputAsync(button.VariableName, button.ButtonType); userData[button.VariableName] = mediaUrl; ButtonActionHelper.HandlePostMediaToThread(mediaUrl, button.ButtonType); break; case ButtonTypeEnum.NextNode: if (!button.Hidden && button.PostToChat) { ButtonActionHelper.HandlePostTextToThread(button.ButtonText); } if (!string.IsNullOrWhiteSpace(button.VariableName) && button.VariableValue != null) //VariableValue should be != null only { ButtonActionHelper.HandleSaveTextInput(button.VariableName, button.VariableValue); } break; case ButtonTypeEnum.DeepLink: await ButtonActionHelper.HandleDeepLinkAsync(button.DeepLinkUrl); if (!button.Hidden && button.PostToChat) { ButtonActionHelper.HandlePostTextToThread(button.ButtonText); } break; case ButtonTypeEnum.GetAgent: if (MainPageViewModel.CurrentInstance != null) { MainPageViewModel.CurrentInstance.AgentChat(); } if (!button.Hidden && button.PostToChat) { ButtonActionHelper.HandlePostTextToThread(button.ButtonText); } break; case ButtonTypeEnum.FetchChatFlow: if (!button.Hidden && button.PostToChat) { ButtonActionHelper.HandlePostTextToThread(button.ButtonText); } if (!string.IsNullOrWhiteSpace(button.VariableName) && button.VariableValue != null) //VariableValue should be != null only { ButtonActionHelper.HandleSaveTextInput(button.VariableName, button.VariableValue); } await ButtonActionHelper.HandleFetchChatFlowAsync(button.Url); break; default: Utils.ShowDialog($"Button type: {button.ButtonType} not supported"); break; } trackViewEvent(button, userData); ButtonActionHelper.NavigateToNode(button.NextNodeId); } else if (parameter is CarouselButton cButton) { var userData = new Dictionary <string, string>(); switch (cButton.Type) { case CardButtonType.NextNode: if (!string.IsNullOrWhiteSpace(cButton.VariableName) && cButton.VariableValue != null) //VariableValue should be != null only { ButtonActionHelper.HandleSaveTextInput(cButton.VariableName, cButton.VariableValue); userData[cButton.VariableName] = cButton.VariableValue; } break; case CardButtonType.DeepLink: await ButtonActionHelper.HandleDeepLinkAsync(cButton.Url); break; case CardButtonType.OpenUrl: ButtonActionHelper.HandleOpenUrl(cButton.Url); break; default: Utils.ShowDialog($"Button type: {cButton.Type} not supported"); break; } trackViewEvent(cButton, userData); ButtonActionHelper.NavigateToNode(cButton.NextNodeId); } }