static void Main(string[] args) { ISlackBot slackBot = Slacker.CreateSlackBot(); slackBot.Start(); MessageEvent message; while (true) { message = slackBot.ReadMessage(); Console.WriteLine("`````````````````"); Console.WriteLine($"type: {message.Type}"); Console.WriteLine($"user: {message.User?.ID}"); Console.WriteLine($"channel: {message.Channel?.Id}"); Console.WriteLine($"text: {message.Text}"); Console.WriteLine($"timestamp: {message.Timestamp}"); if (SlackUtils.MessageToMe(message)) { Command command = ProcessCommand(message.Text); slackBot.SendMessage(new MessageEvent { Channel = message.Channel, Type = EventTypes.Message, Text = $"{message.User.Name} gave command <{command.Operation}> with arguments {JoinArgs(command.Args)}" }); } Thread.Sleep(1000); } }
public SlackResponseDoc MarkAnswerIncorrect(SlackRequestDoc requestDoc, string target) { string userId = SlackUtils.NormalizeId(target); try { _workflowService.OnIncorrectAnswerSelected(requestDoc.ChannelId, requestDoc.UserId, userId); } catch (GameNotStartedException e) { return(SlackResponseDoc.Failure(String.Format(GAME_NOT_STARTED_FORMAT, requestDoc.Command))); } catch (WorkflowException e) { return(SlackResponseDoc.Failure(e.Message)); } SlackResponseDoc delayedResponseDoc = new SlackResponseDoc { ResponseType = SlackResponseType.IN_CHANNEL, Text = String.Format("You couldn't be more wrong, <@{0}>", userId) }; _delayedSlackService.sendResponse(requestDoc.ResponseUrl, delayedResponseDoc); return(new SlackResponseDoc { ResponseType = SlackResponseType.EPHEMERAL, Text = "Marked answer incorrect." }); }
internal static MessageEvent ToMessageContract(this Dictionary <string, object> msg) { var channel = SlackUtils.GetChannel(msg); var user = SlackUtils.GetUserSender(msg); return(new MessageEvent { Type = msg.GetValueByKey("type"), Channel = channel, User = user, Text = msg.GetValueByKey("text"), Timestamp = msg.GetValueByKey("ts").ToDateTime() }); }
public object SkyLogError(string errorMsg) { HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*"); //string referrer = Request.UrlReferrer(); string fErrorMsg = HttpContext.Current.Server.UrlDecode(errorMsg); if (bool.Parse(ConfigurationManager.AppSettings.Get("skyViewLoggingActivateSlack"))) { if (!string.IsNullOrWhiteSpace(fErrorMsg)) { SlackUtils.SendMsgToChannel(fErrorMsg, true); } } return(true); }
public SlackResponseDoc Pass(SlackRequestDoc requestDoc, string target) { string userId = SlackUtils.NormalizeId(target); try { bool userExists = _scoreService.DoesUserExist(requestDoc.ChannelId, userId); if (!userExists) { SlackResponseDoc responseDoc = SlackResponseDoc.Failure("User " + target + " does not exist. Please choose a valid user."); responseDoc.Attachments = new List <SlackAttachment> { new SlackAttachment("Usage: `" + requestDoc.Command + " pass @jsmith`") }; return(responseDoc); } _workflowService.OnTurnChanged(requestDoc.ChannelId, requestDoc.UserId, userId); } catch (GameNotStartedException) { return(SlackResponseDoc.Failure(String.Format(GAME_NOT_STARTED_FORMAT, requestDoc.Command))); } catch (WorkflowException e) { return(SlackResponseDoc.Failure(e.Message)); } SlackResponseDoc delayedResponseDoc = new SlackResponseDoc { ResponseType = SlackResponseType.IN_CHANNEL, Text = String.Format("<@{0}> has decided to pass his/her turn to <@{1}>.\n\nOK, <@{1}>, it's your turn to ask a question!", requestDoc.UserId, userId) }; _delayedSlackService.sendResponse(requestDoc.ResponseUrl, delayedResponseDoc); return(new SlackResponseDoc { ResponseType = SlackResponseType.EPHEMERAL, Text = "Turn passed to <@" + userId + ">." }); }
public SlackResponseDoc MarkAnswerCorrect(SlackRequestDoc requestDoc, string target, string answer) { string text; try { _workflowService.OnCorrectAnswerSelected(requestDoc.ChannelId, requestDoc.UserId); if (target.Equals(NO_CORRECT_ANSWER_TARGET, StringComparison.InvariantCultureIgnoreCase)) { //"Change" back to the original host to reset the workflow state _workflowService.OnTurnChanged(requestDoc.ChannelId, requestDoc.UserId, requestDoc.UserId); if (answer == null) { text = String.Format( "It looks like no one was able to answer that one!\n\n{0}\n\nOK, <@{1}>, let's try another one!", generateScoreText(requestDoc), requestDoc.UserId ); } else { text = String.Format( "It looks like no one was able to answer that one! The correct answer was {0}.\n\n{1}\n\nOK, <@{2}>, let's try another one!", answer, generateScoreText(requestDoc), requestDoc.UserId ); } } else { string userId = SlackUtils.NormalizeId(target); _scoreService.IncrementScore(requestDoc.ChannelId, userId); _workflowService.OnTurnChanged(requestDoc.ChannelId, requestDoc.UserId, userId); if (answer == null) { text = String.Format( "<@{1}> is correct!\n\n{0}\n\nOK, <@{1}>, you're up!", generateScoreText(requestDoc), userId ); } else { text = String.Format( "<@{2}> is correct with {0}!\n\n{1}\n\nOK, <@{2}>, you're up!", answer, generateScoreText(requestDoc), userId ); } } } catch (GameNotStartedException) { return(SlackResponseDoc.Failure(String.Format(GAME_NOT_STARTED_FORMAT, requestDoc.Command))); } catch (WorkflowException e) { return(SlackResponseDoc.Failure(e.Message)); } catch (ScoreException) { SlackResponseDoc responseDoc = SlackResponseDoc.Failure("User " + target + " does not exist. Please choose a valid user."); responseDoc.Attachments = new List <SlackAttachment> { new SlackAttachment("Usage: `" + requestDoc.Command + " correct @jsmith Blue skies`") }; return(responseDoc); } SlackResponseDoc delayedResponseDoc = new SlackResponseDoc { ResponseType = SlackResponseType.IN_CHANNEL, Text = text }; _delayedSlackService.sendResponse(requestDoc.ResponseUrl, delayedResponseDoc); return(new SlackResponseDoc { ResponseType = SlackResponseType.EPHEMERAL, Text = "Score updated." }); }
public void TestNormalizeIdWithNullSlackId() { Assert.IsNull(SlackUtils.NormalizeId(null)); }
public void TestNormalizeIdWithValidSlackIdAndEmptyUsername() { Assert.AreEqual("U12345", SlackUtils.NormalizeId("<@U12345|>")); }
public void TestNormalizeIdWithValidSlackId() { Assert.AreEqual("U12345", SlackUtils.NormalizeId("<@U12345>")); }
public void TestNormalizeIdWithInvalidSlackId() { Assert.AreEqual("garbage", SlackUtils.NormalizeId("garbage")); }