Skip to content

Commit

Permalink
Adds chat.postEphemeral support
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkors committed Apr 7, 2023
1 parent 0020715 commit dfc5234
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 1 deletion.
7 changes: 7 additions & 0 deletions source/src/Slackbot.Net.SlackClients.Http/ISlackClient.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Slackbot.Net.SlackClients.Http.Models.Requests.ChatPostEphemeral;
using Slackbot.Net.SlackClients.Http.Models.Requests.ChatPostMessage;
using Slackbot.Net.SlackClients.Http.Models.Requests.FileUpload;
using Slackbot.Net.SlackClients.Http.Models.Requests.ViewPublish;
Expand Down Expand Up @@ -29,6 +30,12 @@ public interface ISlackClient
/// </summary>
/// <remarks>https://api.slack.com/methods/chat.postMessage</remarks>
Task<ChatPostMessageResponse> ChatPostMessage(ChatPostMessageRequest postMessage);

/// <summary>
/// Scopes required: `chat:write`
/// </summary>
/// <remarks>https://api.slack.com/methods/chat.postEphemeral</remarks>
Task<ChatPostMessageResponse> ChatPostEphemeralMessage(ChatPostEphemeralMessageRequest postMessage);

/// <summary>
/// Scopes required: no scopes required
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Slackbot.Net.Models.BlockKit;

namespace Slackbot.Net.SlackClients.Http.Models.Requests.ChatPostEphemeral;

public class ChatPostEphemeralMessageRequest
{
public string Channel { get; set; }
public string Text { get; set; }
public string User { get; set; }

public bool Link_Names { get; set; } = true;
public string thread_ts { get; set; }
public IBlock[] Blocks { get; set; }
}
7 changes: 7 additions & 0 deletions source/src/Slackbot.Net.SlackClients.Http/SlackClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Extensions.Logging;
using Slackbot.Net.SlackClients.Http.Extensions;
using Slackbot.Net.SlackClients.Http.Models.Requests.ChatPostEphemeral;
using Slackbot.Net.SlackClients.Http.Models.Requests.ChatPostMessage;
using Slackbot.Net.SlackClients.Http.Models.Requests.FileUpload;
using Slackbot.Net.SlackClients.Http.Models.Requests.ViewPublish;
Expand Down Expand Up @@ -47,6 +48,12 @@ public async Task<ChatPostMessageResponse> ChatPostMessage(ChatPostMessageReques
return await _client.PostJson<ChatPostMessageResponse>(postMessage, "chat.postMessage", s => _logger.LogTrace(s));
}

/// <inheritdoc/>
public async Task<ChatPostMessageResponse> ChatPostEphemeralMessage(ChatPostEphemeralMessageRequest postMessage)
{
return await _client.PostJson<ChatPostMessageResponse>(postMessage, "chat.postEphemeral", s => _logger.LogTrace(s));
}

/// <inheritdoc/>
public async Task<ChatGetPermalinkResponse> ChatGetPermalink(string channel, string message_ts)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections;
using Slackbot.Net.Models.BlockKit;
using Slackbot.Net.SlackClients.Http.Exceptions;
using Slackbot.Net.SlackClients.Http.Models.Requests.ChatPostEphemeral;
using Slackbot.Net.SlackClients.Http.Models.Requests.ChatPostMessage;
using Slackbot.Net.Tests.Helpers;

Expand Down Expand Up @@ -33,6 +34,40 @@ public async Task PostWorks()
Assert.True(response.Ok);
}

[Fact]
public async Task PostEphemeralWorks()
{
var msg = new ChatPostEphemeralMessageRequest()
{
Channel = Channel,
Text = Text,
User = "U0EBWMGG4"
};
var response = await SlackClient.ChatPostEphemeralMessage(msg);
Assert.True(response.Ok);
}

[Fact]
public async Task PostEphemeralThreadWorks()
{
var initMsg = await SlackClient.ChatPostMessage(Channel, "Some thread starting text");
var reply = await SlackClient.ChatPostMessage(new ChatPostMessageRequest
{
Channel = Channel,
Text = "A threaded reply ",
thread_ts = initMsg.ts,
});
var msg = new ChatPostEphemeralMessageRequest()
{
Channel = Channel,
Text = "This is ephemeral to johnkors",
User = "U0EBWMGG4",
thread_ts = reply.ts
};
var response = await SlackClient.ChatPostEphemeralMessage(msg);
Assert.True(response.Ok);
}

[Fact]
public async Task PostWithBroadCastWorks()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Setup(ITestOutputHelper helper)
SearchClient = provider.GetService<ISearchClient>();
SlackClient = provider.GetService<ISlackClient>();
SlackOAuthClient = provider.GetService<ISlackOAuthAccessClient>();
Channel = "#testss";
Channel = "#test";
Text = "Test";
}
}
Expand Down

0 comments on commit dfc5234

Please sign in to comment.