-
Notifications
You must be signed in to change notification settings - Fork 16
Add Api Clients with Reactions and Targeted Message support #334
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: next/core
Are you sure you want to change the base?
Changes from all commits
7a92aaf
ce1a868
0ce027b
31731d8
b8e3cae
4a720ff
60f210e
97015ec
c5e9025
27e0058
4cf5f8f
83a0491
d0fa89a
d70704c
5e1187a
a4e0914
3f4d38d
c7664c4
74f3a26
f03fc62
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 |
|---|---|---|
|
|
@@ -9,6 +9,8 @@ | |
| # local app settings files | ||
| appsettings.Local.json | ||
|
|
||
| .claude/ | ||
|
|
||
| # User-specific files | ||
| *.rsuser | ||
| *.suo | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,195 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Microsoft.Teams.Bot.Apps.Schema; | ||
| using Microsoft.Teams.Bot.Core; | ||
| using Microsoft.Teams.Bot.Core.Schema; | ||
|
|
||
| namespace Microsoft.Teams.Bot.Apps.Api; | ||
|
|
||
| using CustomHeaders = Dictionary<string, string>; | ||
|
|
||
| /// <summary> | ||
| /// Provides activity operations for sending, updating, and deleting activities in conversations. | ||
| /// </summary> | ||
| public class ActivitiesApi | ||
| { | ||
| private readonly ConversationClient _client; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="ActivitiesApi"/> class. | ||
| /// </summary> | ||
| /// <param name="conversationClient">The conversation client for activity operations.</param> | ||
| internal ActivitiesApi(ConversationClient conversationClient) | ||
| { | ||
| _client = conversationClient; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Sends an activity to a conversation. | ||
| /// </summary> | ||
| /// <param name="activity">The activity to send. Must contain valid conversation and service URL information.</param> | ||
| /// <param name="customHeaders">Optional custom headers to include in the request.</param> | ||
| /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param> | ||
| /// <returns>A task that represents the asynchronous operation. The task result contains the response with the ID of the sent activity.</returns> | ||
| public Task<SendActivityResponse> SendAsync( | ||
| CoreActivity activity, | ||
| CustomHeaders? customHeaders = null, | ||
| CancellationToken cancellationToken = default) | ||
| => _client.SendActivityAsync(activity, customHeaders, cancellationToken); | ||
|
|
||
| /// <summary> | ||
| /// Updates an existing activity in a conversation. | ||
| /// </summary> | ||
| /// <param name="conversationId">The ID of the conversation.</param> | ||
| /// <param name="activityId">The ID of the activity to update.</param> | ||
| /// <param name="activity">The updated activity data.</param> | ||
| /// <param name="customHeaders">Optional custom headers to include in the request.</param> | ||
| /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param> | ||
| /// <returns>A task that represents the asynchronous operation. The task result contains the response with the ID of the updated activity.</returns> | ||
| public Task<UpdateActivityResponse> UpdateAsync( | ||
| string conversationId, | ||
| string activityId, | ||
| CoreActivity activity, | ||
| CustomHeaders? customHeaders = null, | ||
| CancellationToken cancellationToken = default) | ||
| => _client.UpdateActivityAsync(conversationId, activityId, activity, customHeaders, cancellationToken); | ||
|
|
||
| /// <summary> | ||
| /// Deletes an existing activity from a conversation. | ||
| /// </summary> | ||
| /// <param name="conversationId">The ID of the conversation.</param> | ||
| /// <param name="activityId">The ID of the activity to delete.</param> | ||
| /// <param name="serviceUrl">The service URL for the conversation.</param> | ||
| /// <param name="agenticIdentity">Optional agentic identity for authentication.</param> | ||
| /// <param name="customHeaders">Optional custom headers to include in the request.</param> | ||
| /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param> | ||
| /// <returns>A task that represents the asynchronous operation.</returns> | ||
| public Task DeleteAsync( | ||
| string conversationId, | ||
| string activityId, | ||
| Uri serviceUrl, | ||
| AgenticIdentity? agenticIdentity = null, | ||
| CustomHeaders? customHeaders = null, | ||
| CancellationToken cancellationToken = default) | ||
| => _client.DeleteActivityAsync(conversationId, activityId, serviceUrl, agenticIdentity, customHeaders, cancellationToken); | ||
|
|
||
| /// <summary> | ||
| /// Deletes an existing activity from a conversation using activity context. | ||
| /// </summary> | ||
| /// <param name="activity">The activity to delete. Must contain valid Id, Conversation.Id, and ServiceUrl.</param> | ||
| /// <param name="customHeaders">Optional custom headers to include in the request.</param> | ||
| /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param> | ||
| /// <returns>A task that represents the asynchronous operation.</returns> | ||
| public Task DeleteAsync( | ||
| CoreActivity activity, | ||
| CustomHeaders? customHeaders = null, | ||
| CancellationToken cancellationToken = default) | ||
| => _client.DeleteActivityAsync(activity, customHeaders, cancellationToken); | ||
|
|
||
| /// <summary> | ||
| /// Deletes an existing activity from a conversation using Teams activity context. | ||
| /// </summary> | ||
| /// <param name="activity">The Teams activity to delete. Must contain valid Id, Conversation.Id, and ServiceUrl.</param> | ||
| /// <param name="customHeaders">Optional custom headers to include in the request.</param> | ||
| /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param> | ||
| /// <returns>A task that represents the asynchronous operation.</returns> | ||
| public Task DeleteAsync( | ||
|
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. Why do we need this overload for teamsactivity ?
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. good point, having the overload defeats the benefits of polymorphism |
||
| TeamsActivity activity, | ||
| CustomHeaders? customHeaders = null, | ||
| CancellationToken cancellationToken = default) | ||
| => _client.DeleteActivityAsync(activity, customHeaders, cancellationToken); | ||
|
|
||
| /// <summary> | ||
| /// Uploads and sends historic activities to a conversation. | ||
| /// </summary> | ||
| /// <param name="conversationId">The ID of the conversation.</param> | ||
| /// <param name="transcript">The transcript containing the historic activities.</param> | ||
| /// <param name="serviceUrl">The service URL for the conversation.</param> | ||
| /// <param name="agenticIdentity">Optional agentic identity for authentication.</param> | ||
| /// <param name="customHeaders">Optional custom headers to include in the request.</param> | ||
| /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param> | ||
| /// <returns>A task that represents the asynchronous operation. The task result contains the response with a resource ID.</returns> | ||
| public Task<SendConversationHistoryResponse> SendHistoryAsync( | ||
| string conversationId, | ||
| Transcript transcript, | ||
| Uri serviceUrl, | ||
| AgenticIdentity? agenticIdentity = null, | ||
| CustomHeaders? customHeaders = null, | ||
| CancellationToken cancellationToken = default) | ||
| => _client.SendConversationHistoryAsync(conversationId, transcript, serviceUrl, agenticIdentity, customHeaders, cancellationToken); | ||
|
|
||
| /// <summary> | ||
| /// Uploads and sends historic activities to a conversation using activity context. | ||
| /// </summary> | ||
| /// <param name="activity">The activity providing conversation context. Must contain valid Conversation.Id and ServiceUrl.</param> | ||
| /// <param name="transcript">The transcript containing the historic activities.</param> | ||
| /// <param name="customHeaders">Optional custom headers to include in the request.</param> | ||
| /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param> | ||
| /// <returns>A task that represents the asynchronous operation. The task result contains the response with a resource ID.</returns> | ||
| public Task<SendConversationHistoryResponse> SendHistoryAsync( | ||
| TeamsActivity activity, | ||
| Transcript transcript, | ||
| CustomHeaders? customHeaders = null, | ||
| CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(activity); | ||
| ArgumentNullException.ThrowIfNull(activity.Conversation); | ||
| ArgumentNullException.ThrowIfNull(activity.Conversation.Id); | ||
| ArgumentNullException.ThrowIfNull(activity.ServiceUrl); | ||
|
|
||
| return _client.SendConversationHistoryAsync( | ||
| activity.Conversation.Id, | ||
| transcript, | ||
| activity.ServiceUrl, | ||
| activity.From?.GetAgenticIdentity(), | ||
| customHeaders, | ||
| cancellationToken); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the members of a specific activity. | ||
| /// </summary> | ||
| /// <param name="conversationId">The ID of the conversation.</param> | ||
| /// <param name="activityId">The ID of the activity.</param> | ||
| /// <param name="serviceUrl">The service URL for the conversation.</param> | ||
| /// <param name="agenticIdentity">Optional agentic identity for authentication.</param> | ||
| /// <param name="customHeaders">Optional custom headers to include in the request.</param> | ||
| /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param> | ||
| /// <returns>A task that represents the asynchronous operation. The task result contains a list of members for the activity.</returns> | ||
| public Task<IList<ConversationAccount>> GetMembersAsync( | ||
|
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. what does "members of a specific activity" even mean? is it members of the conversation in which this activity was posted? |
||
| string conversationId, | ||
| string activityId, | ||
| Uri serviceUrl, | ||
| AgenticIdentity? agenticIdentity = null, | ||
| CustomHeaders? customHeaders = null, | ||
| CancellationToken cancellationToken = default) | ||
| => _client.GetActivityMembersAsync(conversationId, activityId, serviceUrl, agenticIdentity, customHeaders, cancellationToken); | ||
|
|
||
| /// <summary> | ||
| /// Gets the members of a specific activity using activity context. | ||
| /// </summary> | ||
| /// <param name="activity">The activity to get members for. Must contain valid Id, Conversation.Id, and ServiceUrl.</param> | ||
| /// <param name="customHeaders">Optional custom headers to include in the request.</param> | ||
| /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param> | ||
| /// <returns>A task that represents the asynchronous operation. The task result contains a list of members for the activity.</returns> | ||
| public Task<IList<ConversationAccount>> GetMembersAsync( | ||
| TeamsActivity activity, | ||
| CustomHeaders? customHeaders = null, | ||
| CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(activity); | ||
| ArgumentNullException.ThrowIfNull(activity.Id); | ||
| ArgumentNullException.ThrowIfNull(activity.Conversation); | ||
| ArgumentNullException.ThrowIfNull(activity.Conversation.Id); | ||
| ArgumentNullException.ThrowIfNull(activity.ServiceUrl); | ||
|
Comment on lines
+181
to
+185
|
||
|
|
||
| return _client.GetActivityMembersAsync( | ||
| activity.Conversation.Id, | ||
| activity.Id, | ||
| activity.ServiceUrl, | ||
| activity.From?.GetAgenticIdentity(), | ||
| customHeaders, | ||
| cancellationToken); | ||
| } | ||
| } | ||
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.
Wondering why we have disparity between send and update in extracting conv id/ activity id from activity itself? maybe we should have an overload for it similar to all other apis?