public void CanParseChannelCreatedMessage() { var bot = m_Mock; var parser = new SlackMessageHandler(bot.Object, "bot-id"); parser.Handle("{ \"type\": \"channel_created\", \"channel\": { \"id\": \"C024BE91L\", \"name\": \"fun\", \"created\": 1360782804, \"creator\": \"U024BE7LH\" } }"); bot.Verify(x => x.ChannelCreated("C024BE91L", "fun", "U024BE7LH")); }
public void CanParseHelloMessage() { var bot = m_Mock; var parser = new SlackMessageHandler(bot.Object, "user-id"); parser.Handle("{ \"type\": \"hello\" }"); bot.Verify(x => x.Hello()); }
public void IgnoresMessagesFromBots() { var bot = m_Mock; var parser = new SlackMessageHandler(bot.Object, "bot-id"); parser.Handle("{\"type\":\"message\",\"subtype\":\"bot_message\",\"channel\":\"D03JWF44C\",\"user\":\"U03JU40UP\",\"text\":\"this is a test\",\"ts\":\"1423514301.000002\",\"team\":\"T03JU3JV5\"}"); bot.Verify(x => x.Message(It.IsAny <Message>()), Times.Never); }
public void CanParseBasicMessage() { var bot = m_Mock; var parser = new SlackMessageHandler(bot.Object, "user-id"); var json = "{\"type\":\"message\",\"channel\":\"D03JWF44C\",\"user\":\"U03JU40UP\",\"text\":\"this is a test\",\"ts\":\"1423514301.000002\",\"team\":\"T03JU3JV5\"}"; parser.Handle(json); bot.Verify(x => x.Message(new Message("D03JWF44C", "U03JU40UP", "this is a test"))); }
public void CanParseUnknownMessage() { var bot = m_Mock; var parser = new SlackMessageHandler(bot.Object, "user-id"); var json = "{ \"type\": \"a never-before seen message type\" }"; parser.Handle(json); bot.Verify(x => x.Unknown(json)); }
public async void CanTestApi() { var slackApi = new SlackApi(m_Configuration.Get("slack-api-key")); using (var rtm = await slackApi.StartRtm()) { var handler = new SlackMessageHandler(new LoggingBot(), rtm.InstanceInfo.BotId); while (true) { var message = await rtm.Receive(new CancellationToken()); handler.Handle(message); } } }
private static void MainLoop(ISlackRealTimeMessaging slackRtm, SlackMessageHandler handler, SlackApi slackApi, CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { var nextMessage = slackRtm.Receive(cancellationToken); while (!nextMessage.Wait(TimeSpan.FromSeconds(10))) { var tickResult = handler.HandleTimerTick(); Console.Write("."); DoResponse(slackApi, tickResult, cancellationToken); } var messageResult = handler.Handle(nextMessage.Result); DoResponse(slackApi, messageResult, cancellationToken); } }
public static async Task MainAsync(Configuration configuration, CancellationToken cancel) { var persistence = new JsonFileKeyValueStore(new FileInfo(configuration.Get("db-file-location"))); var gamesPersistence = new JsonFileKeyValueStore(new FileInfo(configuration.Get("games-db-location"))); var slackApi = new SlackApi(configuration.Get("slack-api-key")); var slackRtm = await(ReconnectingSlackRealTimeMessaging.CreateAsync( async() => await slackApi.StartRtm())); var aliasList = GetAliasList(slackRtm.InstanceInfo.Users); var commandParser = new SlackCommandParser("scbot", slackRtm.InstanceInfo.BotId); var webClient = new WebClient(); var features = new FeatureMessageProcessor(commandParser, NoteProcessor.Create(commandParser, persistence), //ZendeskTicketTracker.Create(commandParser, persistence, configuration), RecordReplayTraceManagement.Create(commandParser), SeatingPlans.Create(commandParser, webClient), Webcams.Create(commandParser, configuration), Silly.Create(commandParser, webClient), Installers.Create(commandParser, webClient), Polls.Create(commandParser), RollBuildNumbers.Create(commandParser, configuration), ReviewFactory.Create(commandParser, webClient, configuration), LabelPrinting.Create(commandParser, webClient, configuration), Jira.Create(commandParser), CompareTeamEmails.Create(commandParser, configuration), GamesProcessor.Create(commandParser, gamesPersistence, aliasList) ); var pasteBin = new HasteServerPasteBin(webClient, configuration.Get("haste-server-url")); var newChannelNotificationsChannel = configuration.GetWithDefault("new-channels-notification-channel", null); var newChannelProcessor = GetNewChannelProcessor(newChannelNotificationsChannel); var bot = new Bot( new ErrorReportingMessageProcessor( new ConcattingMessageProcessor(features), pasteBin), newChannelProcessor); var handler = new SlackMessageHandler(bot, slackRtm.InstanceInfo.BotId); MainLoop(slackRtm, handler, slackApi, cancel); }