-
Notifications
You must be signed in to change notification settings - Fork 16
Prompt Preview Support #433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
035496f
e62104d
b92891f
a64557d
2026c90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Microsoft.Teams.Api.Entities; | ||
|
|
||
| [Experimental("ExperimentalTeamsTargeted")] | ||
| public class TargetedMessageInfoEntity : Entity | ||
|
ShanmathiMayuramKrithivasan marked this conversation as resolved.
|
||
| { | ||
| [JsonPropertyName("messageId")] | ||
| [JsonPropertyOrder(3)] | ||
| public required string MessageId { get; set; } | ||
|
|
||
| public TargetedMessageInfoEntity() : base("targetedMessageInfo") { } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,6 +67,15 @@ public partial class Context<TActivity> : IContext<TActivity> | |
| { | ||
| public async Task<T> Send<T>(T activity, CancellationToken cancellationToken = default) where T : IActivity | ||
| { | ||
| // Auto-populate targetedMessageInfo entity for prompt preview | ||
| // when the incoming activity was a targeted message (reactive flow). | ||
| #pragma warning disable ExperimentalTeamsTargeted | ||
| if (activity is MessageActivity messageActivity && Activity.Recipient?.IsTargeted == true && Activity.Id is not null) | ||
| { | ||
| messageActivity.AddTargetedMessageInfo(Activity.Id); | ||
| } | ||
| #pragma warning restore ExperimentalTeamsTargeted | ||
|
Comment on lines
69
to
+77
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also scan
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed, but from the other direction - Reply skips ToQuoteReply when the incoming activity is targeted, so the blockquote is never generated. Same outcome. Since quoted reply is still not fully rolled out, going with this approach for the fix.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a fan of this approach. I intentionally asked for the check to be for quotedReply here to avoid collision with the quoted replies sdk changes, and we don't know which order they will be merged in. |
||
|
|
||
| var res = await Sender.Send(activity, Ref, CancellationToken); | ||
|
ShanmathiMayuramKrithivasan marked this conversation as resolved.
|
||
| await OnActivitySent(res, ToActivityType<IActivity>()); | ||
| return res; | ||
|
|
@@ -89,10 +98,19 @@ public Task<T> Reply<T>(T activity, CancellationToken cancellationToken = defaul | |
|
|
||
| if (activity is MessageActivity message) | ||
| { | ||
| message.Text = string.Join("\n", [ | ||
| Activity.ToQuoteReply(), | ||
| message.Text != string.Empty ? $"<p>{message.Text}</p>" : string.Empty | ||
| ]); | ||
| // Skip quoted reply when incoming activity is targeted — | ||
| // prompt preview owns the preview surface for targeted messages. | ||
| #pragma warning disable ExperimentalTeamsTargeted | ||
| var isTargeted = Activity.Recipient?.IsTargeted == true && Activity.Id is not null; | ||
| #pragma warning restore ExperimentalTeamsTargeted | ||
|
|
||
| if (!isTargeted) | ||
| { | ||
| message.Text = string.Join("\n", [ | ||
| Activity.ToQuoteReply(), | ||
| message.Text != string.Empty ? $"<p>{message.Text}</p>" : string.Empty | ||
| ]); | ||
| } | ||
| } | ||
|
|
||
| return Send(activity, cancellationToken); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| using System.Text.Json; | ||
|
|
||
| using Microsoft.Teams.Api.Activities; | ||
| using Microsoft.Teams.Api.Entities; | ||
|
|
||
| namespace Microsoft.Teams.Api.Tests.Entities; | ||
|
|
||
| #pragma warning disable ExperimentalTeamsTargeted | ||
| public class TargetedMessageInfoEntityTests | ||
| { | ||
| [Fact] | ||
| public void TargetedMessageInfoEntity_JsonSerialize() | ||
| { | ||
| var entity = new TargetedMessageInfoEntity() | ||
| { | ||
| MessageId = "1772129782775" | ||
| }; | ||
|
|
||
| var json = JsonSerializer.Serialize(entity, new JsonSerializerOptions() | ||
| { | ||
| WriteIndented = true, | ||
| IndentSize = 2, | ||
| DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull | ||
| }); | ||
|
|
||
| Assert.Equal(File.ReadAllText( | ||
| @"../../../Json/Entities/TargetedMessageInfoEntity.json" | ||
| ), json); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TargetedMessageInfoEntity_JsonSerialize_Derived() | ||
| { | ||
| Entity entity = new TargetedMessageInfoEntity() | ||
| { | ||
| MessageId = "1772129782775" | ||
| }; | ||
|
|
||
| var json = JsonSerializer.Serialize(entity, new JsonSerializerOptions() | ||
| { | ||
| WriteIndented = true, | ||
| IndentSize = 2, | ||
| DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull | ||
| }); | ||
|
|
||
| Assert.Equal(File.ReadAllText( | ||
| @"../../../Json/Entities/TargetedMessageInfoEntity.json" | ||
| ), json); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TargetedMessageInfoEntity_JsonDeserialize() | ||
| { | ||
| var json = File.ReadAllText(@"../../../Json/Entities/TargetedMessageInfoEntity.json"); | ||
| var entity = JsonSerializer.Deserialize<TargetedMessageInfoEntity>(json); | ||
|
|
||
| Assert.NotNull(entity); | ||
| Assert.Equal("targetedMessageInfo", entity.Type); | ||
| Assert.Equal("1772129782775", entity.MessageId); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TargetedMessageInfoEntity_JsonDeserialize_Derived() | ||
| { | ||
| var json = File.ReadAllText(@"../../../Json/Entities/TargetedMessageInfoEntity.json"); | ||
| var entity = JsonSerializer.Deserialize<Entity>(json); | ||
|
|
||
| Assert.NotNull(entity); | ||
| Assert.IsType<TargetedMessageInfoEntity>(entity); | ||
|
|
||
| var targeted = (TargetedMessageInfoEntity)entity; | ||
| Assert.Equal("targetedMessageInfo", targeted.Type); | ||
| Assert.Equal("1772129782775", targeted.MessageId); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void AddTargetedMessageInfo_AddsEntity() | ||
| { | ||
| var activity = new MessageActivity("test"); | ||
| activity.AddTargetedMessageInfo("12345"); | ||
|
|
||
| var entity = activity.Entities?.OfType<TargetedMessageInfoEntity>().SingleOrDefault(); | ||
| Assert.NotNull(entity); | ||
| Assert.Equal("12345", entity!.MessageId); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void AddTargetedMessageInfo_DoesNotDuplicate_WhenConcreteEntityExists() | ||
| { | ||
| var activity = new MessageActivity("test") | ||
| .AddEntity(new TargetedMessageInfoEntity { MessageId = "9999" }); | ||
|
|
||
| activity.AddTargetedMessageInfo("12345"); | ||
|
|
||
| var entities = activity.Entities!.OfType<TargetedMessageInfoEntity>().ToList(); | ||
| Assert.Single(entities); | ||
| Assert.Equal("9999", entities[0].MessageId); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void AddTargetedMessageInfo_DoesNotDuplicate_WhenGenericEntityWithMatchingType() | ||
| { | ||
| var activity = new MessageActivity("test") | ||
| .AddEntity(new Entity("targetedMessageInfo")); | ||
|
|
||
| activity.AddTargetedMessageInfo("12345"); | ||
|
|
||
| var entities = activity.Entities!.Where(e => e.Type == "targetedMessageInfo").ToList(); | ||
| Assert.Single(entities); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "type": "targetedMessageInfo", | ||
| "messageId": "1772129782775" | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.