From 9ffcff808d3acd8216f7ed055ff64b12401ac736 Mon Sep 17 00:00:00 2001 From: mbellas-tkxs Date: Wed, 20 Nov 2019 10:04:09 -0500 Subject: [PATCH 1/2] add async methods --- SlackAPI.sln | 9 +- SlackAPI/SlackClient.cs | 518 +++++++++++++++++++++++++++++----- SlackAPI/SlackClientBase.cs | 4 + SlackAPI/SlackSocketClient.cs | 6 +- 4 files changed, 471 insertions(+), 66 deletions(-) diff --git a/SlackAPI.sln b/SlackAPI.sln index 77a33f6..ca63a91 100644 --- a/SlackAPI.sln +++ b/SlackAPI.sln @@ -1,12 +1,17 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26228.4 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.28803.352 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlackAPI", "SlackAPI\SlackAPI.csproj", "{7EED3D9B-9B7A-49A4-AFBF-599153A47DDA}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlackAPI.Tests", "SlackAPI.Tests\SlackAPI.Tests.csproj", "{DEFA9559-0F8F-4C38-9644-67A080EDC46D}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{EB677ECE-F93F-4AEE-BA65-10720D4F0602}" + ProjectSection(SolutionItems) = preProject + .gitattributes = .gitattributes + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/SlackAPI/SlackClient.cs b/SlackAPI/SlackClient.cs index 51f7112..c7b3c39 100644 --- a/SlackAPI/SlackClient.cs +++ b/SlackAPI/SlackClient.cs @@ -7,6 +7,7 @@ using System.Net.Http; using System.Text; using SlackAPI.RPCMessages; +using System.Threading.Tasks; namespace SlackAPI { @@ -48,7 +49,7 @@ public SlackClient(string token, IWebProxy proxySettings) APIToken = token; } - public virtual void Connect(Action onConnected = null, Action onSocketConnected = null) + public virtual void Connect(Action onConnected = null, Action onSocketConnected = null) { EmitLogin((loginDetails) => { @@ -118,19 +119,47 @@ public void APIRequestWithToken(Action callback, params Tuple[0]); } + public Task APIRequestWithTokenAsync(params Tuple[] getParameters) + where K : Response + { + Tuple[] tokenArray = new Tuple[]{ + new Tuple("token", APIToken) + }; + + if (getParameters != null && getParameters.Length > 0) + tokenArray = tokenArray.Concat(getParameters).ToArray(); + + return APIRequestAsync(tokenArray, new Tuple[0]); + } + public void TestAuth(Action callback) { APIRequestWithToken(callback); } + public Task TestAuthAsync() + { + return APIRequestWithTokenAsync(); + } public void GetUserList(Action callback) { APIRequestWithToken(callback); } - public void ChannelsCreate(Action callback, string name) { - APIRequestWithToken(callback, new Tuple("name", name)); - } + public Task GetUserListAsync(Action callback) + { + return APIRequestWithTokenAsync(); + } + + public void ChannelsCreate(Action callback, string name) + { + APIRequestWithToken(callback, new Tuple("name", name)); + } + + public Task ChannelsCreateAsync(Action callback, string name) + { + return APIRequestWithTokenAsync(new Tuple("name", name)); + } public void ChannelsInvite(Action callback, string userId, string channelId) { @@ -142,27 +171,50 @@ public void ChannelsInvite(Action callback, string userId APIRequestWithToken(callback, parameters.ToArray()); } + public Task ChannelsInviteAsync(string userId, string channelId) + { + List> parameters = new List>(); + + parameters.Add(new Tuple("channel", channelId)); + parameters.Add(new Tuple("user", userId)); + + return APIRequestWithTokenAsync(parameters.ToArray()); + } + public void GetChannelList(Action callback, bool ExcludeArchived = true) { APIRequestWithToken(callback, new Tuple("exclude_archived", ExcludeArchived ? "1" : "0")); } + public Task GetChannelListAsync(bool ExcludeArchived = true) + { + return APIRequestWithTokenAsync(new Tuple("exclude_archived", ExcludeArchived ? "1" : "0")); + } + public void GetGroupsList(Action callback, bool ExcludeArchived = true) { APIRequestWithToken(callback, new Tuple("exclude_archived", ExcludeArchived ? "1" : "0")); } + public Task GetGroupsListAsync(Action callback, bool ExcludeArchived = true) + { + return APIRequestWithTokenAsync(new Tuple("exclude_archived", ExcludeArchived ? "1" : "0")); + } public void GetDirectMessageList(Action callback) { APIRequestWithToken(callback); } + public Task GetDirectMessageListAsync() + { + return APIRequestWithTokenAsync(); + } public void GetFiles(Action callback, string userId = null, DateTime? from = null, DateTime? to = null, int? count = null, int? page = null, FileTypes types = FileTypes.all, string channel = null) { List> parameters = new List>(); if (!string.IsNullOrEmpty(userId)) - parameters.Add(new Tuple("user", userId)); + parameters.Add(new Tuple("user", userId)); if (from.HasValue) parameters.Add(new Tuple("ts_from", from.Value.ToProperTimeStamp())); @@ -204,18 +256,65 @@ public void GetFiles(Action callback, string userId = null, Da APIRequestWithToken(callback, parameters.ToArray()); } + public Task GetFiles(string userId = null, DateTime? from = null, DateTime? to = null, int? count = null, int? page = null, FileTypes types = FileTypes.all, string channel = null) + { + List> parameters = new List>(); + + if (!string.IsNullOrEmpty(userId)) + parameters.Add(new Tuple("user", userId)); + + if (from.HasValue) + parameters.Add(new Tuple("ts_from", from.Value.ToProperTimeStamp())); + + if (to.HasValue) + parameters.Add(new Tuple("ts_to", to.Value.ToProperTimeStamp())); + + if (!types.HasFlag(FileTypes.all)) + { + FileTypes[] values = (FileTypes[])Enum.GetValues(typeof(FileTypes)); + + StringBuilder building = new StringBuilder(); + bool first = true; + for (int i = 0; i < values.Length; ++i) + { + if (types.HasFlag(values[i])) + { + if (!first) building.Append(","); + + building.Append(values[i].ToString()); + + first = false; + } + } + + if (building.Length > 0) + parameters.Add(new Tuple("types", building.ToString())); + } + + if (count.HasValue) + parameters.Add(new Tuple("count", count.Value.ToString())); + + if (page.HasValue) + parameters.Add(new Tuple("page", page.Value.ToString())); + + if (!string.IsNullOrEmpty(channel)) + parameters.Add(new Tuple("channel", channel)); + + return APIRequestWithTokenAsync(parameters.ToArray()); + } + void GetHistory(Action historyCallback, string channel, DateTime? latest = null, DateTime? oldest = null, int? count = null) where K : MessageHistory { - List> parameters = new List>(); + List> parameters = new List>(); parameters.Add(new Tuple("channel", channel)); - if(latest.HasValue) + if (latest.HasValue) parameters.Add(new Tuple("latest", latest.Value.ToProperTimeStamp())); - if(oldest.HasValue) + if (oldest.HasValue) parameters.Add(new Tuple("oldest", oldest.Value.ToProperTimeStamp())); - if(count.HasValue) - parameters.Add(new Tuple("count", count.Value.ToString())); + if (count.HasValue) + parameters.Add(new Tuple("count", count.Value.ToString())); APIRequestWithToken(historyCallback, parameters.ToArray()); } @@ -245,12 +344,12 @@ public void MarkChannel(Action callback, string channelId, DateTim public void GetFileInfo(Action callback, string fileId, int? page = null, int? count = null) { - List> parameters = new List>(); + List> parameters = new List>(); - parameters.Add(new Tuple("file", fileId)); + parameters.Add(new Tuple("file", fileId)); - if(count.HasValue) - parameters.Add(new Tuple("count", count.Value.ToString())); + if (count.HasValue) + parameters.Add(new Tuple("count", count.Value.ToString())); if (page.HasValue) parameters.Add(new Tuple("page", page.Value.ToString())); @@ -396,6 +495,29 @@ public void SearchMessages(Action callback, string query APIRequestWithToken(callback, parameters.ToArray()); } + public Task SearchMessagesAsync(string query, string sorting = null, SearchSortDirection? direction = null, bool enableHighlights = false, int? count = null, int? page = null) + { + List> parameters = new List>(); + parameters.Add(new Tuple("query", query)); + + if (sorting != null) + parameters.Add(new Tuple("sort", sorting)); + + if (direction.HasValue) + parameters.Add(new Tuple("sort_dir", direction.Value.ToString())); + + if (enableHighlights) + parameters.Add(new Tuple("highlight", "1")); + + if (count.HasValue) + parameters.Add(new Tuple("count", count.Value.ToString())); + + if (page.HasValue) + parameters.Add(new Tuple("page", page.Value.ToString())); + + return APIRequestWithTokenAsync(parameters.ToArray()); + } + public void SearchFiles(Action callback, string query, string sorting = null, SearchSortDirection? direction = null, bool enableHighlights = false, int? count = null, int? page = null) { List> parameters = new List>(); @@ -418,22 +540,61 @@ public void SearchFiles(Action callback, string query, stri APIRequestWithToken(callback, parameters.ToArray()); } + public Task SearchFilesAsync(string query, string sorting = null, SearchSortDirection? direction = null, bool enableHighlights = false, int? count = null, int? page = null) + { + List> parameters = new List>(); + parameters.Add(new Tuple("query", query)); - public void GetStars(Action callback, string userId = null, int? count = null, int? page = null){ - List> parameters = new List>(); + if (sorting != null) + parameters.Add(new Tuple("sort", sorting)); - if(!string.IsNullOrEmpty(userId)) - parameters.Add(new Tuple("user", userId)); + if (direction.HasValue) + parameters.Add(new Tuple("sort_dir", direction.Value.ToString())); + + if (enableHighlights) + parameters.Add(new Tuple("highlight", "1")); + + if (count.HasValue) + parameters.Add(new Tuple("count", count.Value.ToString())); + + if (page.HasValue) + parameters.Add(new Tuple("page", page.Value.ToString())); + + return APIRequestWithTokenAsync(parameters.ToArray()); + } - if(count.HasValue) - parameters.Add(new Tuple("count", count.Value.ToString())); + public void GetStars(Action callback, string userId = null, int? count = null, int? page = null) + { + List> parameters = new List>(); - if(page.HasValue) - parameters.Add(new Tuple("page", page.Value.ToString())); + if (!string.IsNullOrEmpty(userId)) + parameters.Add(new Tuple("user", userId)); + + if (count.HasValue) + parameters.Add(new Tuple("count", count.Value.ToString())); + + if (page.HasValue) + parameters.Add(new Tuple("page", page.Value.ToString())); APIRequestWithToken(callback, parameters.ToArray()); } + public Task GetStarsAsync(string userId = null, int? count = null, int? page = null) + { + List> parameters = new List>(); + + if (!string.IsNullOrEmpty(userId)) + parameters.Add(new Tuple("user", userId)); + + if (count.HasValue) + parameters.Add(new Tuple("count", count.Value.ToString())); + + if (page.HasValue) + parameters.Add(new Tuple("page", page.Value.ToString())); + + return APIRequestWithTokenAsync(parameters.ToArray()); + } + public void DeleteMessage(Action callback, string channelId, DateTime ts) { List> parameters = new List>() @@ -444,17 +605,36 @@ public void DeleteMessage(Action callback, string channelId, Da APIRequestWithToken(callback, parameters.ToArray()); } + public Task DeleteMessageAsync(string channelId, DateTime ts) + { + List> parameters = new List>() + { + new Tuple("ts", ts.ToProperTimeStamp()), + new Tuple("channel", channelId) + }; + + return APIRequestWithTokenAsync(parameters.ToArray()); + } public void EmitPresence(Action callback, Presence status) { APIRequestWithToken(callback, new Tuple("presence", status.ToString())); } + public Task EmitPresenceAsync(Presence status) + { + return APIRequestWithTokenAsync(new Tuple("presence", status.ToString())); + } public void GetPreferences(Action callback) { APIRequestWithToken(callback); } + public Task GetPreferences() + { + return APIRequestWithTokenAsync(); + } + #region Users public void GetCounts(Action callback) @@ -507,25 +687,71 @@ public void Update( parameters.Add(new Tuple("link_names", "1")); if (blocks != null && blocks.Length > 0) - parameters.Add(new Tuple("blocks", - JsonConvert.SerializeObject(blocks, new JsonSerializerSettings() - { - NullValueHandling = NullValueHandling.Ignore - }))); + parameters.Add(new Tuple("blocks", + JsonConvert.SerializeObject(blocks, new JsonSerializerSettings() + { + NullValueHandling = NullValueHandling.Ignore + }))); if (attachments != null && attachments.Length > 0) parameters.Add(new Tuple("attachments", JsonConvert.SerializeObject(attachments, new JsonSerializerSettings() { - NullValueHandling = NullValueHandling.Ignore + NullValueHandling = NullValueHandling.Ignore }))); - parameters.Add(new Tuple("as_user", as_user.ToString())); + parameters.Add(new Tuple("as_user", as_user.ToString())); APIRequestWithToken(callback, parameters.ToArray()); } + public Task UpdateAsync( + string ts, + string channelId, + string text, + string botName = null, + string parse = null, + bool linkNames = false, + IBlock[] blocks = null, + Attachment[] attachments = null, + bool as_user = false) + { + List> parameters = new List>(); + + parameters.Add(new Tuple("ts", ts)); + parameters.Add(new Tuple("channel", channelId)); + parameters.Add(new Tuple("text", text)); + + if (!string.IsNullOrEmpty(botName)) + parameters.Add(new Tuple("username", botName)); + + if (!string.IsNullOrEmpty(parse)) + parameters.Add(new Tuple("parse", parse)); + + if (linkNames) + parameters.Add(new Tuple("link_names", "1")); + + if (blocks != null && blocks.Length > 0) + parameters.Add(new Tuple("blocks", + JsonConvert.SerializeObject(blocks, new JsonSerializerSettings() + { + NullValueHandling = NullValueHandling.Ignore + }))); + + if (attachments != null && attachments.Length > 0) + parameters.Add(new Tuple("attachments", + JsonConvert.SerializeObject(attachments, new JsonSerializerSettings() + { + NullValueHandling = NullValueHandling.Ignore + }))); + + + parameters.Add(new Tuple("as_user", as_user.ToString())); + + return APIRequestWithTokenAsync< UpdateResponse>(parameters.ToArray()); + } + public void JoinDirectMessageChannel(Action callback, string user) { var param = new Tuple("user", user); @@ -545,15 +771,15 @@ public void PostMessage( string icon_url = null, string icon_emoji = null, bool? as_user = null, - string thread_ts = null) + string thread_ts = null) { - List> parameters = new List>(); + List> parameters = new List>(); - parameters.Add(new Tuple("channel", channelId)); - parameters.Add(new Tuple("text", text)); + parameters.Add(new Tuple("channel", channelId)); + parameters.Add(new Tuple("text", text)); - if(!string.IsNullOrEmpty(botName)) - parameters.Add(new Tuple("username", botName)); + if (!string.IsNullOrEmpty(botName)) + parameters.Add(new Tuple("username", botName)); if (!string.IsNullOrEmpty(parse)) parameters.Add(new Tuple("parse", parse)); @@ -562,22 +788,22 @@ public void PostMessage( parameters.Add(new Tuple("link_names", "1")); if (blocks != null && blocks.Length > 0) - parameters.Add(new Tuple("blocks", - JsonConvert.SerializeObject(blocks, Formatting.None, - new JsonSerializerSettings // Shouldn't include a not set property - { - NullValueHandling = NullValueHandling.Ignore - }))); + parameters.Add(new Tuple("blocks", + JsonConvert.SerializeObject(blocks, Formatting.None, + new JsonSerializerSettings // Shouldn't include a not set property + { + NullValueHandling = NullValueHandling.Ignore + }))); if (attachments != null && attachments.Length > 0) - parameters.Add(new Tuple("attachments", - JsonConvert.SerializeObject(attachments, Formatting.None, - new JsonSerializerSettings // Shouldn't include a not set property - { - NullValueHandling = NullValueHandling.Ignore - }))); - - if (unfurl_links) + parameters.Add(new Tuple("attachments", + JsonConvert.SerializeObject(attachments, Formatting.None, + new JsonSerializerSettings // Shouldn't include a not set property + { + NullValueHandling = NullValueHandling.Ignore + }))); + + if (unfurl_links) parameters.Add(new Tuple("unfurl_links", "1")); if (!string.IsNullOrEmpty(icon_url)) @@ -595,6 +821,68 @@ public void PostMessage( APIRequestWithToken(callback, parameters.ToArray()); } + public Task PostMessageAsync( + string channelId, + string text, + string botName = null, + string parse = null, + bool linkNames = false, + IBlock[] blocks = null, + Attachment[] attachments = null, + bool unfurl_links = false, + string icon_url = null, + string icon_emoji = null, + bool? as_user = null, + string thread_ts = null) + { + List> parameters = new List>(); + + parameters.Add(new Tuple("channel", channelId)); + parameters.Add(new Tuple("text", text)); + + if (!string.IsNullOrEmpty(botName)) + parameters.Add(new Tuple("username", botName)); + + if (!string.IsNullOrEmpty(parse)) + parameters.Add(new Tuple("parse", parse)); + + if (linkNames) + parameters.Add(new Tuple("link_names", "1")); + + if (blocks != null && blocks.Length > 0) + parameters.Add(new Tuple("blocks", + JsonConvert.SerializeObject(blocks, Formatting.None, + new JsonSerializerSettings // Shouldn't include a not set property + { + NullValueHandling = NullValueHandling.Ignore + }))); + + if (attachments != null && attachments.Length > 0) + parameters.Add(new Tuple("attachments", + JsonConvert.SerializeObject(attachments, Formatting.None, + new JsonSerializerSettings // Shouldn't include a not set property + { + NullValueHandling = NullValueHandling.Ignore + }))); + + if (unfurl_links) + parameters.Add(new Tuple("unfurl_links", "1")); + + if (!string.IsNullOrEmpty(icon_url)) + parameters.Add(new Tuple("icon_url", icon_url)); + + if (!string.IsNullOrEmpty(icon_emoji)) + parameters.Add(new Tuple("icon_emoji", icon_emoji)); + + if (as_user.HasValue) + parameters.Add(new Tuple("as_user", as_user.ToString())); + + if (!string.IsNullOrEmpty(thread_ts)) + parameters.Add(new Tuple("thread_ts", thread_ts)); + + return APIRequestWithTokenAsync(parameters.ToArray()); + } + public void PostEphemeralMessage( Action callback, string channelId, @@ -605,13 +893,13 @@ public void PostEphemeralMessage( Block[] blocks = null, Attachment[] attachments = null, bool as_user = false, - string thread_ts = null) + string thread_ts = null) { - List> parameters = new List>(); + List> parameters = new List>(); - parameters.Add(new Tuple("channel", channelId)); - parameters.Add(new Tuple("text", text)); - parameters.Add(new Tuple("user", targetuser)); + parameters.Add(new Tuple("channel", channelId)); + parameters.Add(new Tuple("text", text)); + parameters.Add(new Tuple("user", targetuser)); if (!string.IsNullOrEmpty(parse)) parameters.Add(new Tuple("parse", parse)); @@ -639,23 +927,68 @@ public void PostEphemeralMessage( APIRequestWithToken(callback, parameters.ToArray()); } + + public Task PostEphemeralMessageAsync( + string channelId, + string text, + string targetuser, + string parse = null, + bool linkNames = false, + Block[] blocks = null, + Attachment[] attachments = null, + bool as_user = false, + string thread_ts = null) + { + List> parameters = new List>(); + + parameters.Add(new Tuple("channel", channelId)); + parameters.Add(new Tuple("text", text)); + parameters.Add(new Tuple("user", targetuser)); + + if (!string.IsNullOrEmpty(parse)) + parameters.Add(new Tuple("parse", parse)); + + if (linkNames) + parameters.Add(new Tuple("link_names", "1")); + + if (blocks != null && blocks.Length > 0) + parameters.Add(new Tuple("blocks", + JsonConvert.SerializeObject(blocks, Formatting.None, + new JsonSerializerSettings // Shouldn't include a not set property + { + NullValueHandling = NullValueHandling.Ignore + }))); + + if (attachments != null && attachments.Length > 0) + parameters.Add(new Tuple("attachments", + JsonConvert.SerializeObject(attachments, Formatting.None, + new JsonSerializerSettings // Shouldn't include a not set property + { + NullValueHandling = NullValueHandling.Ignore + }))); + + parameters.Add(new Tuple("as_user", as_user.ToString())); + + return APIRequestWithTokenAsync(parameters.ToArray()); + } + public void DialogOpen( Action callback, string triggerId, Dialog dialog) { - List> parameters = new List>(); + List> parameters = new List>(); - parameters.Add(new Tuple("trigger_id", triggerId)); + parameters.Add(new Tuple("trigger_id", triggerId)); - parameters.Add(new Tuple("dialog", - JsonConvert.SerializeObject(dialog, - new JsonSerializerSettings - { - NullValueHandling = NullValueHandling.Ignore - }))); + parameters.Add(new Tuple("dialog", + JsonConvert.SerializeObject(dialog, + new JsonSerializerSettings + { + NullValueHandling = NullValueHandling.Ignore + }))); - APIRequestWithToken(callback, parameters.ToArray()); + APIRequestWithToken(callback, parameters.ToArray()); } public void AddReaction( @@ -678,6 +1011,27 @@ public void AddReaction( APIRequestWithToken(callback, parameters.ToArray()); } + public Task AddReactionAsync( + string name = null, + string channel = null, + string timestamp = null) + { + List> parameters = new List>(); + + if (!string.IsNullOrEmpty(name)) + parameters.Add(new Tuple("name", name)); + + if (!string.IsNullOrEmpty(channel)) + parameters.Add(new Tuple("channel", channel)); + + if (!string.IsNullOrEmpty(timestamp)) + parameters.Add(new Tuple("timestamp", timestamp)); + + return APIRequestWithTokenAsync(parameters.ToArray()); + } + + + public void UploadFile(Action callback, byte[] fileData, string fileName, string[] channelIds, string title = null, string initialComment = null, bool useAsync = false, string fileType = null) { Uri target = new Uri(Path.Combine(APIBaseLocation, useAsync ? "files.uploadAsync" : "files.upload")); @@ -709,6 +1063,37 @@ public void UploadFile(Action callback, byte[] fileData, str } } + public async Task UploadFileAsync(byte[] fileData, string fileName, string[] channelIds, string title = null, string initialComment = null, bool useAsync = false, string fileType = null) + { + Uri target = new Uri(Path.Combine(APIBaseLocation, useAsync ? "files.uploadAsync" : "files.upload")); + + List parameters = new List(); + parameters.Add(string.Format("token={0}", APIToken)); + + //File/Content + if (!string.IsNullOrEmpty(fileType)) + parameters.Add(string.Format("{0}={1}", "filetype", fileType)); + + if (!string.IsNullOrEmpty(fileName)) + parameters.Add(string.Format("{0}={1}", "filename", fileName)); + + if (!string.IsNullOrEmpty(title)) + parameters.Add(string.Format("{0}={1}", "title", title)); + + if (!string.IsNullOrEmpty(initialComment)) + parameters.Add(string.Format("{0}={1}", "initial_comment", initialComment)); + + parameters.Add(string.Format("{0}={1}", "channels", string.Join(",", channelIds))); + + using (MultipartFormDataContent form = new MultipartFormDataContent()) + { + form.Add(new ByteArrayContent(fileData), "file", fileName); + HttpResponseMessage response = await PostRequestAsync(string.Format("{0}?{1}", target, string.Join("&", parameters.ToArray())), form); + string result = await response.Content.ReadAsStringAsync(); + return result.Deserialize(); + } + } + public void DeleteFile(Action callback, string file = null) { if (string.IsNullOrEmpty(file)) @@ -716,5 +1101,12 @@ public void DeleteFile(Action callback, string file = null) APIRequestWithToken(callback, new Tuple("file", file)); } + + public Task DeleteFileAsync(string file) + { + if (file == null) throw new ArgumentException(nameof(file)); + + return APIRequestWithTokenAsync(new Tuple("file", file)); + } } } diff --git a/SlackAPI/SlackClientBase.cs b/SlackAPI/SlackClientBase.cs index 6d0129d..a0c15a7 100644 --- a/SlackAPI/SlackClientBase.cs +++ b/SlackAPI/SlackClientBase.cs @@ -109,6 +109,10 @@ protected HttpResponseMessage PostRequest(string requestUri, MultipartFormDataCo { return httpClient.PostAsync(requestUri, form).Result; } + protected Task PostRequestAsync(string requestUri, MultipartFormDataContent form) + { + return httpClient.PostAsync(requestUri, form); + } public void RegisterConverter(JsonConverter converter) { diff --git a/SlackAPI/SlackSocketClient.cs b/SlackAPI/SlackSocketClient.cs index 5aff2a3..b9b0c70 100644 --- a/SlackAPI/SlackSocketClient.cs +++ b/SlackAPI/SlackSocketClient.cs @@ -139,7 +139,11 @@ public void HandleUserChange(UserChange change) public void HandleTeamJoin(TeamJoin newuser) { - UserLookup.Add(newuser.user.id, newuser.user); + try + { + UserLookup.Add(newuser.user.id, newuser.user); + } + catch { } } public void HandleChannelCreated(ChannelCreated created) From 6e116df904a2bee60ae36d84e3088d58f74409bd Mon Sep 17 00:00:00 2001 From: mbellas-tkxs Date: Sat, 30 Nov 2019 14:45:05 -0500 Subject: [PATCH 2/2] obsolete SlackTaskClient --- SlackAPI/SlackTaskClient.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/SlackAPI/SlackTaskClient.cs b/SlackAPI/SlackTaskClient.cs index 546d452..f76702b 100644 --- a/SlackAPI/SlackTaskClient.cs +++ b/SlackAPI/SlackTaskClient.cs @@ -11,6 +11,7 @@ namespace SlackAPI { + [Obsolete("Use SlackClient Async methods instead")] public class SlackTaskClient : SlackClientBase { private readonly string APIToken;