// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace Microsoft.Teams.Apps;
///
/// context that comes from client (tab/embed) requests
///
public interface IClientContext
{
///
/// This ID is the unique identifier assigned to the app after deployment and is critical for ensuring the correct app instance is recognized across hosts.
///
public string? AppId { get; }
///
/// Unique ID for the current session for use in correlating telemetry data. A session corresponds to the lifecycle of an app. A new session begins upon the creation of a webview (on Teams mobile) or iframe (in Teams desktop) hosting the app, and ends when it is destroyed.
///
public string AppSessionId { get; }
///
/// The Microsoft Entra tenant ID of the current user, extracted from request auth token.
///
public string TenantId { get; }
///
/// The Microsoft Entra object id of the current user, extracted from the request auth token.
///
public string UserId { get; }
///
/// The name of the current user, extracted from the request auth token.
///
public string UserName { get; }
///
/// The Microsoft Teams ID for the team with which the content is associated.
///
public string? TeamId { get; }
///
/// The ID of the parent message from which this task module was launched.
/// This is only available in task modules launched from bot cards.
///
public string? MessageId { get; }
///
/// The Microsoft Teams ID for the channel with which the content is associated.
///
public string? ChannelId { get; }
///
/// The Microsoft Teams ID for the chat with which the content is associated.
///
public string? ChatId { get; }
///
/// The Microsoft Teams ID for the conversation with which the content is associated.
/// A conversation can be a personal/group chat or channel
///
public string? ConversationId { get; }
///
/// Meeting ID used by tab when running in meeting context
///
public string? MeetingId { get; }
///
/// The developer-defined unique ID for the page this content points to.
///
public string PageId { get; }
///
/// The developer-defined unique ID for the sub-page this content points to.
/// This field should be used to restore to a specific state within a page,
/// such as scrolling to or activating a specific piece of content.
///
public string? SubPageId { get; }
///
/// The MSAL entra token.
///
public string AuthToken { get; }
}
public class ClientContext : IClientContext
{
public string? AppId { get; set; }
public required string AppSessionId { get; set; }
public required string TenantId { get; set; }
public required string UserId { get; set; }
public required string UserName { get; set; }
public string? TeamId { get; set; }
public string? MessageId { get; set; }
public string? ChannelId { get; set; }
public string? ChatId { get; set; }
public string? MeetingId { get; set; }
public required string PageId { get; set; }
public string? SubPageId { get; set; }
public required string AuthToken { get; set; }
public string? ConversationId => ChatId ?? ChannelId;
}