-
Notifications
You must be signed in to change notification settings - Fork 16
feat: implement custom feedback form #435
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4fa8bb3
custom feedback loop for dotneT
182eac7
update return val and tested sample
e390f6b
Merge branch 'main' into lilyydu/custom-feedback
lilyydu d0228d9
Update Libraries/Microsoft.Teams.Api/Activities/Activity.cs
lilyydu 6360e7e
Merge branch 'main' into lilyydu/custom-feedback
lilyydu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
Libraries/Microsoft.Teams.Api/Activities/Invokes/Messages/FetchTaskActivity.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Text.Json.Serialization; | ||
|
|
||
| using Microsoft.Teams.Common; | ||
|
|
||
| namespace Microsoft.Teams.Api.Activities.Invokes; | ||
|
|
||
| public partial class Name : StringEnum | ||
| { | ||
| public partial class Messages : StringEnum | ||
| { | ||
| public static readonly Messages FetchTask = new("message/fetchTask"); | ||
| public bool IsFetchTask => FetchTask.Equals(Value); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The feedback button the user clicked. | ||
| /// </summary> | ||
| [JsonConverter(typeof(JsonConverter<Reaction>))] | ||
| public partial class Reaction(string value) : StringEnum(value) | ||
| { | ||
| public static readonly Reaction Like = new("like"); | ||
| public bool IsLike => Like.Equals(Value); | ||
|
|
||
| public static readonly Reaction Dislike = new("dislike"); | ||
| public bool IsDislike => Dislike.Equals(Value); | ||
| } | ||
|
|
||
| public static partial class Messages | ||
| { | ||
| /// <summary> | ||
| /// Sent when a message has a custom feedback loop and the user clicks a | ||
| /// feedback button. The bot should respond with a task module (dialog) to | ||
| /// collect feedback. | ||
| /// </summary> | ||
| public class FetchTaskActivity() : MessageActivity(Name.Messages.FetchTask) | ||
| { | ||
| /// <summary> | ||
| /// A value that is associated with the activity. | ||
| /// </summary> | ||
| [JsonPropertyName("value")] | ||
| [JsonPropertyOrder(32)] | ||
| public new required FetchTaskValue Value | ||
| { | ||
| get => (FetchTaskValue)base.Value!; | ||
| set => base.Value = value; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The value associated with a message fetch task. | ||
| /// </summary> | ||
| public class FetchTaskValue | ||
| { | ||
| /// <summary> | ||
| /// The data payload containing action name and value. | ||
| /// </summary> | ||
| [JsonPropertyName("data")] | ||
| [JsonPropertyOrder(0)] | ||
| public required FetchTaskData Data { get; set; } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The data payload nested inside the fetch task value. | ||
| /// </summary> | ||
| public class FetchTaskData | ||
| { | ||
| /// <summary> | ||
| /// The name of the action. | ||
| /// </summary> | ||
| [JsonPropertyName("actionName")] | ||
| [JsonPropertyOrder(0)] | ||
| public string ActionName { get; set; } = "feedback"; | ||
|
|
||
| /// <summary> | ||
| /// Contains the user's reaction. | ||
| /// </summary> | ||
| [JsonPropertyName("actionValue")] | ||
| [JsonPropertyOrder(1)] | ||
| public required FetchTaskActionValue ActionValue { get; set; } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The nested action value containing the user's reaction. | ||
| /// </summary> | ||
| public class FetchTaskActionValue | ||
| { | ||
| /// <summary> | ||
| /// The feedback button the user clicked. | ||
| /// </summary> | ||
| [JsonPropertyName("reaction")] | ||
| [JsonPropertyOrder(0)] | ||
| public required Reaction Reaction { get; set; } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Text.Json.Serialization; | ||
|
|
||
| using Microsoft.Teams.Common; | ||
|
|
||
| namespace Microsoft.Teams.Api; | ||
|
|
||
| /// <summary> | ||
| /// The type of feedback loop. | ||
| /// Use <c>Custom</c> to trigger a <c>message/fetchTask</c> invoke so the bot | ||
| /// can return its own task module dialog. | ||
| /// Use <c>Default</c> for the standard Teams thumbs up/down UI. | ||
| /// </summary> | ||
| [JsonConverter(typeof(JsonConverter<FeedbackType>))] | ||
| public partial class FeedbackType(string value) : StringEnum(value) | ||
| { | ||
| public static readonly FeedbackType Default = new("default"); | ||
| public bool IsDefault => Default.Equals(Value); | ||
|
|
||
| public static readonly FeedbackType Custom = new("custom"); | ||
| public bool IsCustom => Custom.Equals(Value); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Configuration for a feedback loop on a message. | ||
| /// </summary> | ||
| public class FeedbackLoop | ||
| { | ||
| /// <summary> | ||
| /// The type of feedback loop. | ||
| /// </summary> | ||
| [JsonPropertyName("type")] | ||
| [JsonPropertyOrder(0)] | ||
| public FeedbackType Type { get; set; } = FeedbackType.Default; | ||
|
|
||
| public FeedbackLoop() { } | ||
|
|
||
| public FeedbackLoop(FeedbackType type) | ||
| { | ||
| Type = type; | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
Libraries/Microsoft.Teams.Apps/Activities/Invokes/Messages/FetchTaskActivity.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Microsoft.Teams.Api.Activities; | ||
| using Microsoft.Teams.Api.Activities.Invokes; | ||
| using Microsoft.Teams.Apps.Routing; | ||
|
|
||
| namespace Microsoft.Teams.Apps.Activities.Invokes; | ||
|
|
||
| public static partial class Message | ||
| { | ||
| [AttributeUsage(AttributeTargets.Method, Inherited = true)] | ||
| public class FetchTaskAttribute() : InvokeAttribute(Api.Activities.Invokes.Name.Messages.FetchTask, typeof(Messages.FetchTaskActivity)) | ||
| { | ||
| public override object Coerce(IContext<IActivity> context) => context.ToActivityType<Messages.FetchTaskActivity>(); | ||
| } | ||
| } | ||
|
|
||
| public static partial class AppInvokeActivityExtensions | ||
| { | ||
| /// <summary> | ||
| /// Registers a handler for <c>message/fetchTask</c> activities. | ||
| /// The bot should return a task module response containing the dialog to show the user. | ||
| /// </summary> | ||
| public static App OnMessageFetchTask(this App app, Func<IContext<Messages.FetchTaskActivity>, CancellationToken, Task<Api.TaskModules.Response>> handler) | ||
| { | ||
| app.Router.Register(new Route() | ||
| { | ||
| Name = string.Join("/", [ActivityType.Invoke, Name.Messages.FetchTask]), | ||
| Type = app.Status is null ? RouteType.System : RouteType.User, | ||
| Handler = async context => await handler(context.ToActivityType<Messages.FetchTaskActivity>(), context.CancellationToken), | ||
|
lilyydu marked this conversation as resolved.
|
||
| Selector = activity => activity is Messages.FetchTaskActivity | ||
| }); | ||
|
|
||
| return app; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.