public async Task ProcessButtonsAsync(JToken node) { ClearButtonTimer(); var parsedNode = node.ToObject <ChatNode>(); if (parsedNode.Buttons == null || parsedNode.Buttons.Count == 0) { return; } ClearButtons(); var allButtons = node["Buttons"].ToObject <List <Button> >(); foreach (var btn in allButtons.Where(x => x.Kind == ButtonKind.ClickInput)) { btn.VariableName = node["VariableName"] + ""; btn.NodeId = parsedNode.Id; btn.ButtonName = VerbProcessor.Process(btn.ButtonName); btn.ButtonText = VerbProcessor.Process(btn.ButtonText); CurrentClickButtons.Add(btn); } foreach (var btn in allButtons.Where(x => x.Kind == ButtonKind.TextInput)) { btn.VariableName = node["VariableName"] + ""; btn.NodeId = parsedNode.Id; btn.ButtonName = VerbProcessor.Process(btn.ButtonName); btn.ButtonText = VerbProcessor.Process(btn.ButtonText); try { if (btn.ButtonType == ButtonTypeEnum.GetItemFromSource) { btn.ItemsSource = (await APIHelper.HitAsync <Dictionary <string, string> >(btn.Url)); btn.Items = btn.ItemsSource; } } catch { } CurrentTextInputButtons.Add(btn); } //Handling node timeout to default button var defaultBtn = allButtons.FirstOrDefault(x => x.DefaultButton); if (defaultBtn != null && parsedNode.TimeoutInMs > 0) { buttonTimeoutTimer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(parsedNode.TimeoutInMs) }; buttonTimeoutTimer.Tick += (s, e) => { ClearButtons(); defaultBtn.Action.Execute(defaultBtn); }; buttonTimeoutTimer.Start(); } }
public async Task ProcessButtonsAsync(JToken node) { ClearButtonTimer(); var parsedNode = node.ToObject <ChatNode>(); if (parsedNode.Buttons == null || parsedNode.Buttons.Count == 0) { return; } ClearButtons(); var allButtons = node["Buttons"].ToObject <List <Button> >(); foreach (var btnSrc in allButtons.Where(x => x.Kind == ButtonKind.ClickInput)) { if (string.IsNullOrWhiteSpace(btnSrc.ButtonName)) { btnSrc.ButtonName = btnSrc.ButtonText; } var btn = btnSrc.DeepCopy(); if (btn.DoesRepeat) { var repeatOn = ButtonActionHelper.GetSavedArray(btn.RepeatOn); if (repeatOn != null) { var max = btn.MaxRepeats == 0 ? repeatOn.Count - 1 : btn.MaxRepeats; for (int i = btn.StartPosition; i <= max; i++) { var b = btn.DeepCopy(); b.VariableName = node["VariableName"] + ""; b.NodeId = parsedNode.Id; ButtonActionHelper.ClearSavedValue(b.RepeatAs); ButtonActionHelper.HandleSaveTextInput(b.RepeatAs, repeatOn[i] + ""); b.ButtonName = VerbProcessor.Process(b.ButtonName, false); b.ButtonText = VerbProcessor.Process(b.ButtonText, false); if (btn.ButtonType == ButtonTypeEnum.GetText && !string.IsNullOrWhiteSpace(btn.DefaultText)) { btn.VariableValue = btn.DefaultText; } ButtonActionHelper.ClearSavedValue(b.RepeatAs); CurrentClickButtons.Add(b); } } } else { btn.VariableName = node["VariableName"] + ""; btn.NodeId = parsedNode.Id; if (btn.ButtonType == ButtonTypeEnum.GetText && !string.IsNullOrWhiteSpace(btn.DefaultText)) { btn.VariableValue = btn.DefaultText; } btn.ButtonName = VerbProcessor.Process(btn.ButtonName); btn.ButtonText = VerbProcessor.Process(btn.ButtonText); CurrentClickButtons.Add(btn); } } foreach (var btn in allButtons.Where(x => x.Kind == ButtonKind.TextInput)) { if (string.IsNullOrWhiteSpace(btn.ButtonName)) { btn.ButtonName = btn.ButtonText; } btn.VariableName = node["VariableName"] + ""; btn.NodeId = parsedNode.Id; btn.ButtonName = VerbProcessor.Process(btn.ButtonName); btn.ButtonText = VerbProcessor.Process(btn.ButtonText); try { if (btn.ButtonType == ButtonTypeEnum.GetItemFromSource) { btn.ItemsSource = (await APIHelper.HitAsync <Dictionary <string, string> >(btn.Url)); btn.Items = btn.ItemsSource; } } catch { #if DEBUG if (Debugger.IsAttached) { btn.ItemsSource = JsonConvert.DeserializeObject <Dictionary <string, string> >("{\r\n \"ADVERTISING & MARKETING SERVICES\": \"Advertising & Marketing Services\",\r\n \"AEROSPACE\": \"Aerospace\",\r\n \"ARCHITECTURE\": \"Architecture\",\r\n \"ARTS & CRAFTS\": \"Arts & Crafts\",\r\n \"AUTOMOTIVE\": \"Automotive\",\r\n \"BANK\": \"Bank\",\r\n \"BIOTECHNOLOGY\": \"Biotechnology\",\r\n \"BOOK STORE\": \"Book Store\",\r\n \"BLOGS\": \"Blogs\",\r\n \"BUSINESS SERVICES\": \"Business Services\",\r\n \"CARS\": \"Cars\",\r\n \"USED CARS\": \"Used Cars\",\r\n \"CARGO & LOGISTICS\": \"Cargo & Logistics\",\r\n \"CATERING\": \"Catering\",\r\n \"CHEMICALS\": \"Chemicals\",\r\n \"COLLEGE\": \"College\",\r\n \"COMMUNITY\": \"Community\",\r\n \"COMPUTERS\": \"Computers\",\r\n \"CONSTRUCTION MATERIAL\": \"Construction Material\",\r\n \"CONSULTANTS\": \"Consultants\",\r\n \"EDUCATION\": \"Education\",\r\n \"ELECTRONICS\": \"Electronics\",\r\n \"ENERGY\": \"Energy\",\r\n \"ENTERTAINMENT\": \"Entertainment\",\r\n \"EQUIPMENT\": \"Equipment\",\r\n \"EVENT PLANNING SERVICES\": \"Event Planning Services\",\r\n \"EVENTS\": \"Events\",\r\n \"EXPORTS\": \"Exports\",\r\n \"FASHION - APPAREL\": \"Fashion - Apparel\",\r\n \"FASHION - FOOTWEAR\": \"Fashion - Footwear\",\r\n \"F&B - BAKERY\": \"F&B - Bakery\",\r\n \"F&B - BARS\": \"F&B - Bars\",\r\n \"F&B - CAFE\": \"F&B - Cafe\",\r\n \"F&B - RESTAURANTS\": \"F&B - Restaurants\",\r\n \"FREELANCER\": \"Freelancer\",\r\n \"FLOWER SHOP\": \"Flower Shop\",\r\n \"FINANCIAL SERVICES\": \"Financial Services\",\r\n \"FURNITURE\": \"Furniture\",\r\n \"GENERAL SERVICES\": \"General Services\",\r\n \"GIFTS & NOVELTIES\": \"Gifts & Novelties\",\r\n \"GROCERY\": \"Grocery\",\r\n \"GAMING\": \"Gaming\",\r\n \"GARDEN\": \"Garden\",\r\n \"HOME FURNISHINGS\": \"Home Furnishings\",\r\n \"HEALTH & FITNESS\": \"Health & Fitness\",\r\n \"HOME APPLIANCES\": \"Home Appliances\",\r\n \"HARDWARE & SANITARY-WARE\": \"Hardware & Sanitary-Ware\",\r\n \"HOME MAINTENANCE\": \"Home Maintenance\",\r\n \"HOME CARE\": \"Home Care\",\r\n \"HOTEL & MOTELS\": \"Hotel & Motels\",\r\n \"HOSPITAL\": \"Hospital\",\r\n \"HYPERMARKET\": \"Hypermarket\",\r\n \"INSURANCE\": \"Insurance\",\r\n \"INTERIOR DESIGN\": \"Interior Design\",\r\n \"KINDER GARTEN\": \"Kinder Garten\",\r\n \"KIDS GOODS\": \"Kids Goods\",\r\n \"KITCHEN EQUIPMENT\": \"Kitchen Equipment\",\r\n \"LEGAL SERVICES\": \"Legal Services\",\r\n \"MANUFACTURERS\": \"Manufacturers\",\r\n \"MEDICAL - DENTAL\": \"Medical - Dental\",\r\n \"MEDICAL - GENERAL\": \"Medical - General\",\r\n \"MEDIA & NEWS\": \"Media & News\",\r\n \"MINING\": \"Mining\",\r\n \"NATURAL & AYURVEDA\": \"Natural & Ayurveda\",\r\n \"NON-PROFIT ORGANIZATION\": \"Non-Profit Organization\",\r\n \"OFFICE SUPPLIES\": \"Office Supplies\",\r\n \"OTHER RETAIL\": \"Other Retail\",\r\n \"OUTDOOR & SPORTING GOODS\": \"Outdoor & Sporting Goods\",\r\n \"PETS\": \"Pets\",\r\n \"PHOTOGRAPHY\": \"Photography\",\r\n \"POLITICAL ORGANIZATION\": \"Political Organization\",\r\n \"REAL ESTATE & CONSTRUCTION\": \"Real Estate & Construction\",\r\n \"RELIGIOUS ORGANIZATION\": \"Religious Organization\",\r\n \"SPA\": \"Spa\",\r\n \"SPORTS\": \"Sports\",\r\n \"SHOPPING COMPLEX\": \"Shopping Complex\",\r\n \"SOFTWARE\": \"Software\",\r\n \"SCIENCE & ENGINEERING\": \"Science & Engineering\",\r\n \"SECURITY\": \"Security\",\r\n \"TELECOMMUNICATION\": \"Telecommunication\",\r\n \"TOURISM\": \"Tourism\",\r\n \"TRADING\": \"Trading\",\r\n \"TRANSPORTATION SERVICE\": \"Transportation Service\",\r\n \"TRAINING INSTITUTES\": \"Training Institutes\",\r\n \"TUITIONS & COACHING\": \"Tuitions & Coaching\",\r\n \"WATCHES\": \"Watches\",\r\n \"WATCHES & JEWELRY\": \"Watches & Jewelry\"\r\n}"); btn.Items = btn.ItemsSource; } #endif } CurrentTextInputButtons.Add(btn); } //Handling node timeout to default button var defaultBtn = allButtons.FirstOrDefault(x => x.DefaultButton && !Utils.IGNORED_DEFAULT_BUTTONS.Contains(x.ButtonType)); if (defaultBtn != null && parsedNode.TimeoutInMs >= 0) { buttonTimeoutTimer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(parsedNode.TimeoutInMs) }; buttonTimeoutTimer.Tick += (s, e) => { ClearButtonTimer(); defaultBtn.VariableName = node["VariableName"] + ""; defaultBtn.NodeId = parsedNode.Id; defaultBtn.ButtonName = VerbProcessor.Process(defaultBtn.ButtonName); defaultBtn.ButtonText = VerbProcessor.Process(defaultBtn.ButtonText); defaultBtn.Action.Execute(defaultBtn); }; buttonTimeoutTimer.Start(); } }