private async Task should_raise_file_comment_reaction_event( Mock <IWebSocketClient> webSocket, SlackConnection slackConnection) { // given var fixture = new Fixture(); var connectionInfo = new ConnectionInformation { Users = { { "some-user", new SlackUser { Id = "some-user", Name = "i-have-a-name" } }, { "another-user", new SlackUser { Id = "another-user", Name = "i-have-a-name-too-thanks" } } }, WebSocket = webSocket.Object }; await slackConnection.Initialise(connectionInfo); ISlackReaction lastReaction = null; slackConnection.OnReaction += reaction => { lastReaction = reaction; return(Task.CompletedTask); }; var file = fixture.Create <string>(); var fileComment = fixture.Create <string>(); var inboundMessage = new ReactionMessage { User = "******", Reaction = fixture.Create <string>(), RawData = fixture.Create <string>(), ReactingToUser = "******", Timestamp = fixture.Create <double>(), ReactingTo = new FileCommentReaction { File = file, FileComment = fileComment } }; // when webSocket.Raise(x => x.OnMessage += null, null, inboundMessage); // then lastReaction.ShouldLookLike(new SlackFileCommentReaction { User = connectionInfo.Users["some-user"], Reaction = inboundMessage.Reaction, File = file, FileComment = fileComment, RawData = inboundMessage.RawData, ReactingToUser = connectionInfo.Users["another-user"], Timestamp = inboundMessage.Timestamp }); }
private async Task should_raise_message_reaction_event( Mock <IWebSocketClient> webSocket, SlackConnection slackConnection) { // given var fixture = new Fixture(); var connectionInfo = new ConnectionInformation { Users = { { "userABC", new SlackUser { Id = "userABC", Name = "i-have-a-name" } }, { "secondUser", new SlackUser { Id = "secondUser", Name = "i-have-a-name-too-thanks" } } }, SlackChatHubs = new Dictionary <string, SlackChatHub> { { "chat-hub-1", new SlackChatHub() } }, WebSocket = webSocket.Object }; await slackConnection.Initialise(connectionInfo); ISlackReaction lastReaction = null; slackConnection.OnReaction += reaction => { lastReaction = reaction; return(Task.CompletedTask); }; var inboundMessage = new ReactionMessage { User = "******", Reaction = fixture.Create <string>(), RawData = fixture.Create <string>(), ReactingToUser = "******", Timestamp = fixture.Create <double>(), ReactingTo = new MessageReaction { Channel = "chat-hub-1" } }; // when webSocket.Raise(x => x.OnMessage += null, null, inboundMessage); // then lastReaction.ShouldLookLike(new SlackMessageReaction { User = connectionInfo.Users["userABC"], Reaction = inboundMessage.Reaction, RawData = inboundMessage.RawData, ChatHub = connectionInfo.SlackChatHubs["chat-hub-1"], ReactingToUser = connectionInfo.Users["secondUser"], Timestamp = inboundMessage.Timestamp }); }
private void should_return_unknown_reaction_message(MessageInterpreter interpreter) { // given string json = @" { 'type': 'reaction_added', 'user': '******', 'reaction': 'thumbsup', 'item_user': '******', 'item': { 'type': 'nifty_new_slack_reaction', 'item1': 'Fc0HS2KBEZ', 'item2': 'F0HS27V1Z', }, 'event_ts': '1360782804.083113' } "; // when var result = interpreter.InterpretMessage(json); // then var expected = new ReactionMessage { MessageType = MessageType.Reaction_Added, RawData = json, Reaction = "thumbsup", User = "******", Timestamp = 1360782804.083113, ReactingToUser = "******", ReactingTo = new UnknownReaction() }; result.ShouldLookLike(expected); }
private void should_return_file_comment_reaction_message(MessageInterpreter interpreter) { // given string json = @" { 'type': 'reaction_added', 'user': '******', 'reaction': 'thumbsup', 'item_user': '******', 'item': { 'type': 'file_comment', 'file_comment': 'Fc0HS2KBEZ', 'file': 'F0HS27V1Z', }, 'event_ts': '1360782804.083113' } "; // when var result = interpreter.InterpretMessage(json); // then var expected = new ReactionMessage { MessageType = MessageType.Reaction_Added, RawData = json, Reaction = "thumbsup", User = "******", Timestamp = 1360782804.083113, ReactingToUser = "******", ReactingTo = new FileCommentReaction { File = "F0HS27V1Z", FileComment = "Fc0HS2KBEZ" }, }; result.ShouldLookLike(expected); }
public static void CreateCustomReactionMessage( ulong userId, IUserMessage message, CustomReactionAction defaultAction, bool allowMultipleReactions = false, bool anyoneCanInteract = false, int timeout = 300000, Action onTimeout = null ) { var reactionMessage = new ReactionMessage(userId, message, defaultAction, allowMultipleReactions, anyoneCanInteract); ReactionMessageCache.Add( message.Id.ToString(), reactionMessage, new CacheItemPolicy { SlidingExpiration = TimeSpan.FromMilliseconds(timeout), RemovedCallback = onTimeout == null ? null : (CacheEntryRemovedCallback)(_ => onTimeout()) } ); }
private void should_return_message_reaction_message(MessageInterpreter interpreter) { // given string json = @" { 'type': 'reaction_added', 'user': '******', 'reaction': 'thumbsup', 'item_user': '******', 'item': { 'type': 'message', 'channel': 'C0G9QF9GZ', 'ts': '1360782400.498405' }, 'event_ts': '1360782804.083113' } "; // when var result = interpreter.InterpretMessage(json); // then var expected = new ReactionMessage { MessageType = MessageType.Reaction_Added, RawData = json, Reaction = "thumbsup", User = "******", Timestamp = 1360782804.083113, ReactingToUser = "******", ReactingTo = new MessageReaction { Channel = "C0G9QF9GZ", Timestamp = "1360782400.498405" } }; result.ShouldLookLike(expected); }
public void Register(IUserMessage message, EventAction subscribed, EventHandler <ReactionEventArgs> callback, string state = null, bool doSave = true) { var msg = new ReactionMessage() { Message = message, State = state, Added = DateTime.UtcNow, Events = subscribed, Save = doSave }; if (doSave) { msg.Method = new ReactionMethod(callback.Method); } else { msg.Method = new ReactionMethod(callback); } messages[message.Id] = msg; Console.WriteLine($"Registered: {messages.Count}, {message.Id}"); }
private Task HandleReaction(ReactionMessage inboundMessage) { if (string.IsNullOrEmpty(inboundMessage.User)) { return(Task.CompletedTask); } if (!string.IsNullOrEmpty(this.Self.Id) && inboundMessage.User == this.Self.Id) { return(Task.CompletedTask); } if (inboundMessage.ReactingTo is MessageReaction messageReaction) { //TODO: Interface methods? Extension methods? return(this.RaiseReactionReceived( new SlackMessageReaction { User = this.GetMessageUser(inboundMessage.User), Timestamp = inboundMessage.Timestamp, ChatHub = this.GetChatHub(messageReaction.Channel), RawData = inboundMessage.RawData, Reaction = inboundMessage.Reaction, ReactingToUser = this.GetMessageUser(inboundMessage.ReactingToUser) })); } if (inboundMessage.ReactingTo is FileReaction fileReaction) { return(this.RaiseReactionReceived( new SlackFileReaction { User = this.GetMessageUser(inboundMessage.User), Timestamp = inboundMessage.Timestamp, File = fileReaction.File, RawData = inboundMessage.RawData, Reaction = inboundMessage.Reaction, ReactingToUser = this.GetMessageUser(inboundMessage.ReactingToUser) })); } if (inboundMessage.ReactingTo is FileCommentReaction fileCommentReaction) { return(this.RaiseReactionReceived( new SlackFileCommentReaction { User = this.GetMessageUser(inboundMessage.User), Timestamp = inboundMessage.Timestamp, File = fileCommentReaction.File, FileComment = fileCommentReaction.FileComment, RawData = inboundMessage.RawData, Reaction = inboundMessage.Reaction, ReactingToUser = this.GetMessageUser(inboundMessage.ReactingToUser) })); } return(this.RaiseReactionReceived( new SlackUnknownReaction { User = this.GetMessageUser(inboundMessage.User), Timestamp = inboundMessage.Timestamp, RawData = inboundMessage.RawData, Reaction = inboundMessage.Reaction, ReactingToUser = this.GetMessageUser(inboundMessage.ReactingToUser) })); }