Skip to content
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
51 changes: 51 additions & 0 deletions SlackNet.Tests/AgentSessionTitleChangedTests.cs
Original file line number Diff line number Diff line change
@@ -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<Event>(@"{ ""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<AgentSessionTitleChanged>().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<Event>(@"{ ""type"": ""agent_session_title_changed"", ""channel"": ""C1"", ""thread_ts"": ""1.2"", ""user"": ""U1"", ""title"": ""First title"" }");

var changed = result.ShouldBeA<AgentSessionTitleChanged>().And;
changed.Title.ShouldBe("First title");
changed.PreviousTitle.ShouldBeNull();
}

[Test]
public void AgentSessionTitleChanged_InSessionChannel_MayHaveNoThread()
{
var result = Deserialize<Event>(@"{ ""type"": ""agent_session_title_changed"", ""channel"": ""C1"", ""user"": ""U1"", ""title"": ""Renamed"" }");

result.ShouldBeA<AgentSessionTitleChanged>().And.ThreadTs.ShouldBeNull();
}

private T Deserialize<T>(string json) => JsonConvert.DeserializeObject<T>(json, _sut);
}
35 changes: 35 additions & 0 deletions SlackNet/Events/AgentSessionTitleChanged.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace SlackNet.Events;

/// <summary>
/// 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 <c>agents.sessions.rename</c>.
/// </summary>
/// <remarks>See the <a href="https://docs.slack.dev/reference/events/agent_session_title_changed/">Slack documentation</a> for more information.</remarks>
public class AgentSessionTitleChanged : Event
{
/// <summary>
/// The channel containing the session.
/// </summary>
public string Channel { get; set; }

/// <summary>
/// The root of the thread the session is scoped to.
/// </summary>
public string ThreadTs { get; set; }

/// <summary>
/// The user who changed the title.
/// </summary>
public string User { get; set; }

/// <summary>
/// The new title of the session.
/// </summary>
public string Title { get; set; }

/// <summary>
/// The title of the session before the change. Omitted when the session had no title before the change.
/// </summary>
public string PreviousTitle { get; set; }
}
Loading