private IEnumerable <ResponseMessage> HandleSendUpdate(IncomingMessage incomingMessage) { if (incomingMessage.ChannelType != ResponseType.DirectMessage || !incomingMessage.RawText.ToLower().StartsWith("sendupdate:")) { yield break; } var updateJson = incomingMessage.RawText.Substring("sendupdate:".Length); var update = JObject.Parse(updateJson).ToObject <SendUpdate>(); var authenticated = IsPinValid(update.Pin, incomingMessage); if (!authenticated) { yield return(incomingMessage.ReplyDirectlyToUser("You're not authorized to do this punk")); yield break; } var subscriptions = UpdateSubscriptions.Where((subscription, i) => string.IsNullOrEmpty(subscription.Event) || subscription.Event == update.Event); var channelUpdateMessage = $"*{update.Title}(_{update.Event}_)*{Environment.NewLine}{update.Message}{Environment.NewLine}@channel"; yield return(ResponseMessage.ChannelMessage("CDFGJ40Q5", channelUpdateMessage, (Attachment)null)); var updates = new List <ResponseMessage>(); var tasks = subscriptions.Select((subscription, i) => { var template = subscription.WebhookUrl .Replace("{event}", "{0}") .Replace("{title}", "{1}") .Replace("{message}", "{2}"); var url = String.Format(template, update.Event, update.Title, update.Message); var request = new HttpRequestMessage(HttpMethod.Get, url); updates.Add(incomingMessage.ReplyDirectlyToUser($"Sending update to {url}")); return(_httpClient.SendAsync(request)); }); foreach (var responseMessage in updates) { yield return(responseMessage); } updates = Task.WhenAll(tasks).Result.Select(message => { return(incomingMessage.ReplyDirectlyToUser( $"{(message.IsSuccessStatusCode ? "Success" : "Failure")}: {message.RequestMessage.RequestUri}")); }).ToList(); foreach (var responseMessage in updates) { yield return(responseMessage); } }
private ResponseMessage HandleKarmaChange(IncomingMessage message, ChangeRequest changeRequest) { try { _karmaRepositoryPlugin.Update(changeRequest); var currentKarma = _karmaRepositoryPlugin.Get(changeRequest.Name); return(message.ReplyToChannel(_karmaPlugin.GenerateCurrentKarmaMessage(changeRequest, currentKarma))); } catch (Exception e) { return(ResponseMessage.ChannelMessage("bots", e.Message + "\n" + e.StackTrace, new List <Attachment>())); } }
/// <summary> /// Will generate a message to be sent the current channel the message arrived from /// </summary> public ResponseMessage ReplyToChannel(string text, Attachment attachment = null) { if (attachment == null) { return(ResponseMessage.ChannelMessage(this.Channel, text, attachments: null)); } var attachments = new List <Attachment> { attachment }; return(this.ReplyToChannel(text, attachments)); }
private IEnumerable <ResponseMessage> RespondIfLinkFound(IncomingMessage arg1, IValidHandle arg2) { var textToSend = arg1.RawText.Replace("say", ""); var channel = "testss"; // default var regexed = RegexHelper.FindChannelName(arg1.RawText); if (!string.IsNullOrEmpty(regexed)) { channel = regexed; } textToSend = RegexHelper.RemoveChannel(textToSend); textToSend = RegexHelper.RemoveUser(textToSend); yield return(ResponseMessage.ChannelMessage(channel, $"{textToSend}", new List <Attachment>())); }
/// <summary> /// Will generate a message to be sent the current channel the message arrived from /// </summary> public ResponseMessage ReplyToChannel(string text, Attachment attachment = null) { return(ResponseMessage.ChannelMessage(Channel, text, attachment)); }
/// <summary> /// Will display on Slack that the bot is typing on the current channel. Good for letting the end users know the bot is doing something. /// </summary> public ResponseMessage IndicateTypingOnChannel() { return(ResponseMessage.ChannelMessage(Channel, string.Empty, null, new TypingIndicatorMessage())); }
/// <summary> /// Will display on Slack that the bot is typing on the current channel. Good for letting the end users know the bot is doing something. /// </summary> public ResponseMessage IndicateTypingOnChannel() { return(ResponseMessage.ChannelMessage(this.Channel, string.Empty, attachments: null, message: new TypingIndicatorMessage())); }
/// <summary> /// Will generate a message to be sent the current channel the message arrived from /// </summary> public ResponseMessage ReplyToChannel(string text, List <Attachment> attachments) { return(ResponseMessage.ChannelMessage(this.Channel, text, attachments)); }
public ResponseMessage UploadToChannel(Stream stream, string fileName) { return(ResponseMessage.ChannelMessage(Channel, string.Empty, attachment: null, message: new UploadMessage(stream, fileName))); }
public ResponseMessage UploadToChannel(string filePath) { return(ResponseMessage.ChannelMessage(Channel, string.Empty, attachment: null, message: new UploadMessage(filePath))); }
private static ResponseMessage RespondToBotsChannel(string message) { return(ResponseMessage.ChannelMessage("bottests", message, new List <Attachment>())); }