diff --git a/SlackNet.Tests/ApiLintTest.cs b/SlackNet.Tests/ApiLintTest.cs index cffa754..7da4174 100644 --- a/SlackNet.Tests/ApiLintTest.cs +++ b/SlackNet.Tests/ApiLintTest.cs @@ -180,6 +180,11 @@ public Task Respond(string responseUrl, IReadOnlyMessage message, CancellationTo throw new NotImplementedException(); } + public ISlackApiClient WithAccessToken(string accessToken) + { + throw new NotImplementedException(); + } + public IApiApi Api { get; } public IAuthApi Auth { get; } public IBotsApi Bots { get; } diff --git a/SlackNet/SlackApiClient.cs b/SlackNet/SlackApiClient.cs index ab5d9ae..fe92fd0 100644 --- a/SlackNet/SlackApiClient.cs +++ b/SlackNet/SlackApiClient.cs @@ -105,6 +105,13 @@ public interface ISlackApiClient /// The message to respond with. /// Task Respond(string responseUrl, IReadOnlyMessage message, CancellationToken? cancellationToken); + + /// + /// Returns a copy of the client using a different access token. + /// Useful when you need to run a command as a specific user. + /// + /// New access token. + ISlackApiClient WithAccessToken(string accessToken); } public class SlackApiClient : ISlackApiClient @@ -130,6 +137,13 @@ public SlackApiClient(IHttp http, ISlackUrlBuilder urlBuilder, SlackJsonSettings _token = token; } + /// + /// Returns a copy of the client using a different access token. + /// Useful when you need to run a command as a specific user. + /// + /// New access token. + public ISlackApiClient WithAccessToken(string accessToken) => new SlackApiClient(_http, _urlBuilder, _jsonSettings, accessToken); + public IApiApi Api => new ApiApi(this); public IAuthApi Auth => new AuthApi(this); public IBotsApi Bots => new BotsApi(this);