private void FetchData() { using (var syncClient = new InSync($"{nameof(SlackFixture.FetchData)} - Connected callback")) { this.UserClient.GetUserList(list => { Console.WriteLine($"Slack users retrieved. Total: {list?.members?.Length}"); this.Users = list?.members?.ToDictionary(x => x.id, x => x); }); syncClient.Proceed(); } }
/// <summary>Sends the confirmation response.</summary> /// <param name="sender">The Slack sender.</param> /// <param name="originalMessage">The original message.</param> private void SendConfirmationResponse(User sender, IEnumerable <string> receivers, int kudosCount) { var slackBot = slackFixture.BotClient; var message = GenerateConfirmMessage(sender, receivers, kudosCount); using (var syncDirectJoint = new InSync("JoinDirectMessageChannel")) { slackBot.JoinDirectMessageChannel(response => { using (var syncPosting = new InSync("DirectMessagePosting")) { slackBot.PostMessage(response => { syncPosting.Proceed(); }, response.channel?.id, message); } syncDirectJoint.Proceed(); }, sender.id); } }
public SlackSocketClient CreateClient(string authToken, IWebProxy proxySettings = null, bool maintainPresenceChanges = false, Action <SlackSocketClient, PresenceChange> presenceChanged = null) { SlackSocketClient client; LoginResponse loginResponse = null; using (var syncClient = new InSync($"{nameof(SlackAPI.SlackClient.Connect)} - Connected callback")) using (var syncClientSocket = new InSync($"{nameof(SlackAPI.SlackClient.Connect)} - SocketConnected callback")) using (var syncClientSocketHello = new InSync($"{nameof(SlackAPI.SlackClient.Connect)} - SocketConnected hello callback")) { client = new SlackSocketClient(authToken, proxySettings, maintainPresenceChanges); void OnPresenceChanged(PresenceChange x) { presenceChanged?.Invoke(client, x); } client.OnPresenceChanged += OnPresenceChanged; client.OnHello += () => syncClientSocketHello.Proceed(); client.Connect(x => { loginResponse = x; Console.WriteLine($"Connected {x.ok}"); syncClient.Proceed(); if (!x.ok) { // If connect fails, socket connect callback is not called syncClientSocket.Proceed(); syncClientSocketHello.Proceed(); } }, () => { Console.WriteLine("Socket Connected"); syncClientSocket.Proceed(); }); } return(client); }
/// <summary>Sends the inform messages.</summary> /// <param name="sender">The Slack sender.</param> /// <param name="originalMessage">The original message.</param> private void SendInformMessages(User sender, IEnumerable <string> receiverSlackIds, int kudosCount) { var slackBot = slackFixture.BotClient; var messages = GenerateInformMessages(sender, receiverSlackIds, kudosCount); foreach ((var receiver, var message) in messages) { using (var syncDirectJoint = new InSync($"JoinDirectMessageChannel - {receiver}")) { slackBot.JoinDirectMessageChannel(response => { using (var syncPosting = new InSync($"DirectMessagePosting - {receiver}")) { slackBot.PostMessage(response => { syncPosting.Proceed(); }, response.channel?.id, message); } syncDirectJoint.Proceed(); }, receiver); } } }