Skip to content

Commit dfc5234

Browse files
committed
Adds chat.postEphemeral support
1 parent 0020715 commit dfc5234

File tree

5 files changed

+64
-1
lines changed

5 files changed

+64
-1
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Slackbot.Net.SlackClients.Http.Models.Requests.ChatPostEphemeral;
12
using Slackbot.Net.SlackClients.Http.Models.Requests.ChatPostMessage;
23
using Slackbot.Net.SlackClients.Http.Models.Requests.FileUpload;
34
using Slackbot.Net.SlackClients.Http.Models.Requests.ViewPublish;
@@ -29,6 +30,12 @@ public interface ISlackClient
2930
/// </summary>
3031
/// <remarks>https://api.slack.com/methods/chat.postMessage</remarks>
3132
Task<ChatPostMessageResponse> ChatPostMessage(ChatPostMessageRequest postMessage);
33+
34+
/// <summary>
35+
/// Scopes required: `chat:write`
36+
/// </summary>
37+
/// <remarks>https://api.slack.com/methods/chat.postEphemeral</remarks>
38+
Task<ChatPostMessageResponse> ChatPostEphemeralMessage(ChatPostEphemeralMessageRequest postMessage);
3239

3340
/// <summary>
3441
/// Scopes required: no scopes required
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Slackbot.Net.Models.BlockKit;
2+
3+
namespace Slackbot.Net.SlackClients.Http.Models.Requests.ChatPostEphemeral;
4+
5+
public class ChatPostEphemeralMessageRequest
6+
{
7+
public string Channel { get; set; }
8+
public string Text { get; set; }
9+
public string User { get; set; }
10+
11+
public bool Link_Names { get; set; } = true;
12+
public string thread_ts { get; set; }
13+
public IBlock[] Blocks { get; set; }
14+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.Extensions.Logging;
22
using Slackbot.Net.SlackClients.Http.Extensions;
3+
using Slackbot.Net.SlackClients.Http.Models.Requests.ChatPostEphemeral;
34
using Slackbot.Net.SlackClients.Http.Models.Requests.ChatPostMessage;
45
using Slackbot.Net.SlackClients.Http.Models.Requests.FileUpload;
56
using Slackbot.Net.SlackClients.Http.Models.Requests.ViewPublish;
@@ -47,6 +48,12 @@ public async Task<ChatPostMessageResponse> ChatPostMessage(ChatPostMessageReques
4748
return await _client.PostJson<ChatPostMessageResponse>(postMessage, "chat.postMessage", s => _logger.LogTrace(s));
4849
}
4950

51+
/// <inheritdoc/>
52+
public async Task<ChatPostMessageResponse> ChatPostEphemeralMessage(ChatPostEphemeralMessageRequest postMessage)
53+
{
54+
return await _client.PostJson<ChatPostMessageResponse>(postMessage, "chat.postEphemeral", s => _logger.LogTrace(s));
55+
}
56+
5057
/// <inheritdoc/>
5158
public async Task<ChatGetPermalinkResponse> ChatGetPermalink(string channel, string message_ts)
5259
{

source/test/Slackbot.Net.SlackClients.Http.Tests/ChatPostMessageTests.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections;
22
using Slackbot.Net.Models.BlockKit;
33
using Slackbot.Net.SlackClients.Http.Exceptions;
4+
using Slackbot.Net.SlackClients.Http.Models.Requests.ChatPostEphemeral;
45
using Slackbot.Net.SlackClients.Http.Models.Requests.ChatPostMessage;
56
using Slackbot.Net.Tests.Helpers;
67

@@ -33,6 +34,40 @@ public async Task PostWorks()
3334
Assert.True(response.Ok);
3435
}
3536

37+
[Fact]
38+
public async Task PostEphemeralWorks()
39+
{
40+
var msg = new ChatPostEphemeralMessageRequest()
41+
{
42+
Channel = Channel,
43+
Text = Text,
44+
User = "U0EBWMGG4"
45+
};
46+
var response = await SlackClient.ChatPostEphemeralMessage(msg);
47+
Assert.True(response.Ok);
48+
}
49+
50+
[Fact]
51+
public async Task PostEphemeralThreadWorks()
52+
{
53+
var initMsg = await SlackClient.ChatPostMessage(Channel, "Some thread starting text");
54+
var reply = await SlackClient.ChatPostMessage(new ChatPostMessageRequest
55+
{
56+
Channel = Channel,
57+
Text = "A threaded reply ",
58+
thread_ts = initMsg.ts,
59+
});
60+
var msg = new ChatPostEphemeralMessageRequest()
61+
{
62+
Channel = Channel,
63+
Text = "This is ephemeral to johnkors",
64+
User = "U0EBWMGG4",
65+
thread_ts = reply.ts
66+
};
67+
var response = await SlackClient.ChatPostEphemeralMessage(msg);
68+
Assert.True(response.Ok);
69+
}
70+
3671
[Fact]
3772
public async Task PostWithBroadCastWorks()
3873
{

source/test/Slackbot.Net.SlackClients.Http.Tests/Helpers/Setup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public Setup(ITestOutputHelper helper)
3434
SearchClient = provider.GetService<ISearchClient>();
3535
SlackClient = provider.GetService<ISlackClient>();
3636
SlackOAuthClient = provider.GetService<ISlackOAuthAccessClient>();
37-
Channel = "#testss";
37+
Channel = "#test";
3838
Text = "Test";
3939
}
4040
}

0 commit comments

Comments
 (0)