From 06f268945a3b2892054fc8906c195365ecbfd856 Mon Sep 17 00:00:00 2001 From: Jason Proulx Date: Thu, 10 Sep 2020 11:47:39 -0400 Subject: [PATCH 1/3] Added conversations.list endpoint functionality and cursor request parameter functionality in base response class. --- SlackAPI.sln | 18 +++++++++--------- .../RPCMessages/ConversationsListResponse.cs | 14 ++++++++++++++ SlackAPI/Response.cs | 7 +++++++ SlackAPI/SlackClient.cs | 16 ++++++++++++++++ SlackAPI/SlackTaskClient.cs | 16 ++++++++++++++++ 5 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 SlackAPI/RPCMessages/ConversationsListResponse.cs diff --git a/SlackAPI.sln b/SlackAPI.sln index f3b012b7..f3f74ac0 100644 --- a/SlackAPI.sln +++ b/SlackAPI.sln @@ -1,20 +1,20 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26228.4 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30320.27 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", "{532C9828-A2CC-4281-950A-248B06D42E9C}" -ProjectSection(SolutionItems) = preProject - appveyor.yml = appveyor.yml - build.cake = build.cake - Directory.Build.props = Directory.Build.props - GlobalAssemblyInfo.cs = GlobalAssemblyInfo.cs - README.md = README.md -EndProjectSection + ProjectSection(SolutionItems) = preProject + appveyor.yml = appveyor.yml + build.cake = build.cake + Directory.Build.props = Directory.Build.props + GlobalAssemblyInfo.cs = GlobalAssemblyInfo.cs + README.md = README.md + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/SlackAPI/RPCMessages/ConversationsListResponse.cs b/SlackAPI/RPCMessages/ConversationsListResponse.cs new file mode 100644 index 00000000..005938f6 --- /dev/null +++ b/SlackAPI/RPCMessages/ConversationsListResponse.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SlackAPI.RPCMessages +{ + [RequestPath("conversations.list")] + public class ConversationsListResponse : Response + { + public Channel[] channels; + } +} diff --git a/SlackAPI/Response.cs b/SlackAPI/Response.cs index cff403b0..339bc0b8 100644 --- a/SlackAPI/Response.cs +++ b/SlackAPI/Response.cs @@ -25,5 +25,12 @@ public void AssertOk() if (!(ok)) throw new InvalidOperationException(string.Format("An error occurred: {0}", this.error)); } + + public ResponseMetaData response_metadata; + } + + public class ResponseMetaData + { + public string next_cursor; } } diff --git a/SlackAPI/SlackClient.cs b/SlackAPI/SlackClient.cs index d0fbcbcc..5d7d865d 100644 --- a/SlackAPI/SlackClient.cs +++ b/SlackAPI/SlackClient.cs @@ -147,6 +147,22 @@ public void ChannelsInvite(Action callback, string userId APIRequestWithToken(callback, parameters.ToArray()); } + public void GetConversationsList(Action callback, string cursor = "", bool ExcludeArchived = true, int limit = 100, string[] types = null) + { + List> parameters = new List>() + { + Tuple.Create("exclude_archived", ExcludeArchived ? "1" : "0") + }; + if (limit > 0) + Tuple.Create("limit", limit.ToString()); + if (types.Any()) + Tuple.Create("types", string.Join(",", types)); + if (!string.IsNullOrEmpty(cursor)) + parameters.Add(new Tuple("cursor", cursor)); + + APIRequestWithToken(callback, parameters.ToArray()); + } + public void GetChannelList(Action callback, bool ExcludeArchived = true) { APIRequestWithToken(callback, new Tuple("exclude_archived", ExcludeArchived ? "1" : "0")); diff --git a/SlackAPI/SlackTaskClient.cs b/SlackAPI/SlackTaskClient.cs index 4b19cab1..d85eb54e 100644 --- a/SlackAPI/SlackTaskClient.cs +++ b/SlackAPI/SlackTaskClient.cs @@ -127,6 +127,22 @@ public Task ChannelsInviteAsync(string userId, string cha return APIRequestWithTokenAsync(parameters.ToArray()); } + public Task GetConversationsListAsync(string cursor = "", bool ExcludeArchived = true, int limit = 100, string[] types = null) + { + List> parameters = new List>() + { + Tuple.Create("exclude_archived", ExcludeArchived ? "1" : "0") + }; + if (limit > 0) + parameters.Add(Tuple.Create("limit", limit.ToString())); + if (types != null && types.Any()) + parameters.Add(Tuple.Create("types", string.Join(",", types))); + if (!string.IsNullOrEmpty(cursor)) + parameters.Add(new Tuple("cursor", cursor)); + + return APIRequestWithTokenAsync(parameters.ToArray()); + } + public Task GetChannelListAsync(bool ExcludeArchived = true) { return APIRequestWithTokenAsync(new Tuple("exclude_archived", ExcludeArchived ? "1" : "0")); From ebe39058f754c3c19e1ef4f5e45fab748fc33593 Mon Sep 17 00:00:00 2001 From: Jason Proulx Date: Mon, 14 Sep 2020 10:02:02 -0400 Subject: [PATCH 2/3] Fixed indentation? --- SlackAPI/SlackClient.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SlackAPI/SlackClient.cs b/SlackAPI/SlackClient.cs index 5d7d865d..ac13416e 100644 --- a/SlackAPI/SlackClient.cs +++ b/SlackAPI/SlackClient.cs @@ -154,8 +154,8 @@ public void GetConversationsList(Action callback, str Tuple.Create("exclude_archived", ExcludeArchived ? "1" : "0") }; if (limit > 0) - Tuple.Create("limit", limit.ToString()); - if (types.Any()) + Tuple.Create("limit", limit.ToString()); + if (types.Any()) Tuple.Create("types", string.Join(",", types)); if (!string.IsNullOrEmpty(cursor)) parameters.Add(new Tuple("cursor", cursor)); From 7155e34cb651a626b05e1115e89c72a122377d25 Mon Sep 17 00:00:00 2001 From: Jason Proulx Date: Tue, 29 Sep 2020 09:37:18 -0400 Subject: [PATCH 3/3] Fixed missing "parameters.add" code in GetConversationsList() --- SlackAPI/SlackClient.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SlackAPI/SlackClient.cs b/SlackAPI/SlackClient.cs index ac13416e..eae70331 100644 --- a/SlackAPI/SlackClient.cs +++ b/SlackAPI/SlackClient.cs @@ -154,11 +154,11 @@ public void GetConversationsList(Action callback, str Tuple.Create("exclude_archived", ExcludeArchived ? "1" : "0") }; if (limit > 0) - Tuple.Create("limit", limit.ToString()); + parameters.Add(Tuple.Create("limit", limit.ToString())); if (types.Any()) - Tuple.Create("types", string.Join(",", types)); + parameters.Add(Tuple.Create("types", string.Join(",", types))); if (!string.IsNullOrEmpty(cursor)) - parameters.Add(new Tuple("cursor", cursor)); + parameters.Add(Tuple.Create("cursor", cursor)); APIRequestWithToken(callback, parameters.ToArray()); }