public async Task Connect()
        {
            SlackSocketClient.Connect((loginResponse =>
            {
                if (loginResponse.ok)
                {
                    Logger.LogInformation("Socket client responded ok");
                }
                else
                {
                    Logger.LogError($"SlackSocketClient Error: {loginResponse.error}");
                }
            }), () =>
                                      Logger.LogInformation("Socket connected"));
            SlackSocketClient.OnMessageReceived += message =>
            {
                Logger.LogInformation(JsonConvert.SerializeObject(message));
            };
            SlackSocketClient.OnReactionAdded += reaction =>
            {
                Logger.LogInformation(JsonConvert.SerializeObject(reaction));
            };
            await SlackTaskClient.ConnectAsync();

            var response = await SlackTaskClient.PostMessageAsync("#sandbox", "Hi", "I'm a bot");

            if (!response.ok)
            {
                Logger.LogError($"Post Message Error: {response.error}");
            }

            Logger.LogInformation("Connected");
        }
Beispiel #2
0
        public async Task Connect()
        {
            _timeout = _slackConfiguration.Value.Timeout;

            _actualClient = new SlackTaskClient(_slackConfiguration.Value.Token);
            var loginResponse = await _actualClient.ConnectAsync();

            if (loginResponse.ok)
            {
                _log.LogInformation("Connection to slack established.");
            }
            else
            {
                throw new InvalidOperationException(loginResponse.error);
            }

//            _actualClient.OnHello += () => { _log.LogInformation("Slack -- hello"); };
//
//            _actualClient.OnMessageReceived += message =>
//            {
//                _log.LogDebug("Slack message received: {slackMessage}", message);
//            };
//
//            _actualClient.OnReactionAdded += added =>
//            {
//                _log.LogDebug("Slack message received: {slackReaction}", added);
//            };
//
//            _actualClient.OnPongReceived += pong => { _log.LogDebug("Slack pong received: {pong}", pong); };
        }
Beispiel #3
0
        public static async Task <bool> VerifyToken(string userToken)
        {
            SlackTaskClient slackTaskClient = new SlackTaskClient(userToken);
            LoginResponse   response        = await slackTaskClient.ConnectAsync();

            return(response.ok);
        }
Beispiel #4
0
        public async Task <List <Models.Channel> > GetChannels(DateTime messagesOlderThan)
        {
            List <Models.Channel> ChannelList = new List <Models.Channel>();
            LoginResponse         res         = await SlackClient.ConnectAsync();

            ChannelList.AddRange(await GetPrivateChannels(res.groups, messagesOlderThan));
            ChannelList.AddRange(await GetPublicChannels(res.channels, messagesOlderThan));
            ChannelList.AddRange(await GetDirectMessageChannels(res.ims, res.users, messagesOlderThan));

            return(ChannelList);
        }