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
11 changes: 11 additions & 0 deletions src/Microsoft.Teams.Apps/Schema/SuggestedAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ public class ActionType(string value) : StringEnum(value)
public static readonly ActionType SignIn = new("signin");
/// <summary>Gets the <c>call</c> action type.</summary>
public static readonly ActionType Call = new("call");
/// <summary>
/// Gets the <c>setCachePolicy</c> action type used to control caching for a link-unfurling response.
/// Set the action value to <c>{"type":"no-cache"}</c> to prevent Teams from caching the response.
/// </summary>
public static readonly ActionType SetCachePolicy = new("setCachePolicy");
/// <summary>Gets the experimental <c>Action.Submit</c> action type.</summary>
public static readonly ActionType Submit = new("Action.Submit");

Expand Down Expand Up @@ -150,6 +155,12 @@ public static class ActionTypes
/// <summary>Gets the <c>call</c> action type.</summary>
public static ActionType Call => ActionType.Call;

/// <summary>
/// Gets the <c>setCachePolicy</c> action type used to control caching for a link-unfurling response.
/// Set the action value to <c>{"type":"no-cache"}</c> to prevent Teams from caching the response.
/// </summary>
public static ActionType SetCachePolicy => ActionType.SetCachePolicy;

/// <summary>Gets the experimental <c>Action.Submit</c> action type.</summary>
[System.Diagnostics.CodeAnalysis.Experimental("ExperimentalTeamsSuggestedAction")]
public static ActionType Submit => ActionType.Submit;
Expand Down
22 changes: 22 additions & 0 deletions test/Microsoft.Teams.Apps.UnitTests/SuggestedActionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public void ActionTypes_Constants_HaveExpectedValues()
Assert.Equal("downloadFile", ActionTypes.DownloadFile);
Assert.Equal("signin", ActionTypes.SignIn);
Assert.Equal("call", ActionTypes.Call);
Assert.Equal("setCachePolicy", ActionTypes.SetCachePolicy);
Assert.Equal("Action.Submit", ActionTypes.Submit);
}

Expand Down Expand Up @@ -250,4 +251,25 @@ public void MessageActivity_SuggestedActions_RoundTrip()
Assert.Equal("imBack", roundTripped.SuggestedActions.Actions[1].Type!.ToString());
Assert.Equal("Say Hi", roundTripped.SuggestedActions.Actions[1].Title);
}

[Fact]
public void MessageActivity_SetCachePolicySuggestedAction_RoundTripsNoCacheValue()
{
MessageActivity activity = new("Link unfurl")
{
SuggestedActions = new SuggestedActions()
.AddAction(new SuggestedAction(
ActionTypes.SetCachePolicy,
"Disable caching",
new { type = "no-cache" }))
};

string json = activity.ToJson();
CoreActivity coreActivity = CoreActivity.FromJsonString(json);
MessageActivity roundTripped = MessageActivity.FromActivity(coreActivity);

SuggestedAction action = Assert.Single(roundTripped.SuggestedActions!.Actions);
Assert.Equal("setCachePolicy", action.Type!.ToString());
Assert.Equal("no-cache", action.Value!["type"]!.GetValue<string>());
}
}
Loading