public async Task StartAsync(IDialogContext context) { var message = context.Activity as IMessageActivity; var query = FootballQuery.Parse(message.Value); await context.PostAsync($"Ok. Searching for the LiveScore Between {query.Team1} and {query.Team2} "); try { await SearchLivescore(context, query); } catch (FormCanceledException ex) { await context.PostAsync($"Oops! Something went wrong :( Technical Details: {ex.InnerException.Message}"); } }
public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> result) { var message = await result; if (message.Value != null) { // Got an Action Submit dynamic value = message.Value; string submitType = value.Type.ToString(); switch (submitType) { case "leagueSearch": FootballQuery query1; try { query1 = FootballQuery.Parse(value); // Trigger validation using Data Annotations attributes from the FootballsQuery model List <ValidationResult> results = new List <ValidationResult>(); bool valid = Validator.TryValidateObject(query1, new ValidationContext(query1, null, null), results, true); if (!valid) { // Some field in the Football Query are not valid var errors = string.Join("\n", results.Select(o => " - " + o.ErrorMessage)); await context.PostAsync("Please complete all the search parameters:\n" + errors); return; } } catch (InvalidCastException) { // Football Query could not be parsed await context.PostAsync("Please complete all the search parameters"); return; } // Proceed with Footballs search await context.Forward(new LeagueDialog(), this.ResumeAfterOptionDialog, message, CancellationToken.None); return; case "leagueSelection": await SendFootballSelectionAsync(context, (League)JsonConvert.DeserializeObject <League>(value.ToString())); context.Wait(MessageReceivedAsync); return; case "LivescoreSearch": FootballQuery query2; try { query2 = FootballQuery.Parse(value); // Trigger validation using Data Annotations attributes from the FootballsQuery model List <ValidationResult> results = new List <ValidationResult>(); bool valid = Validator.TryValidateObject(query2, new ValidationContext(query2, null, null), results, true); if (!valid) { // Some field in the Football Query are not valid var errors = string.Join("\n", results.Select(o => " - " + o.ErrorMessage)); await context.PostAsync("Please complete all the search parameters:\n" + errors); return; } } catch (InvalidCastException) { // Football Query could not be parsed await context.PostAsync("Please complete all the search parameters"); return; } // Proceed with Livescore search await context.Forward(new LivescoreDialog(), this.ResumeAfterOptionDialog, message, CancellationToken.None); return; } } if (message.Text != null && (message.Text.ToLower().Contains("help") || message.Text.ToLower().Contains("support") || message.Text.ToLower().Contains("problem"))) { await context.Forward(new SupportDialog(), this.ResumeAfterSupportDialog, message, CancellationToken.None); } else { await ShowOptionsAsync(context); } }