-
Notifications
You must be signed in to change notification settings - Fork 16
Add SuggestedActions support #383
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 all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4648a3d
Add SuggestedActions support to MessageActivity
rido-min e0f8e91
Refactor suggested actions to use SuggestedAction type
rido-min 499bd49
Merge branch 'next/core' into next/core-suggestedactions
rido-min 6052081
Add time-off card, welcome middleware, and event docs
rido-min 9ca8b52
Update help message and remove catch-all echo handler
rido-min c064e51
Add "suggested" command with suggested actions reply
rido-min 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
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
131 changes: 131 additions & 0 deletions
131
core/src/Microsoft.Teams.Bot.Apps/Schema/SuggestedAction.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,131 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Microsoft.Teams.Bot.Apps.Schema; | ||
|
|
||
| /// <summary> | ||
| /// Represents a clickable action | ||
| /// </summary> | ||
| public class SuggestedAction | ||
| { | ||
| /// <summary> | ||
| /// Default constructor for JSON deserialization. | ||
| /// </summary> | ||
| public SuggestedAction() | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="SuggestedAction"/> class with the specified type and title. | ||
| /// </summary> | ||
| /// <param name="type">The type of action. See <see cref="ActionType"/> for common values.</param> | ||
| /// <param name="title">The text description displayed on the button.</param> | ||
| public SuggestedAction(string type, string title) | ||
| { | ||
| Type = type; | ||
| Title = title; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the type of action implemented by this button. | ||
| /// See <see cref="ActionType"/> for common values. | ||
| /// </summary> | ||
| [JsonPropertyName("type")] | ||
| public string? Type { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the text description which appears on the button. | ||
| /// </summary> | ||
| [JsonPropertyName("title")] | ||
| public string? Title { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the image URL which will appear on the button, next to the text label. | ||
| /// </summary> | ||
| [JsonPropertyName("image")] | ||
| public string? Image { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the text for this action. | ||
| /// </summary> | ||
| [JsonPropertyName("text")] | ||
| public string? Text { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the text to display in the chat feed if the button is clicked. | ||
| /// </summary> | ||
| [JsonPropertyName("displayText")] | ||
| public string? DisplayText { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the supplementary parameter for the action. | ||
| /// The content of this property depends on the action type. | ||
| /// </summary> | ||
| [JsonPropertyName("value")] | ||
| public object? Value { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the channel-specific data associated with this action. | ||
| /// </summary> | ||
| [JsonPropertyName("channelData")] | ||
| public object? ChannelData { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the alternate image text to be used in place of the image. | ||
| /// </summary> | ||
| [JsonPropertyName("imageAltText")] | ||
| public string? ImageAltText { get; set; } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// String constants for card action types. | ||
| /// </summary> | ||
| public static class ActionType | ||
| { | ||
| /// <summary> | ||
| /// Opens the specified URL in the browser. | ||
| /// </summary> | ||
| public const string OpenUrl = "openUrl"; | ||
|
|
||
| /// <summary> | ||
| /// Sends a message back to the bot as if the user typed it (visible to all conversation members). | ||
| /// </summary> | ||
| public const string IMBack = "imBack"; | ||
|
|
||
| /// <summary> | ||
| /// Sends a message back to the bot privately (not visible to other conversation members). | ||
| /// </summary> | ||
| public const string PostBack = "postBack"; | ||
|
|
||
| /// <summary> | ||
| /// Plays the specified audio content. | ||
| /// </summary> | ||
| public const string PlayAudio = "playAudio"; | ||
|
|
||
| /// <summary> | ||
| /// Plays the specified video content. | ||
| /// </summary> | ||
| public const string PlayVideo = "playVideo"; | ||
|
|
||
| /// <summary> | ||
| /// Displays the specified image. | ||
| /// </summary> | ||
| public const string ShowImage = "showImage"; | ||
|
|
||
| /// <summary> | ||
| /// Downloads the specified file. | ||
| /// </summary> | ||
| public const string DownloadFile = "downloadFile"; | ||
|
|
||
| /// <summary> | ||
| /// Initiates a sign-in flow. | ||
| /// </summary> | ||
| public const string SignIn = "signin"; | ||
|
|
||
| /// <summary> | ||
| /// Initiates a phone call. | ||
| /// </summary> | ||
| public const string Call = "call"; | ||
| } |
68 changes: 68 additions & 0 deletions
68
core/src/Microsoft.Teams.Bot.Apps/Schema/SuggestedActions.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,68 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Microsoft.Teams.Bot.Apps.Schema; | ||
|
|
||
| /// <summary> | ||
| /// Represents suggested actions that can be shown to the user as quick reply buttons. | ||
| /// </summary> | ||
| public class SuggestedActions | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the IDs of the recipients that the actions should be shown to. | ||
| /// These IDs are relative to the channelId and a subset of all recipients of the activity. | ||
| /// </summary> | ||
| [JsonPropertyName("to")] | ||
| public IList<string> To { get; set; } = []; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the actions that can be shown to the user. | ||
| /// </summary> | ||
| [JsonPropertyName("actions")] | ||
| public IList<SuggestedAction> Actions { get; set; } = []; | ||
|
|
||
| /// <summary> | ||
| /// Adds recipients to the suggested actions. | ||
| /// </summary> | ||
| /// <param name="recipients">The recipient IDs to add.</param> | ||
| /// <returns>This instance for chaining.</returns> | ||
| public SuggestedActions AddRecipients(params string[] recipients) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(recipients); | ||
| foreach (var to in recipients) | ||
| { | ||
| To.Add(to); | ||
| } | ||
|
|
||
| return this; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Adds a single action to the suggested actions. | ||
| /// </summary> | ||
| /// <param name="action">The action to add.</param> | ||
| /// <returns>This instance for chaining.</returns> | ||
| public SuggestedActions AddAction(SuggestedAction action) | ||
| { | ||
| Actions.Add(action); | ||
| return this; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Adds multiple actions to the suggested actions. | ||
| /// </summary> | ||
| /// <param name="actions">The actions to add.</param> | ||
| /// <returns>This instance for chaining.</returns> | ||
| public SuggestedActions AddActions(params SuggestedAction[] actions) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(actions); | ||
| foreach (var action in actions) | ||
| { | ||
| Actions.Add(action); | ||
| } | ||
|
|
||
| return this; | ||
| } | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious to know the motivation behind moving this property to the
TeamsActivityThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b/c the builder works with TeamsActivity, then inheriting in MessageActivity. I have a bigger workitem to reconcile these two.