Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions packages/Teams/dotnet/Actions/SendMessageToTeamsChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Runtime.CompilerServices;
using System.Security.Claims;
using System.Threading;
using System.Threading.Tasks;
using AdaptiveExpressions.Properties;
Expand Down Expand Up @@ -118,22 +119,19 @@ public SendMessageToTeamsChannel([CallerFilePath] string callerPath = "", [Calle
teamsChannelId = dc.Context.Activity.TeamsGetChannelId();
}

if (!(dc.Context.Adapter is BotFrameworkAdapter))
// Retrieve the bot appid from TurnState's ClaimsIdentity
string appId;
if (dc.Context.TurnState.Get<ClaimsIdentity>(BotAdapter.BotIdentityKey) is ClaimsIdentity botIdentity)
{
throw new InvalidOperationException($"{Kind} is not supported by the current adapter.");
appId = JwtTokenValidation.GetAppIdFromClaims(botIdentity.Claims);
}

// TODO: this will NOT work with certificate app credentials

// TeamsInfo.SendMessageToTeamsChannelAsync requires AppCredentials
var credentials = dc.Context.TurnState.Get<IConnectorClient>()?.Credentials as MicrosoftAppCredentials;
if (credentials == null)
else
{
throw new InvalidOperationException($"Missing credentials as {nameof(MicrosoftAppCredentials)} in {nameof(IConnectorClient)} from TurnState");
throw new InvalidOperationException($"Missing {BotAdapter.BotIdentityKey} in {nameof(ITurnContext)} TurnState");
}

// The result comes back as a tuple, which is used to set the two properties (if present).
var result = await TeamsInfo.SendMessageToTeamsChannelAsync(dc.Context, activity, teamsChannelId, credentials, cancellationToken: cancellationToken).ConfigureAwait(false);
var result = await TeamsInfo.SendMessageToTeamsChannelAsync(dc.Context, activity, teamsChannelId, appId, cancellationToken: cancellationToken).ConfigureAwait(false);

if (ConversationReferenceProperty != null)
{
Expand Down