private void should_return_standard_message(MessageInterpreter interpreter)
        {
            // given
            string json = @"
                {
                  'type': 'message',
                  'channel': '<myChannel>',
                  'user': '******',
                  'text': 'hi, my name is <noobot>',
                  'ts': '1445366603.000002',
                  'team': '<myTeam>'
                }
            ";

            // when
            var result = interpreter.InterpretMessage(json);

            // then
            var expected = new ChatMessage
            {
                MessageType = MessageType.Message,
                Channel     = "<myChannel>",
                User        = "******",
                Text        = "hi, my name is <noobot>",
                Team        = "<myTeam>",
                RawData     = json,
                Timestamp   = 1445366603.000002
            };

            result.ShouldLookLike(expected);
        }
        private void should_return_channel_joined_message(MessageInterpreter interpreter)
        {
            // given
            string json = @"
                {
                  'type': 'channel_joined',
                  'channel': {
                    id: 'test-channel',
                    is_channel: true
                  }
                }
            ";

            // when
            var result = interpreter.InterpretMessage(json);

            // then
            var expected = new ChannelJoinedMessage
            {
                MessageType = MessageType.Channel_Joined,
                Channel     = new Channel
                {
                    Id        = "test-channel",
                    IsChannel = true
                },
                RawData = json,
            };

            result.ShouldLookLike(expected);
        }
        private void should_return_message_given_standard_message_with_null_data(MessageInterpreter interpreter)
        {
            // given
            string json = @"
                {
                  'type': 'message',
                  'channel': null,
                  'user': null,
                  'text': null,
                  'ts': '1445366603.000002',
                  'team': null
                }
            ";

            // when
            var result = interpreter.InterpretMessage(json);

            // then
            var expected = new ChatMessage
            {
                MessageType = MessageType.Message,
                Channel     = null,
                User        = null,
                Text        = null,
                Team        = null,
                RawData     = json,
                Timestamp   = 1445366603.000002
            };

            result.ShouldLookLike(expected);
        }
        private void should_return_group_joined_message(MessageInterpreter interpreter)
        {
            // given
            string json = @"
                {
                  'type': 'group_joined',
                  'channel': {
                    id: 'test-group',
                    is_group: true
                  }
                }
            ";

            // when
            var result = interpreter.InterpretMessage(json);

            // then
            var expected = new GroupJoinedMessage
            {
                MessageType = MessageType.Group_Joined,
                Channel     = new Group
                {
                    Id      = "test-group",
                    IsGroup = true
                },
                RawData = json,
            };

            result.ShouldLookLike(expected);
        }
Example #5
0
        private void should_return_channel_created_message(MessageInterpreter interpreter)
        {
            // given
            string json = @"
                {
                    'type': 'channel_created',
                    'channel': {
                        'id': 'C024BE91L',
                        'name': 'fun',
                        'created': 1360782804,
                        'creator': 'U024BE7LH'
                    }
                }
            ";

            // when
            var result = interpreter.InterpretMessage(json);

            // then
            var expected = new ChannelCreatedMessage
            {
                MessageType = MessageType.Channel_Created,
                Channel     = new Channel
                {
                    Id      = "C024BE91L",
                    Name    = "fun",
                    Creator = "U024BE7LH"
                },
                RawData = json,
            };

            result.ShouldLookLike(expected);
        }
        private void should_return_dm_channel_joined_message(MessageInterpreter interpreter)
        {
            // given
            string json = @"
                {
                   'type':'im_created',
                   'channel':{
                      'id':'D99999',
                      'user':'******',
                      'is_im':true,
                      'is_open':true
                   }
                }
            ";

            // when
            var result = interpreter.InterpretMessage(json);

            // then
            var expected = new DmChannelJoinedMessage
            {
                MessageType = MessageType.Im_Created,
                Channel     = new Im
                {
                    Id     = "D99999",
                    User   = "******",
                    IsIm   = true,
                    IsOpen = true
                },
                RawData = json,
            };

            result.ShouldLookLike(expected);
        }
Example #7
0
        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);
        }
 public void TestListRequest()
 {
     Assert.AreEqual(MessageType.ListCameras,
                     interpreter.InterpretMessage(CreateActivity("list")));
     Assert.AreEqual(MessageType.ListCameras,
                     interpreter.InterpretMessage(CreateActivity("LIST!!!")));
     Assert.AreEqual(MessageType.ListCameras,
                     interpreter.InterpretMessage((CreateActivity("show me a List of cameras"))));
 }
        private void should_return_unknown_message_given_dodge_json(MessageInterpreter interpreter)
        {
            // given
            string json = @"{ 'type': 'something_else', 'channel': { 'isObject': true } }";

            // when
            var result = interpreter.InterpretMessage(json);

            // then
            result.ShouldBeOfType <UnknownMessage>();
        }
        private void should_log_when_logging_level_is_all([Frozen] Mock <ILogger> logger, MessageInterpreter interpreter)
        {
            // given
            SlackConnector.LoggingLevel = ConsoleLoggingLevel.All;

            // when
            var result = interpreter.InterpretMessage(@"{ 'something': 'no end tag'");

            // then
            result.ShouldBeOfType <UnknownMessage>();
            logger.Verify(x => x.LogError(It.IsAny <string>()), Times.AtLeastOnce);
        }
        private void shouldnt_log_when_logging_level_is_non([Frozen] Mock <ILogger> logger, MessageInterpreter interpreter)
        {
            // given
            SlackConnector.LoggingLevel = ConsoleLoggingLevel.None;

            // when
            var result = interpreter.InterpretMessage(null);

            // then
            result.ShouldBeOfType <UnknownMessage>();
            logger.Verify(x => x.LogError(It.IsAny <string>()), Times.Never);
        }
        private void should_return_unknown_message_type(MessageInterpreter interpreter)
        {
            // given
            string json = @"{ 'type': 'something_else' }";

            // when
            var result = interpreter.InterpretMessage(json);

            // then
            var expected = new UnknownMessage
            {
                RawData = json
            };

            result.ShouldLookLike(expected);
        }
        private void should_return_user_joined_message(MessageInterpreter interpreter)
        {
            // given
            string json = @"
                {  
                   'type':'team_join',
                   'user':{  
                      'id':'U3339999',
                      'name':'tmp',
                      'profile':{  
                         'real_name':'temp-name'
                      },
                      'is_admin':false,
                      'is_bot':true
                   }
                }
            ";

            // when
            var result = interpreter.InterpretMessage(json);

            // then
            var expected = new UserJoinedMessage
            {
                MessageType = MessageType.Team_Join,
                User        = new User
                {
                    Id      = "U3339999",
                    Name    = "tmp",
                    IsAdmin = false,
                    IsBot   = true,
                    Profile = new Profile
                    {
                        RealName = "temp-name"
                    }
                },
                RawData = json,
            };

            result.ShouldLookLike(expected);
        }
Example #14
0
        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);
        }
Example #15
0
        private void should_return_pong_message(MessageInterpreter interpreter)
        {
            // given
            string json = @"
                {
                  'type': 'pong',
                  'ts': '1445366603.000002'
                }
            ";

            // when
            var result = interpreter.InterpretMessage(json);

            // then
            var expected = new PongMessage
            {
                MessageType = MessageType.Pong,
                RawData     = json
            };

            result.ShouldLookLike(expected);
        }
Example #16
0
        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);
        }
Example #17
0
        /// <summary>
        /// POST: api/Messages
        /// Receive a message from a user and reply to it
        /// </summary>
        public async Task <HttpResponseMessage> Post([FromBody] Activity activity)
        {
            if (activity.Type == ActivityTypes.Message)
            {
                logger.Info("ChannelId: " + activity.ChannelId + ";Query: " + activity.Text);
                var connector = new ConnectorClient(new Uri(activity.ServiceUrl));
                var userData  = new UserData(activity);

                var cameraData = GetCameraDataService(userData);

                string cameraName  = null;
                var    messageType = messageInterpreter.InterpretMessage(activity);

                int choice;
                var previousChoiceList = userData.GetChoiceList();
                if (previousChoiceList != null && int.TryParse(activity.Text, out choice) && choice >= 1 && choice <= previousChoiceList.CameraNames.Count)
                {
                    logger.Debug("Replying to choice selection");
                    // First see if the user is responding to a choice list.
                    // Note that we're 1-indexing for purposes of talking to the user.
                    cameraName = previousChoiceList.CameraNames[choice - 1];
                    await ReplyWithCameraLookup(activity, connector, userData, cameraData, cameraName);
                }
                else if (messageType == MessageType.PointlessChatter)
                {
                    logger.Debug("Replying with something equally pointless");
                    await connector.Conversations.ReplyToActivityAsync(
                        new PointlessPhraseReplyActivityBuilder(cameraData)
                        .BuildReplyActivity(activity, userData));
                }
                else if (messageType == MessageType.ListCameras)
                {
                    logger.Debug("Replying with list-cameras");
                    await connector.Conversations.ReplyToActivityAsync(
                        new CameraListReplyActivityBuilder(cameraData.ListCameras())
                        .BuildReplyActivity(activity, userData));
                }
                else if (messageType == MessageType.HelpRequest)
                {
                    logger.Debug("Replying with help");
                    await connector.Conversations.ReplyToActivityAsync(
                        new HelpReplyActivityBuilder()
                        .BuildReplyActivity(activity, userData));
                }
                else if (messageType == MessageType.SelectCity)
                {
                    logger.Debug("Replying to city change");
                    await connector.Conversations.ReplyToActivityAsync(
                        new SelectCityReplyActivityBuilder(cameraDataServiceManager)
                        .BuildReplyActivity(activity, userData));
                }
                else
                {
                    // Otherwise just look up the text they gave us.
                    cameraName = activity.Text;
                    logger.Debug("Replying to query: " + cameraName);
                    await ReplyWithCameraLookup(activity, connector, userData, cameraData, cameraName);
                }
            }
            else
            {
                HandleSystemMessage(activity);
            }

            var response = Request.CreateResponse(HttpStatusCode.OK);

            return(response);
        }
        private void should_return_message_with_file(MessageInterpreter interpreter)
        {
            // given
            string json = @"
                {
                  'type': 'message',
                  'files': [
                     {
                      'id':'some-id',
                      'created':12345,
                      'timestamp':54321,
                      'name':'name.gif',
                      'title':'title.gif',
                      'mimetype':'image\/gif',
                      'filetype':'gif',
                      'pretty_type':'GIF',
                      'user':'******',
                      'editable':true,
                      'size':63689,
                      'mode':'hosted',
                      'is_external':true,
                      'external_type':'some-external-type',
                      'is_public':true,
                      'public_url_shared':true,
                      'display_as_bot':true,
                      'username':'******',
                      'url_private':'https:\/\/url_private',
                      'url_private_download':'https:\/\/url_private_download',
                      'thumb_64':'https:\/\/thumb_64',
                      'thumb_80':'https:\/\/thumb_80',
                      'thumb_360':'https:\/\/thumb_360',
                      'thumb_360_w':43,
                      'thumb_360_h':29,
                      'thumb_160':'https:\/\/thumb_160',
                      'thumb_360_gif':'https:\/\/thumb_360_gif',
                      'image_exif_rotation':6,
                      'original_w':53,
                      'original_h':39,
                      'deanimate_gif':'https:\/\/deanimate_gif',
                      'permalink':'https:\/\/permalink',
                      'permalink_public':'https:\/\/permalink_public'
                   }]
                }
            ";

            // when
            var result = interpreter.InterpretMessage(json);

            // then
            var expected = new ChatMessage
            {
                MessageType = MessageType.Message,
                Files       = new[]
                {
                    new File
                    {
                        Id                 = "some-id",
                        Created            = 12345,
                        Timestamp          = 54321,
                        Name               = "name.gif",
                        Title              = "title.gif",
                        Mimetype           = "image/gif",
                        FileType           = "gif",
                        PrettyType         = "GIF",
                        User               = "******",
                        Editable           = true,
                        Size               = 63689,
                        Mode               = "hosted",
                        IsExternal         = true,
                        ExternalType       = "some-external-type",
                        IsPublic           = true,
                        PublicUrlShared    = true,
                        DisplayAsBot       = true,
                        Username           = "******",
                        UrlPrivate         = "https://url_private",
                        UrlPrivateDownload = "https://url_private_download",
                        Thumb64            = "https://thumb_64",
                        Thumb80            = "https://thumb_80",
                        Thumb360           = "https://thumb_360",
                        Thumb360Width      = 43,
                        Thumb360Height     = 29,
                        Thumb160           = "https://thumb_160",
                        Thumb360Gif        = "https://thumb_360_gif",
                        ImageExifRotation  = 6,
                        OriginalWidth      = 53,
                        OriginalHeight     = 39,
                        DeanimateGif       = "https://deanimate_gif",
                        Permalink          = "https://permalink",
                        PermalinkPublic    = "https://permalink_public"
                    }
                },
                RawData = json
            };

            result.ShouldLookLike(expected);
        }