Skip to content

Commit 38a3871

Browse files
murdahljohnkors
andauthored
Add Chat update, ConversationOpen, input placeholder (#23)
* Add Chat update, ConversationOpen, input placeholder * conversation.open: fix xml doc comment * formatting: remove superflous whitespace --------- Co-authored-by: John Korsnes <johnkors@gmail.com>
1 parent b388554 commit 38a3871

File tree

5 files changed

+71
-16
lines changed

5 files changed

+71
-16
lines changed

source/src/Slackbot.Net.Shared/BlockElements.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,10 @@ public class Element : IElement
9797

9898
public class PlainTextInputElement : IElement
9999
{
100-
public string type { get; set;} = ElementTypes.PlainTextInput;
101-
public string initial_value { get; set;}
100+
public string type { get; set; } = ElementTypes.PlainTextInput;
101+
public string initial_value { get; set; }
102102
public string action_id { get; set; }
103+
public Text placeholder { get; set; }
103104
}
104105

105106
public class ImageElement : IElement

source/src/Slackbot.Net.SlackClients.Http/ISlackClient.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Slackbot.Net.SlackClients.Http.Models.Requests.ChatPostEphemeral;
22
using Slackbot.Net.SlackClients.Http.Models.Requests.ChatPostMessage;
3+
using Slackbot.Net.SlackClients.Http.Models.Requests.ChatUpdate;
34
using Slackbot.Net.SlackClients.Http.Models.Requests.FileUpload;
45
using Slackbot.Net.SlackClients.Http.Models.Requests.ViewPublish;
56
using Slackbot.Net.SlackClients.Http.Models.Responses;
@@ -37,6 +38,12 @@ public interface ISlackClient
3738
/// <remarks>https://api.slack.com/methods/chat.postEphemeral</remarks>
3839
Task<ChatPostMessageResponse> ChatPostEphemeralMessage(ChatPostEphemeralMessageRequest postMessage);
3940

41+
/// <summary>
42+
/// Scopes required: `chat:write`
43+
/// </summary>
44+
/// <remarks>https://api.slack.com/methods/chat.update</remarks>
45+
Task<ChatPostMessageResponse> ChatUpdate(ChatUpdateRequest postMessage);
46+
4047
/// <summary>
4148
/// Scopes required: no scopes required
4249
/// </summary>
@@ -76,6 +83,12 @@ public interface ISlackClient
7683
/// <remarks>https://api.slack.com/methods/conversations.list</remarks>
7784
Task<ConversationsRepliesResponse> ConversationsReplies(string channel, string ts, int? limit = null, string cursor = null);
7885

86+
/// <summary>
87+
/// Scopes required: channels:manage | groups:write | im:write | mpim:write
88+
/// </summary>
89+
/// <remarks>https://api.slack.com/methods/conversations.open</remarks>
90+
Task<ConversationsOpenResponse> ConversationsOpen(string[] users);
91+
7992

8093
/// <summary>
8194
/// Scopes required: none
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Slackbot.Net.Models.BlockKit;
2+
3+
namespace Slackbot.Net.SlackClients.Http.Models.Requests.ChatUpdate;
4+
5+
public class ChatUpdateRequest
6+
{
7+
public string channel { get; set; }
8+
public string ts { get; set; }
9+
public string text { get; set; }
10+
public IBlock[] blocks { get; set; }
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Slackbot.Net.SlackClients.Http.Models.Responses;
2+
3+
public class ConversationsOpenResponse : Response
4+
{
5+
public Channel channel { get; set; }
6+
}
7+
8+
public class Channel
9+
{
10+
public string id { get; set; }
11+
}

source/src/Slackbot.Net.SlackClients.Http/SlackClient.cs

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Slackbot.Net.SlackClients.Http.Extensions;
33
using Slackbot.Net.SlackClients.Http.Models.Requests.ChatPostEphemeral;
44
using Slackbot.Net.SlackClients.Http.Models.Requests.ChatPostMessage;
5+
using Slackbot.Net.SlackClients.Http.Models.Requests.ChatUpdate;
56
using Slackbot.Net.SlackClients.Http.Models.Requests.FileUpload;
67
using Slackbot.Net.SlackClients.Http.Models.Requests.ViewPublish;
78
using Slackbot.Net.SlackClients.Http.Models.Responses;
@@ -54,6 +55,12 @@ public async Task<ChatPostMessageResponse> ChatPostEphemeralMessage(ChatPostEphe
5455
return await _client.PostJson<ChatPostMessageResponse>(postMessage, "chat.postEphemeral", s => _logger.LogTrace(s));
5556
}
5657

58+
/// <inheritdoc/>
59+
public async Task<ChatPostMessageResponse> ChatUpdate(ChatUpdateRequest postMessage)
60+
{
61+
return await _client.PostJson<ChatPostMessageResponse>(postMessage, "chat.update", s => _logger.LogTrace(s));
62+
}
63+
5764
/// <inheritdoc/>
5865
public async Task<ChatGetPermalinkResponse> ChatGetPermalink(string channel, string message_ts)
5966
{
@@ -63,7 +70,7 @@ public async Task<ChatGetPermalinkResponse> ChatGetPermalink(string channel, str
6370
new KeyValuePair<string, string>("message_ts", message_ts)
6471
};
6572

66-
return await _client.PostParametersAsForm<ChatGetPermalinkResponse>(parameters,"chat.getPermalink", s => _logger.LogTrace(s));
73+
return await _client.PostParametersAsForm<ChatGetPermalinkResponse>(parameters, "chat.getPermalink", s => _logger.LogTrace(s));
6774
}
6875

6976
/// <inheritdoc/>
@@ -76,13 +83,13 @@ public async Task<Response> ReactionsAdd(string name, string channel, string tim
7683
new KeyValuePair<string, string>("timestamp", timestamp)
7784
};
7885

79-
return await _client.PostParametersAsForm<ChatGetPermalinkResponse>(parameters,"reactions.add", s => _logger.LogTrace(s));
86+
return await _client.PostParametersAsForm<ChatGetPermalinkResponse>(parameters, "reactions.add", s => _logger.LogTrace(s));
8087
}
8188

8289
/// <inheritdoc/>
8390
public async Task<UsersListResponse> UsersList()
8491
{
85-
return await _client.PostParametersAsForm<UsersListResponse>(null,"users.list", s => _logger.LogTrace(s));
92+
return await _client.PostParametersAsForm<UsersListResponse>(null, "users.list", s => _logger.LogTrace(s));
8693
}
8794

8895
/// <inheritdoc/>
@@ -98,7 +105,7 @@ public async Task<ConversationsListResponse> ConversationsListPublicChannels(int
98105
{
99106
parameters.Add(new KeyValuePair<string, string>("cursor", cursor));
100107
}
101-
return await _client.PostParametersAsForm<ConversationsListResponse>(parameters,"conversations.list", s => _logger.LogTrace(s));
108+
return await _client.PostParametersAsForm<ConversationsListResponse>(parameters, "conversations.list", s => _logger.LogTrace(s));
102109
}
103110

104111
/// <inheritdoc/>
@@ -108,7 +115,7 @@ public async Task<ConversationsListResponse> ConversationsMembers(string channel
108115
{
109116
new KeyValuePair<string, string>("channel", channel)
110117
};
111-
return await _client.PostParametersAsForm<ConversationsListResponse>(parameters,"conversations.members", s => _logger.LogTrace(s));
118+
return await _client.PostParametersAsForm<ConversationsListResponse>(parameters, "conversations.members", s => _logger.LogTrace(s));
112119
}
113120

114121
/// <inheritdoc/>
@@ -121,8 +128,18 @@ public async Task<ConversationsRepliesResponse> ConversationsReplies(string chan
121128
new KeyValuePair<string, string>("limit", (limit ?? 1000).ToString()),
122129
new KeyValuePair<string, string>("include_all_metadata", "true"),
123130
};
124-
return await _client.PostParametersAsForm<ConversationsRepliesResponse>(parameters,"conversations.replies", s => _logger.LogTrace(s));
125-
}
131+
return await _client.PostParametersAsForm<ConversationsRepliesResponse>(parameters, "conversations.replies", s => _logger.LogTrace(s));
132+
}
133+
134+
/// <inheritdoc/>
135+
public async Task<ConversationsOpenResponse> ConversationsOpen(string[] users)
136+
{
137+
var parameters = new List<KeyValuePair<string, string>>
138+
{
139+
new KeyValuePair<string, string>("users", string.Join(",", users)),
140+
};
141+
return await _client.PostParametersAsForm<ConversationsOpenResponse>(parameters, "conversations.open", s => _logger.LogTrace(s));
142+
}
126143

127144
/// <inheritdoc/>
128145
public async Task<Response> AppsUninstall(string clientId, string clientSecret)
@@ -132,9 +149,9 @@ public async Task<Response> AppsUninstall(string clientId, string clientSecret)
132149
new KeyValuePair<string, string>("client_id", clientId),
133150
new KeyValuePair<string, string>("client_secret", clientSecret)
134151
};
135-
return await _client.PostParametersAsForm<ConversationsListResponse>(parameters,"apps.uninstall", s => _logger.LogTrace(s));
152+
return await _client.PostParametersAsForm<ConversationsListResponse>(parameters, "apps.uninstall", s => _logger.LogTrace(s));
136153
}
137-
154+
138155
/// <inheritdoc/>
139156
public async Task<ViewPublishResponse> ViewPublish(ViewPublishRequest view)
140157
{
@@ -148,7 +165,7 @@ public async Task<UserProfileResponse> UserProfile(string user)
148165
{
149166
new KeyValuePair<string, string>("user", user),
150167
};
151-
return await _client.PostParametersAsForm<UserProfileResponse>(parameters,"users.profile.get", s => _logger.LogTrace(s));
168+
return await _client.PostParametersAsForm<UserProfileResponse>(parameters, "users.profile.get", s => _logger.LogTrace(s));
152169
}
153170

154171
/// <inheritdoc/>
@@ -166,7 +183,7 @@ public async Task<FileUploadResponse> FilesUpload(FileUploadRequest req)
166183
};
167184
return await _client.PostParametersAsForm<FileUploadResponse>(parameters, "files.upload", s => _logger.LogTrace(s));
168185
}
169-
186+
170187
/// <inheritdoc/>
171188
public async Task<FileUploadResponse> FilesUpload(FileUploadMultiPartRequest req)
172189
{
@@ -181,12 +198,14 @@ public async Task<FileUploadResponse> FilesUpload(FileUploadMultiPartRequest req
181198
{
182199
parameters.Add(new KeyValuePair<string, string>("initial_comment", req.Initial_Comment));
183200
}
184-
201+
185202
if (req.Thread_Ts is { })
186203
{
187204
parameters.Add(new KeyValuePair<string, string>("thread_ts", req.Thread_Ts));
188205
}
189-
206+
190207
return await _client.PostParametersAsMultiPartFormData<FileUploadResponse>(parameters, req.File, "files.upload", s => _logger.LogTrace(s));
191208
}
192-
}
209+
210+
211+
}

0 commit comments

Comments
 (0)