diff --git a/SlackNet.Bot/BotMessage.cs b/SlackNet.Bot/BotMessage.cs
index 20c2845..3e8c921 100644
--- a/SlackNet.Bot/BotMessage.cs
+++ b/SlackNet.Bot/BotMessage.cs
@@ -86,5 +86,5 @@ public HubIdentifier Hub
///
/// Allows message sending to be cancelled, if it hasn't already been sent.
///
- public CancellationToken? CancellationToken { get; set; }
+ public CancellationToken CancellationToken { get; set; }
}
\ No newline at end of file
diff --git a/SlackNet.Bot/IMessage.cs b/SlackNet.Bot/IMessage.cs
index 32bd279..93b8d76 100644
--- a/SlackNet.Bot/IMessage.cs
+++ b/SlackNet.Bot/IMessage.cs
@@ -24,7 +24,7 @@ public interface IMessage
IList Blocks { get; set; }
bool IsInThread { get; }
bool MentionsBot { get; }
- Task ReplyWith(string text, bool createThread = false, CancellationToken? cancellationToken = null);
- Task ReplyWith(BotMessage message, bool createThread = false, CancellationToken? cancellationToken = null);
- Task ReplyWith(Func> createReply, bool createThread = false, CancellationToken? cancellationToken = null);
+ Task ReplyWith(string text, bool createThread = false, CancellationToken cancellationToken = default);
+ Task ReplyWith(BotMessage message, bool createThread = false, CancellationToken cancellationToken = default);
+ Task ReplyWith(Func> createReply, bool createThread = false, CancellationToken cancellationToken = default);
}
\ No newline at end of file
diff --git a/SlackNet.Bot/SlackBot.cs b/SlackNet.Bot/SlackBot.cs
index c721067..7c9cb62 100644
--- a/SlackNet.Bot/SlackBot.cs
+++ b/SlackNet.Bot/SlackBot.cs
@@ -32,7 +32,7 @@ public interface ISlackBot : IObserver
///
/// Connect to Slack.
///
- Task Connect(CancellationToken? cancellationToken = null);
+ Task Connect(CancellationToken cancellationToken = default);
///
/// Transform stream of incoming messages.
@@ -98,7 +98,7 @@ public interface ISlackBot : IObserver
///
/// Send a message to Slack as the bot.
///
- Task Send(BotMessage message, CancellationToken? cancellationToken = null);
+ Task Send(BotMessage message, CancellationToken cancellationToken = default);
///
/// Show typing indicator in Slack while performing some action.
@@ -210,7 +210,7 @@ public SlackBot(ISlackRtmClient rtmClient, ISlackApiClient apiClient, IScheduler
.Where(m => m.User != Id)
.SelectMany(CreateSlackMessage);
_outgoingWithMiddlewareApplied = _outgoingMessages
- .LimitFrequency(TimeSpan.FromSeconds(1), m => m.CancellationToken ?? CancellationToken.None, _scheduler);
+ .LimitFrequency(TimeSpan.FromSeconds(1), m => m.CancellationToken, _scheduler);
}
///
@@ -226,7 +226,7 @@ public SlackBot(ISlackRtmClient rtmClient, ISlackApiClient apiClient, IScheduler
///
/// Connect to Slack.
///
- public async Task Connect(CancellationToken? cancellationToken = null)
+ public async Task Connect(CancellationToken cancellationToken = default)
{
// If already connected, client will throw
var connection = _rtm.Connect(cancellationToken: cancellationToken);
@@ -451,11 +451,9 @@ private async Task> FetchUsers()
///
/// Send a message to Slack as the bot.
///
- public async Task Send(BotMessage message, CancellationToken? cancellationToken = null)
+ public async Task Send(BotMessage message, CancellationToken cancellationToken = default)
{
- var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(
- message.CancellationToken ?? CancellationToken.None,
- cancellationToken ?? CancellationToken.None);
+ var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(message.CancellationToken, cancellationToken);
message.CancellationToken = linkedTokenSource.Token;
var sent = _sentMessages.FirstOrDefaultAsync(m => m.Message == message)
diff --git a/SlackNet.Bot/SlackMessage.cs b/SlackNet.Bot/SlackMessage.cs
index 77593c1..b232229 100644
--- a/SlackNet.Bot/SlackMessage.cs
+++ b/SlackNet.Bot/SlackMessage.cs
@@ -32,10 +32,10 @@ public class SlackMessage(ISlackBot bot) : IMessage
|| Text.IndexOf(bot.Name, StringComparison.OrdinalIgnoreCase) >= 0
|| Conversation?.IsIm == true;
- public Task ReplyWith(string text, bool createThread = false, CancellationToken? cancellationToken = null) =>
+ public Task ReplyWith(string text, bool createThread = false, CancellationToken cancellationToken = default) =>
ReplyWith(new BotMessage { Text = text }, createThread, cancellationToken);
- public async Task ReplyWith(Func> createReply, bool createThread = false, CancellationToken? cancellationToken = null)
+ public async Task ReplyWith(Func> createReply, bool createThread = false, CancellationToken cancellationToken = default)
{
await bot.WhileTyping(Conversation.Id, async () =>
{
@@ -45,7 +45,7 @@ await bot.WhileTyping(Conversation.Id, async () =>
}).ConfigureAwait(false);
}
- public async Task ReplyWith(BotMessage message, bool createThread = false, CancellationToken? cancellationToken = null)
+ public async Task ReplyWith(BotMessage message, bool createThread = false, CancellationToken cancellationToken = default)
{
if (message == null) throw new ArgumentNullException(nameof(message));
diff --git a/SlackNet.Tests/ApiLintTest.cs b/SlackNet.Tests/ApiLintTest.cs
index d939dad..dc1ff4d 100644
--- a/SlackNet.Tests/ApiLintTest.cs
+++ b/SlackNet.Tests/ApiLintTest.cs
@@ -84,7 +84,7 @@ private static IEnumerable ParameterTypes(MethodInfo method)
private static void LastParamShouldBeOptionalCancellationToken(MethodInfo method)
{
var lastParam = method.GetParameters().Last();
- lastParam.ParameterType.ShouldBe(typeof(CancellationToken?), $"{method.DeclaringType!.Name}.{method.Name} is missing CancellationToken param");
+ lastParam.ParameterType.ShouldBe(typeof(CancellationToken), $"{method.DeclaringType!.Name}.{method.Name} is missing CancellationToken param");
lastParam.DefaultValue.ShouldBeNull($"{method.DeclaringType.Name}.{method.Name} CancellationToken param isn't null by default");
}
@@ -145,7 +145,7 @@ private static object DummyValue(ParameterInfo param) => ArgumentFactories.TryGe
{ typeof(IEnumerable), _ => Enumerable.Empty() },
{ typeof(FileUpload), _ => new FileUpload(string.Empty, string.Empty) },
{ typeof(IEnumerable), _ => Enumerable.Empty() },
- { typeof(CancellationToken?), _ => null },
+ { typeof(CancellationToken), _ => null },
};
private static IEnumerable ApiClasses => typeof(ApiApi).Assembly
@@ -163,47 +163,47 @@ public void Reset()
Args = null;
}
- public Task Get(string apiMethod, Args args, CancellationToken? cancellationToken)
+ public Task Get(string apiMethod, Args args, CancellationToken cancellationToken)
{
SlackMethod = apiMethod;
Args = args;
return Task.FromResult(0);
}
- public Task Get(string apiMethod, Args args, CancellationToken? cancellationToken) where T : class
+ public Task Get(string apiMethod, Args args, CancellationToken cancellationToken) where T : class
{
SlackMethod = apiMethod;
Args = args;
return Task.FromResult(Activator.CreateInstance());
}
- public Task Post(string apiMethod, Args args, HttpContent content, CancellationToken? cancellationToken)
+ public Task Post(string apiMethod, Args args, HttpContent content, CancellationToken cancellationToken)
{
SlackMethod = apiMethod;
Args = args;
return Task.FromResult(0);
}
- public Task Post(string apiMethod, Args args, CancellationToken? cancellationToken) =>
+ public Task Post(string apiMethod, Args args, CancellationToken cancellationToken) =>
Post