Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing response type for Chat.PostEphemeral #184

Merged
merged 1 commit into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions SlackNet.Bot/SlackBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,20 @@ private async Task<PostMessageResponse> PostMessage(BotMessage message)
AsUser = true
};

return message.Ephemeral
? await _api.Chat.PostEphemeral(message.ReplyTo.User.Id, slackMessage, message.CancellationToken).ConfigureAwait(false)
: await _api.Chat.PostMessage(slackMessage, message.CancellationToken).ConfigureAwait(false);
if (message.Ephemeral)
{
PostEphemeralResponse response = await _api.Chat.PostEphemeral(message.ReplyTo.User.Id, slackMessage, message.CancellationToken).ConfigureAwait(false);

// for backwards compatibility, convert to the other type and supply the correct information
// which is more than null values for each
return new PostMessageResponse
{
Ts = response.MessageTs,
Channel = slackMessage.Channel
};
}

return await _api.Chat.PostMessage(slackMessage, message.CancellationToken).ConfigureAwait(false);
}

private async Task<bool> ReplyingInDifferentHub(BotMessage message) =>
Expand Down
6 changes: 3 additions & 3 deletions SlackNet/WebApi/ChatApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public interface IChatApi
/// <param name="userId">ID of the user who will receive the ephemeral message. The user should be in the channel specified by the channel argument.</param>
/// <param name="message">The message to post. Not all message properties are supported by <c>PostEphemeral</c>.</param>
/// <param name="cancellationToken"></param>
Task<PostMessageResponse> PostEphemeral(string userId, Message message, CancellationToken? cancellationToken = null);
Task<PostEphemeralResponse> PostEphemeral(string userId, Message message, CancellationToken? cancellationToken = null);

/// <summary>
/// Attaches Slack app unfurl behavior to a specified and relevant message.
Expand Down Expand Up @@ -218,8 +218,8 @@ private Args PopulateMessageArgs(Message message, Args args)
},
cancellationToken);

public Task<PostMessageResponse> PostEphemeral(string userId, Message message, CancellationToken? cancellationToken = null) =>
_client.Post<PostMessageResponse>("chat.postEphemeral", new Args
public Task<PostEphemeralResponse> PostEphemeral(string userId, Message message, CancellationToken? cancellationToken = null) =>
_client.Post<PostEphemeralResponse>("chat.postEphemeral", new Args
{
{ "channel", message.Channel },
{ "text", message.Text },
Expand Down