/// <summary> /// Asynchronously processes a message. /// </summary> /// <param name="slack">The slack.</param> /// <param name="message">The message.</param> /// <param name="cancellationToken">A token to monitor for cancellation requests. The default value is <see cref="System.Threading.CancellationToken.None" />.</param> /// <returns> /// A <see cref="Task{ChatMessageSinkResult}" /> that represents the asynchronous process operation. /// </returns> public async Task <ChatMessageSinkResult> ProcessMessageAsync(ISlack slack, Message message, CancellationToken cancellationToken = default(CancellationToken)) { if (_witClient == null) { throw new InvalidOperationException("WorkItem Client is null"); } await Task.Delay(0); var attachments = new List <Attachment>(); var matches = Pattern.Matches(message.Text); foreach (var id in matches.OfType <Match>().Where(x => x.Success).Select(x => x.Groups["id"]).Where(x => x.Success).Select(x => x.Value)) { WorkItem wi; try { // todo: get all at once wi = await _witClient.GetWorkItemAsync(XmlConvert.ToInt32(id)); } catch (VssServiceException ex) { // Ignore items that don't exist // "TF401232: Work item 1 does not exist, or you do not have permissions to read it." if (ex.Message.StartsWith("TF401232:")) { await slack.SendAsync(message.CreateReply(string.Format("WorkItem {0} not found", id))); return(ChatMessageSinkResult.Complete); } throw; } attachments.Add(WorkItemToAttachment(wi)); } if (attachments.Any()) { await slack.SendAsync(message.CreateReply("", attachments)); return(ChatMessageSinkResult.Complete); } return(ChatMessageSinkResult.Continue); }
/// <summary> /// Asynchronously processes a message. /// </summary> /// <param name="slack">The slack.</param> /// <param name="message">The message.</param> /// <param name="cancellationToken">A token to monitor for cancellation requests. The default value is <see cref="System.Threading.CancellationToken.None" />.</param> /// <returns> /// A <see cref="Task{ChatMessageSinkResult}" /> that represents the asynchronous process operation. /// </returns> public async Task<ChatMessageSinkResult> ProcessMessageAsync(ISlack slack, Message message, CancellationToken cancellationToken = default(CancellationToken)) { if (_witClient == null) { throw new InvalidOperationException("WorkItem Client is null"); } await Task.Delay(0); var attachments = new List<Attachment>(); var matches = Pattern.Matches(message.Text); foreach (var id in matches.OfType<Match>().Where(x => x.Success).Select(x => x.Groups["id"]).Where(x => x.Success).Select(x => x.Value)) { WorkItem wi; try { // todo: get all at once wi = await _witClient.GetWorkItemAsync(XmlConvert.ToInt32(id)); } catch (VssServiceException ex) { // Ignore items that don't exist // "TF401232: Work item 1 does not exist, or you do not have permissions to read it." if (ex.Message.StartsWith("TF401232:")) { await slack.SendAsync(message.CreateReply(string.Format("WorkItem {0} not found", id))); return ChatMessageSinkResult.Complete; } throw; } attachments.Add(WorkItemToAttachment(wi)); } if (attachments.Any()) { await slack.SendAsync(message.CreateReply("", attachments)); return ChatMessageSinkResult.Complete; } return ChatMessageSinkResult.Continue; }
/// <summary> /// Asynchronously processes a message. /// </summary> /// <param name="slack">The slack.</param> /// <param name="message">The message.</param> /// <param name="cancellationToken">A token to monitor for cancellation requests. The default value is <see cref="System.Threading.CancellationToken.None" />.</param> /// <returns> /// A <see cref="Task{ChatMessageSinkResult}" /> that represents the asynchronous process operation. /// </returns> public async Task <ChatMessageSinkResult> ProcessMessageAsync( ISlack slack, Message message, CancellationToken cancellationToken = default(CancellationToken)) { if (_witClient == null) { throw new InvalidOperationException("WorkItem Client is null"); } var attachments = new List <Attachment>(); var matches = Pattern.Matches(message.Text); foreach (var id in matches.OfType <Match>() .Where(x => x.Success) .Select(x => x.Groups["id"]) .Where(x => x.Success) .Select(x => x.Value)) { WorkItem wi; try { // todo: get all at once wi = await _witClient.GetWorkItemAsync(XmlConvert.ToInt32(id)); } catch (VssServiceException ex) { // Ignore items that don't exist // "TF401232: Work item 1 does not exist, or you do not have permissions to read it." if (ex.Message.StartsWith("TF401232:")) { await slack.SendAsync(message.CreateReply(string.Format("WorkItem {0} not found", id))); return(ChatMessageSinkResult.Complete); } throw; } attachments.Add(WorkItemToAttachment(wi)); } //Check for !searchtfs command - you can comment this out if you don't want it if (searchString != "" && !attachments.Any() && message.Text.Contains(searchString)) { string searchParam = message.Text.Replace(searchString, "").Trim(); var query = new Wiql(); if (int.TryParse(searchParam, out var id)) { query.Query = $"select * from WorkItems where [System.TeamProject]='{projectName}' " + $"and [System.Id] = {id}"; } else { var dt = DateTime.Today.AddMonths(-3).ToString(CultureInfo.InvariantCulture); query.Query = $"select * from WorkItems where [System.TeamProject]='{projectName}' " + $"and [System.CreatedDate] > '{dt}' " + $"and ([System.Title] Contains '{searchParam}' " + $"or [System.AssignedTo] Contains '{searchParam}')"; } var w = await _witClient.QueryByWiqlAsync(query).ConfigureAwait(false); foreach (var w2 in w.WorkItems) { var wi = await _witClient.GetWorkItemAsync(w2.Id).ConfigureAwait(false); var wiType = GetField(wi, "System.WorkItemType"); attachments.Add(WorkItemToAttachment(wi)); } } if (attachments.Any()) { await slack.SendAsync(message.CreateReply("", attachments)).ConfigureAwait(false); return(ChatMessageSinkResult.Complete); } await slack.SendAsync(message.CreateReply("I'm bored. Let's drink!")).ConfigureAwait(false); return(ChatMessageSinkResult.Continue); }
/// <summary> /// Asynchronously processes a message. /// </summary> /// <param name="slack">The slack.</param> /// <param name="message">The message.</param> /// <param name="cancellationToken">A token to monitor for cancellation requests. The default value is <see cref="System.Threading.CancellationToken.None" />.</param> /// <returns> /// A <see cref="Task{ChatMessageSinkResult}" /> that represents the asynchronous process operation. /// </returns> public async Task <ChatMessageSinkResult> ProcessMessageAsync(ISlack slack, Message message, CancellationToken cancellationToken = default(CancellationToken)) { if (_witClient == null) { throw new InvalidOperationException("WorkItem Client is null"); } await Task.Delay(0); var attachments = new List <Attachment>(); var matches = Pattern.Matches(message.Text); foreach (var id in matches.OfType <Match>().Where(x => x.Success).Select(x => x.Groups["id"]).Where(x => x.Success).Select(x => x.Value)) { WorkItem wi; try { // todo: get all at once wi = await _witClient.GetWorkItemAsync(XmlConvert.ToInt32(id)); } catch (VssServiceException ex) { // Ignore items that don't exist // "TF401232: Work item 1 does not exist, or you do not have permissions to read it." if (ex.Message.StartsWith("TF401232:")) { await slack.SendAsync(message.CreateReply(string.Format("WorkItem {0} not found", id))); return(ChatMessageSinkResult.Complete); } throw; } attachments.Add(WorkItemToAttachment(wi)); } //Check for !searchtfs command - you can comment this out if you don't want it if (searchString != "" && attachments.Count() == 0 && message.Text.Contains(searchString)) { string searchParam = message.Text.Replace(searchString, "").Trim(); //This query is whatever you want WorkItemQueryResult w = await _witClient.QueryByIdAsync(new TeamContext("Projects"), new Guid(workItemQueryGuid)); WorkItem wi; foreach (WorkItemLink w2 in w.WorkItemRelations) { wi = await _witClient.GetWorkItemAsync(w2.Target.Id); var wiType = GetField(wi, "System.WorkItemType"); if ((wiType == "Bug" || wiType == "Product Backlog Item") && WorkItemMatchesSearch(wi, searchParam)) { attachments.Add(WorkItemToAttachment(wi)); } } } if (attachments.Any()) { await slack.SendAsync(message.CreateReply("", attachments)); return(ChatMessageSinkResult.Complete); } return(ChatMessageSinkResult.Continue); }
public GameAPIController(ISlack slackService) { _slackService = slackService; }
public HomeController(ISlack slackService) { _slackService = slackService; }