-
Notifications
You must be signed in to change notification settings - Fork 17
Add agentic identity defaults to Teams app API #598
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
Open
heyitsaamir
wants to merge
23
commits into
core/api-flatten
Choose a base branch
from
heyitsaamir-agentic-api-default-identity
base: core/api-flatten
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
6865db6
Add agentic identity defaults to app API
heyitsaamir 932a337
Hide request context from app API defaults
heyitsaamir dbf4f55
Simplify activity identity parameters
heyitsaamir 96505f3
Inline app request context resolution
heyitsaamir cbc4e16
Restore ApiClient doc links
heyitsaamir 81879dd
Add agent XML documentation guidance
heyitsaamir 8acbf2b
Remove Claude instruction file
heyitsaamir ca8467e
Condense XML doc guidance
heyitsaamir 38c7f36
Clarify effective identity request options
heyitsaamir 5a53f89
Inline Teams request options
heyitsaamir e0ba479
Apply identity defaults to flattened API
heyitsaamir 792734d
Add inbound activity API scoping
heyitsaamir 0c2611f
Clarify activity update request context
heyitsaamir c253d96
Clarify agentic tenant documentation
heyitsaamir 521a656
Add API request options for activity calls
heyitsaamir 09bd658
Remove activity additional headers support
heyitsaamir 9815ae0
Rename activity request options
heyitsaamir 55b5fb7
Document breaking change PR guidance
heyitsaamir 1f93eea
Centralize request options conversion
heyitsaamir ffd8251
Add service URL to request options
heyitsaamir 6f99b07
Remove identity service URL overload
heyitsaamir 2dd0b5d
Simplify request options documentation
heyitsaamir 262c2de
Generalize ApiClient defaults documentation
heyitsaamir 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # Agent Instructions | ||
|
|
||
| ## XML documentation | ||
|
|
||
| - Prefer `<see cref="..."/>` for linkable XML doc references, including explicit overloads like `<see cref="ForServiceUrl(Uri)"/>`; use `<c>...</c>` only for inline code formatting. | ||
|
|
||
| ## Pull requests | ||
|
|
||
| - If a change breaks a public-facing API or behavior, call it out explicitly in the PR/review description. |
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 |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| // Licensed under the MIT License. | ||
|
|
||
| using System.Diagnostics.CodeAnalysis; | ||
| using Microsoft.Teams.Apps.Schema; | ||
| using Microsoft.Teams.Core; | ||
| using Microsoft.Teams.Core.Http; | ||
| using Microsoft.Teams.Core.Schema; | ||
|
|
@@ -19,88 +20,117 @@ public class ActivityClient | |
| { | ||
| private readonly CoreConversationClient _client; | ||
| private readonly Uri _serviceUrl; | ||
| private readonly AgenticIdentity? _defaultAgenticIdentity; | ||
|
|
||
| internal ActivityClient(Uri serviceUrl, CoreConversationClient client) | ||
| internal ActivityClient(Uri serviceUrl, CoreConversationClient client, AgenticIdentity? defaultAgenticIdentity = null) | ||
| { | ||
| _serviceUrl = serviceUrl; | ||
| _client = client; | ||
| _defaultAgenticIdentity = defaultAgenticIdentity; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Create a new activity in a conversation. | ||
| /// </summary> | ||
| public Task<SendActivityResponse?> CreateAsync(string conversationId, CoreActivity activity, Dictionary<string, string>? additionalHeaders = null, CancellationToken cancellationToken = default) | ||
| public Task<SendActivityResponse?> CreateAsync(string conversationId, CoreActivity activity, RequestOptions options = default, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(activity); | ||
| activity.ServiceUrl ??= _serviceUrl; | ||
| activity.ServiceUrl ??= options.ServiceUrl ?? _serviceUrl; | ||
| activity.Conversation ??= new Conversation(conversationId); | ||
| return _client.SendActivityAsync(activity, customHeaders: additionalHeaders, cancellationToken: cancellationToken); | ||
| return _client.SendActivityAsync(activity, requestContext: options.ToBotRequestContext(_defaultAgenticIdentity), cancellationToken: cancellationToken); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Update an existing activity in a conversation. | ||
| /// </summary> | ||
| public Task<UpdateActivityResponse> UpdateAsync(string conversationId, string id, CoreActivity activity, Dictionary<string, string>? additionalHeaders = null, CancellationToken cancellationToken = default) | ||
| public Task<UpdateActivityResponse> UpdateAsync(string conversationId, string id, CoreActivity activity, RequestOptions options = default, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(activity); | ||
| activity.ServiceUrl ??= _serviceUrl; | ||
| return _client.UpdateActivityAsync(conversationId, id, activity, requestContext: BotRequestContext.FromActivity(activity), customHeaders: additionalHeaders, cancellationToken: cancellationToken); | ||
| activity.ServiceUrl ??= options.ServiceUrl ?? _serviceUrl; | ||
| BotRequestContext? requestContext = BotRequestContext.Merge( | ||
| options.ToBotRequestContext(_defaultAgenticIdentity), | ||
| BotRequestContext.FromActivity(activity)); | ||
| return _client.UpdateActivityAsync(conversationId, id, activity, requestContext: requestContext, cancellationToken: cancellationToken); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Reply to an existing activity in a conversation. | ||
| /// </summary> | ||
| public Task<SendActivityResponse?> ReplyAsync(string conversationId, string id, CoreActivity activity, Dictionary<string, string>? additionalHeaders = null, CancellationToken cancellationToken = default) | ||
| public Task<SendActivityResponse?> ReplyAsync(string conversationId, string id, CoreActivity activity, RequestOptions options = default, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(activity); | ||
| activity.ReplyToId = id; | ||
| activity.ServiceUrl ??= _serviceUrl; | ||
| activity.ServiceUrl ??= options.ServiceUrl ?? _serviceUrl; | ||
| activity.Conversation ??= new Conversation(conversationId); | ||
| return _client.SendActivityAsync(activity, customHeaders: additionalHeaders, cancellationToken: cancellationToken); | ||
| return _client.SendActivityAsync(activity, requestContext: options.ToBotRequestContext(_defaultAgenticIdentity), cancellationToken: cancellationToken); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Delete an activity from a conversation. | ||
| /// </summary> | ||
| public Task DeleteAsync(string conversationId, string id, AgenticIdentity? agenticIdentity = null, Dictionary<string, string>? additionalHeaders = null, CancellationToken cancellationToken = default) | ||
| public Task DeleteAsync(string conversationId, string id, AgenticIdentity? agenticIdentity = null, CancellationToken cancellationToken = default) | ||
| => DeleteAsync(conversationId, id, new RequestOptions { AgenticIdentity = agenticIdentity }, cancellationToken); | ||
|
|
||
| /// <summary> | ||
| /// Delete an activity from a conversation. | ||
| /// </summary> | ||
| public Task DeleteAsync(string conversationId, string id, RequestOptions options, CancellationToken cancellationToken = default) | ||
| { | ||
| return _client.DeleteActivityAsync(conversationId, id, _serviceUrl, requestContext: BotRequestContext.FromAgenticIdentity(agenticIdentity), customHeaders: additionalHeaders, cancellationToken: cancellationToken); | ||
| return _client.DeleteActivityAsync(conversationId, id, options.ServiceUrl ?? _serviceUrl, requestContext: options.ToBotRequestContext(_defaultAgenticIdentity), cancellationToken: cancellationToken); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Get members of a specific activity. | ||
| /// </summary> | ||
| public async Task<IList<TeamsChannelAccount?>> GetMembersAsync(string conversationId, string id, RequestOptions options = default, CancellationToken cancellationToken = default) | ||
| { | ||
| IList<ChannelAccount> members = await _client.GetActivityMembersAsync(conversationId, id, options.ServiceUrl ?? _serviceUrl, requestContext: options.ToBotRequestContext(_defaultAgenticIdentity), cancellationToken: cancellationToken).ConfigureAwait(false); | ||
| return [.. members.Select(m => TeamsChannelAccount.FromChannelAccount(m))]; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Create a new targeted activity in a conversation. | ||
| /// Targeted activities are only visible to the specified recipient. | ||
| /// </summary> | ||
| [Experimental("ExperimentalTeamsTargeted")] | ||
| public Task<SendActivityResponse?> CreateTargetedAsync(string conversationId, CoreActivity activity, Dictionary<string, string>? additionalHeaders = null, CancellationToken cancellationToken = default) | ||
| public Task<SendActivityResponse?> CreateTargetedAsync(string conversationId, CoreActivity activity, RequestOptions options = default, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(activity); | ||
| activity.ServiceUrl ??= _serviceUrl; | ||
| activity.ServiceUrl ??= options.ServiceUrl ?? _serviceUrl; | ||
| activity.Conversation ??= new Conversation(conversationId); | ||
| // Ensure recipient is marked as targeted | ||
| if (activity.Recipient is not null) | ||
| { | ||
| activity.Recipient.IsTargeted = true; | ||
| } | ||
| return _client.SendActivityAsync(activity, customHeaders: additionalHeaders, cancellationToken: cancellationToken); | ||
| return _client.SendActivityAsync(activity, requestContext: options.ToBotRequestContext(_defaultAgenticIdentity), cancellationToken: cancellationToken); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Update an existing targeted activity in a conversation. | ||
| /// </summary> | ||
| [Experimental("ExperimentalTeamsTargeted")] | ||
| public Task<UpdateActivityResponse> UpdateTargetedAsync(string conversationId, string id, CoreActivity activity, Dictionary<string, string>? additionalHeaders = null, CancellationToken cancellationToken = default) | ||
| public Task<UpdateActivityResponse> UpdateTargetedAsync(string conversationId, string id, CoreActivity activity, RequestOptions options = default, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(activity); | ||
| activity.ServiceUrl ??= _serviceUrl; | ||
| return _client.UpdateTargetedActivityAsync(conversationId, id, activity, requestContext: BotRequestContext.FromActivity(activity), customHeaders: additionalHeaders, cancellationToken: cancellationToken); | ||
| activity.ServiceUrl ??= options.ServiceUrl ?? _serviceUrl; | ||
| BotRequestContext? requestContext = BotRequestContext.Merge( | ||
|
Member
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. add this merge to conversation client in core instead for consistency |
||
| options.ToBotRequestContext(_defaultAgenticIdentity), | ||
| BotRequestContext.FromActivity(activity)); | ||
| return _client.UpdateTargetedActivityAsync(conversationId, id, activity, requestContext: requestContext, cancellationToken: cancellationToken); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Delete a targeted activity from a conversation. | ||
| /// </summary> | ||
| public Task DeleteTargetedAsync(string conversationId, string id, AgenticIdentity? agenticIdentity = null, Dictionary<string, string>? additionalHeaders = null, CancellationToken cancellationToken = default) | ||
| public Task DeleteTargetedAsync(string conversationId, string id, AgenticIdentity? agenticIdentity = null, CancellationToken cancellationToken = default) | ||
| => DeleteTargetedAsync(conversationId, id, new RequestOptions { AgenticIdentity = agenticIdentity }, cancellationToken); | ||
|
|
||
| /// <summary> | ||
| /// Delete a targeted activity from a conversation. | ||
| /// </summary> | ||
| public Task DeleteTargetedAsync(string conversationId, string id, RequestOptions options, CancellationToken cancellationToken = default) | ||
| { | ||
| return _client.DeleteTargetedActivityAsync(conversationId, id, _serviceUrl, requestContext: BotRequestContext.FromAgenticIdentity(agenticIdentity), customHeaders: additionalHeaders, cancellationToken: cancellationToken); | ||
| return _client.DeleteTargetedActivityAsync(conversationId, id, options.ServiceUrl ?? _serviceUrl, requestContext: options.ToBotRequestContext(_defaultAgenticIdentity), cancellationToken: cancellationToken); | ||
| } | ||
| } | ||
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.
same, add merge to core client