-
Notifications
You must be signed in to change notification settings - Fork 16
Add Reactions Feature (Bot to User) #335
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
14 commits
Select commit
Hold shift + click to select a range
6eda85e
Update Reaction.cs
aacebo aa39343
Update Reaction.cs
aacebo 2b3288c
add client
aacebo 780d9a6
Merge branch 'main' into aacebo/bot-reactions
rido-min f017817
Add Samples.Reactions bot and refactor reaction APIs
rido-min 48e5d4c
Address review feedback: fix docs, formatting, and add test coverage …
Copilot 91159ca
Rename CreateOrUpdateAsync to AddAsync in ReactionClient
rido-min 7c58a95
Remove PlusOne reaction type from ReactionType class
rido-min 0ac3b38
Fix JSON structure in launchSettings.TEMPLATE.json
rido-min 03cce3c
Merge branch 'main' into feat/reactions
rido-min be9d910
Update reaction handling and types; improve async API usage
rido-min f1527a0
Update tests to check for "Like" instead of "Angry" reaction
rido-min 1caf0dd
Update ReactionClient API route and docs; rename test
rido-min e78eca2
Merge branch 'main' into feat/reactions
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
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,94 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Microsoft.Teams.Api.Messages; | ||
| using Microsoft.Teams.Common.Http; | ||
|
|
||
| namespace Microsoft.Teams.Api.Clients; | ||
|
|
||
| /// <summary> | ||
| /// Client for working with app message reactions for a given conversation/activity. | ||
| /// </summary> | ||
| public class ReactionClient : Client | ||
| { | ||
| public readonly string ServiceUrl; | ||
|
|
||
| public ReactionClient(string serviceUrl, CancellationToken cancellationToken = default) | ||
| : base(cancellationToken) | ||
| { | ||
| ServiceUrl = serviceUrl; | ||
| } | ||
|
|
||
| public ReactionClient(string serviceUrl, IHttpClient client, CancellationToken cancellationToken = default) | ||
| : base(client, cancellationToken) | ||
| { | ||
| ServiceUrl = serviceUrl; | ||
| } | ||
|
|
||
| public ReactionClient(string serviceUrl, IHttpClientOptions options, CancellationToken cancellationToken = default) | ||
| : base(options, cancellationToken) | ||
| { | ||
| ServiceUrl = serviceUrl; | ||
| } | ||
|
|
||
| public ReactionClient(string serviceUrl, IHttpClientFactory factory, CancellationToken cancellationToken = default) | ||
| : base(factory, cancellationToken) | ||
| { | ||
| ServiceUrl = serviceUrl; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Adds a reaction on an activity in a conversation. | ||
| /// </summary> | ||
| /// <param name="conversationId">The conversation id.</param> | ||
| /// <param name="activityId">The id of the activity to react to.</param> | ||
| /// <param name="reactionType"> | ||
| /// The reaction type (for example: "like", "heart", "launch", etc.). | ||
| /// </param> | ||
rido-min marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param> | ||
| /// <returns> | ||
| /// A <see cref="Task"/> representing the asynchronous operation. | ||
| /// </returns> | ||
| public async Task AddAsync( | ||
| string conversationId, | ||
| string activityId, | ||
| ReactionType reactionType, | ||
| CancellationToken cancellationToken = default | ||
| ) | ||
| { | ||
| // Assumed route: | ||
| // PUT v3/conversations/{conversationId}/activities/{activityId}/reactions/{reactionType} | ||
| var url = $"{ServiceUrl}v3/conversations/{conversationId}/activities/{activityId}/reactions/{reactionType}"; | ||
| var req = HttpRequest.Put(url); | ||
| await _http.SendAsync(req, cancellationToken != default ? cancellationToken : _cancellationToken); | ||
rido-min marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /// <summary> | ||
| /// Removes a reaction from an activity in a conversation. | ||
| /// </summary> | ||
| /// <param name="conversationId">The conversation id.</param> | ||
| /// <param name="activityId">The id of the activity the reaction is on.</param> | ||
| /// <param name="reactionType"> | ||
| /// The reaction type to remove (for example: "like", "heart", "launch", etc.). | ||
| /// </param> | ||
rido-min marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param> | ||
| /// <returns> | ||
| /// A <see cref="Task"/> representing the asynchronous operation. | ||
| /// </returns> | ||
| public async Task DeleteAsync( | ||
| string conversationId, | ||
| string activityId, | ||
| ReactionType reactionType, | ||
| CancellationToken cancellationToken = default | ||
| ) | ||
| { | ||
| // Assumed route: | ||
| // DELETE v3/conversations/{conversationId}/activities/{activityId}/reactions/{reactionType} | ||
| var url = | ||
| $"{ServiceUrl}v3/conversations/{conversationId}/activities/{activityId}/reactions/{reactionType}"; | ||
|
|
||
| var req = HttpRequest.Delete(url); | ||
|
|
||
| await _http.SendAsync(req, cancellationToken != default ? cancellationToken : _cancellationToken); | ||
| } | ||
| } | ||
rido-min marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| using Microsoft.Teams.Api.Clients; | ||
| using Microsoft.Teams.Api.Messages; | ||
| using Microsoft.Teams.Apps.Activities; | ||
| using Microsoft.Teams.Apps.Extensions; | ||
| using Microsoft.Teams.Plugins.AspNetCore.DevTools.Extensions; | ||
| using Microsoft.Teams.Plugins.AspNetCore.Extensions; | ||
|
|
||
| var builder = WebApplication.CreateBuilder(args); | ||
| builder.AddTeams().AddTeamsDevTools(); | ||
| var app = builder.Build(); | ||
| var teams = app.UseTeams(); | ||
|
|
||
|
|
||
| teams.OnMessage(async (context, cancellationToken) => | ||
| { | ||
| await context.Send($"you said '{context.Activity.Text}'", cancellationToken); | ||
|
|
||
| // replace with context.Api.Conversations.Reactions once Reactions client is available in PROD. | ||
| var api = new ApiClient(context.Activity.ServiceUrl!, context.Api.Client, cancellationToken); | ||
|
|
||
| await api.Conversations.Reactions.AddAsync(context.Activity.Conversation.Id, context.Activity.Id, new ReactionType("1f44b_wavinghand-tone4")); | ||
|
|
||
| await Task.Delay(2000, cancellationToken); | ||
| await api.Conversations.Reactions.AddAsync(context.Activity.Conversation.Id, context.Activity.Id, new ReactionType("1f601_beamingfacewithsmilingeyes")); | ||
|
|
||
| await Task.Delay(2000, cancellationToken); | ||
| await api.Conversations.Reactions.DeleteAsync(context.Activity.Conversation.Id, context.Activity.Id, new ReactionType("1f601_beamingfacewithsmilingeyes")); | ||
rido-min marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
rido-min marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| teams.OnMessageReaction(async (context, cancellationToken) => | ||
| { | ||
| context.Log.Info($"Reaction '{context.Activity.ReactionsAdded?.FirstOrDefault()?.Type}' added by {context.Activity.From?.Name}"); | ||
| await context.Send($"you added '{context.Activity.ReactionsAdded?.FirstOrDefault()?.Type}' " + | ||
| $"and removed '{context.Activity.ReactionsRemoved?.FirstOrDefault()?.Type}'", cancellationToken); | ||
| }); | ||
|
|
||
| app.Run(); | ||
16 changes: 16 additions & 0 deletions
16
Samples/Samples.Reactions/Properties/launchSettings.TEMPLATE.json
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,16 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/launchsettings.json", | ||
| "profiles": { | ||
| "bot-config": { | ||
| "commandName": "Project", | ||
| "launchBrowser": false, | ||
| "applicationUrl": "http://localhost:3978", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "Teams__TenantId": "", | ||
| "Teams__ClientId": "", | ||
| "Teams__ClientSecret": "" | ||
| } | ||
| } | ||
| } | ||
| } |
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,14 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\Libraries\Microsoft.Teams.Plugins\Microsoft.Teams.Plugins.AspNetCore.DevTools\Microsoft.Teams.Plugins.AspNetCore.DevTools.csproj" /> | ||
| <ProjectReference Include="..\..\Libraries\Microsoft.Teams.Plugins\Microsoft.Teams.Plugins.AspNetCore\Microsoft.Teams.Plugins.AspNetCore.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
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,9 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| }, | ||
| "AllowedHosts": "*" | ||
| } |
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.