diff --git a/SlackNet.Tests/AgentSessionTitleChangedTests.cs b/SlackNet.Tests/AgentSessionTitleChangedTests.cs new file mode 100644 index 0000000..c31e51a --- /dev/null +++ b/SlackNet.Tests/AgentSessionTitleChangedTests.cs @@ -0,0 +1,51 @@ +using EasyAssertions; +using Newtonsoft.Json; +using NUnit.Framework; +using SlackNet.Events; + +namespace SlackNet.Tests; + +public class AgentSessionTitleChangedTests +{ + private JsonSerializerSettings _sut; + + [SetUp] + public void SetUp() + { + _sut = Default.JsonSettings(Default.SlackTypeResolver(Default.AssembliesContainingSlackTypes)).SerializerSettings; + } + + [Test] + public void AgentSessionTitleChanged_DeserializedFromSlackPayload() + { + var result = Deserialize(@"{ ""channel"": ""C0123ABC456"", ""event_ts"": ""1783536983.783769"", ""previous_title"": ""Scuba diving research"", ""team_id"": ""T0123ABC456"", ""thread_ts"": ""1782234671.392669"", ""title"": ""Bora Bora trip prep"", ""type"": ""agent_session_title_changed"", ""user"": ""U123ABC456"" }"); + + var changed = result.ShouldBeA().And; + changed.Channel.ShouldBe("C0123ABC456"); + changed.ThreadTs.ShouldBe("1782234671.392669"); + changed.User.ShouldBe("U123ABC456"); + changed.Title.ShouldBe("Bora Bora trip prep"); + changed.PreviousTitle.ShouldBe("Scuba diving research"); + changed.EventTs.ShouldBe("1783536983.783769"); + } + + [Test] + public void AgentSessionTitleChanged_SessionHadNoTitle_HasNoPreviousTitle() + { + var result = Deserialize(@"{ ""type"": ""agent_session_title_changed"", ""channel"": ""C1"", ""thread_ts"": ""1.2"", ""user"": ""U1"", ""title"": ""First title"" }"); + + var changed = result.ShouldBeA().And; + changed.Title.ShouldBe("First title"); + changed.PreviousTitle.ShouldBeNull(); + } + + [Test] + public void AgentSessionTitleChanged_InSessionChannel_MayHaveNoThread() + { + var result = Deserialize(@"{ ""type"": ""agent_session_title_changed"", ""channel"": ""C1"", ""user"": ""U1"", ""title"": ""Renamed"" }"); + + result.ShouldBeA().And.ThreadTs.ShouldBeNull(); + } + + private T Deserialize(string json) => JsonConvert.DeserializeObject(json, _sut); +} diff --git a/SlackNet/Events/AgentSessionTitleChanged.cs b/SlackNet/Events/AgentSessionTitleChanged.cs new file mode 100644 index 0000000..3c8739e --- /dev/null +++ b/SlackNet/Events/AgentSessionTitleChanged.cs @@ -0,0 +1,35 @@ +namespace SlackNet.Events; + +/// +/// Sent when a user changes the title of an agent session, even if the agent previously set that title. +/// If your agent keeps sessions in sync between Slack and your own UI, reflect the user's title change accordingly. +/// To set a session's title from your app, use agents.sessions.rename. +/// +/// See the Slack documentation for more information. +public class AgentSessionTitleChanged : Event +{ + /// + /// The channel containing the session. + /// + public string Channel { get; set; } + + /// + /// The root of the thread the session is scoped to. + /// + public string ThreadTs { get; set; } + + /// + /// The user who changed the title. + /// + public string User { get; set; } + + /// + /// The new title of the session. + /// + public string Title { get; set; } + + /// + /// The title of the session before the change. Omitted when the session had no title before the change. + /// + public string PreviousTitle { get; set; } +}