예제 #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);
            }
        }
예제 #2
0
        public override Task Run()
        {
            if (!_isConfigured)
            {
                throw new AdapterNotConfiguredException();
            }
            Logger.Info(string.Format("Logging into Slack"));

            if (_api == null)
            {
                _api = new SlackAPI(_token);
            }

            if (!(Robot.Router is NullRouter))
                Robot.Router.Post("/Slack/slack-command", (Action<OwinContext>)HandleSlackCommand);

            return ConnectSocket();
        }
예제 #3
0
        public override Task Run()
        {
            if (!_isConfigured)
            {
                throw new AdapterNotConfiguredException();
            }
            Logger.Info(string.Format("Logging into Slack"));

            if (_api == null)
            {
                _api = new SlackAPI(_token);
            }

            if (!(Robot.Router is NullRouter))
            {
                Robot.Router.Post("/Slack/slack-command", (Action <OwinContext>)HandleSlackCommand);
            }

            return(ConnectSocket());
        }