Exemple #1
0
        private void InternalSend(string destination, AdapterArguments adapterArgs, string[] messages)
        {
            var room = destination;

            var channel = _rooms.FirstOrDefault(r => StringComparer.InvariantCultureIgnoreCase.Equals(r.Id, room) ||
                                                StringComparer.InvariantCultureIgnoreCase.Equals(r.Name, room));

            if (channel != null)
            {
                room = channel.Id;
                //EnsureBotInRoom(channel);

                if (!channel.IsMember)
                {
                    // Currently bots cannot self enter a room.
                    // Instead we'll just log for now.
                    Logger.ErrorFormat("Bots cannot join rooms. Invite bot into room {0}({1})", channel.Id, channel.Name);
                    return;
                }
            }

            var im = _ims.FirstOrDefault(i => StringComparer.InvariantCultureIgnoreCase.Equals(i.Id, room) ||
                                         StringComparer.InvariantCultureIgnoreCase.Equals(i.User, room));

            if (im != null)
            {
                room = im.Id;
                EnsureBotInRoom(im);
            }

            var user = _users.FirstOrDefault(u => StringComparer.InvariantCultureIgnoreCase.Equals(u.Id, room) ||
                                             StringComparer.InvariantCultureIgnoreCase.Equals(u.Name, room));

            if (user != null)
            {
                var response = _api.ImOpen(user.Id);
                if (!response.Ok)
                {
                    Logger.ErrorFormat("Could not join im channel {0} ({1})", user.Id, response.Error);
                    return;
                }
                room = response.Channel;
                im   = new Im()
                {
                    Id = response.Channel, User = user.Id, IsOpen = true
                };
                _ims.Add(im);
            }

            Logger.DebugFormat("Trying to send message to room {0}({1})", room, destination);

            foreach (var message in messages)
            {
                SlackAPI.Send(_socket, room, message);
            }
        }
Exemple #2
0
        private void EnsureBotInRoom(Im directMessage)
        {
            if (directMessage.IsOpen)
            {
                return;
            }

            var response = _api.ImOpen(directMessage.User);

            if (!response.Ok)
            {
                Logger.ErrorFormat("Could not join im channel {0} ({1})", directMessage.User, response.Error);
                return;
            }

            directMessage.IsOpen = true;
        }
Exemple #3
0
        private void InternalSend(string destination, AdapterArguments adapterArgs, string[] messages)
        {
            var room = destination;

            var channel = _rooms.FirstOrDefault(r => StringComparer.InvariantCultureIgnoreCase.Equals(r.Id, room) ||
                StringComparer.InvariantCultureIgnoreCase.Equals(r.Name, room));

            if (channel != null)
            {
                room = channel.Id;
                //EnsureBotInRoom(channel);

                if (!channel.IsMember)
                {
                    // Currently bots cannot self enter a room.
                    // Instead we'll just log for now.
                    Logger.ErrorFormat("Bots cannot join rooms. Invite bot into room {0}({1})", channel.Id, channel.Name);
                    return;
                }
            }

            var im = _ims.FirstOrDefault(i => StringComparer.InvariantCultureIgnoreCase.Equals(i.Id, room) ||
                StringComparer.InvariantCultureIgnoreCase.Equals(i.User, room));

            if (im != null)
            {
                room = im.Id;
                EnsureBotInRoom(im);
            }

            var user = _users.FirstOrDefault(u => StringComparer.InvariantCultureIgnoreCase.Equals(u.Id, room) ||
                StringComparer.InvariantCultureIgnoreCase.Equals(u.Name, room));

            if (user != null)
            {
                var response = _api.ImOpen(user.Id);
                if (!response.Ok)
                {
                    Logger.ErrorFormat("Could not join im channel {0} ({1})", user.Id, response.Error);
                    return;
                }
                room = response.Channel;
                im = new Im() { Id = response.Channel, User = user.Id, IsOpen = true };
                _ims.Add(im);
            }

            Logger.DebugFormat("Trying to send message to room {0}({1})", room, destination);

            foreach (var message in messages)
            {
                SlackAPI.Send(_socket, room, message);
            }
        }
Exemple #4
0
        private void EnsureBotInRoom(Im directMessage)
        {
            if (directMessage.IsOpen)
                return;

            var response = _api.ImOpen(directMessage.User);

            if (!response.Ok)
            {
                Logger.ErrorFormat("Could not join im channel {0} ({1})", directMessage.User, response.Error);
                return;
            }

            directMessage.IsOpen = true;
        }