@microsoft/teams.apps
Version:
<p> <a href="https://www.npmjs.com/package/@microsoft/teams.apps" target="_blank"> <img src="https://img.shields.io/npm/v/@microsoft/teams.apps/latest" /> </a> <a href="https://www.npmjs.com/package/@microsoft/teams.apps?activeTab=code
104 lines (103 loc) • 4.77 kB
TypeScript
import { ApiClientSettings, AgenticIdentity, InvokeResponse, IToken, TokenStatus } from '@microsoft/teams.api';
import { Client as HttpClient, ILogger, IStorage } from '@microsoft/teams.common';
import { type ApiClient } from './api';
import { EventManager } from './app.events';
import { IActivityContext } from './contexts';
import { type IAgent365BaggageOptions } from './diagnostics/agent365-baggage';
import { IActivityEvent } from './events';
import { Router } from './router';
import { TurnStateLoader } from './state';
import { IActivitySender, IPlugin } from './types';
import { PluginAdditionalContext } from './types/app-routing';
/**
* Dependencies the {@link ActivityProcessor} needs to process an inbound activity
* into a response. The owning {@link App} constructs the processor and passes
* these in, which is what lets `App` keep these primitives private instead of
* exposing them just so a free `this: App`-bound `$process` function could reach
* them.
*/
export interface IActivityProcessorOptions<TPlugin extends IPlugin = IPlugin> {
readonly router: Router<PluginAdditionalContext<TPlugin>>;
readonly plugins: ReadonlyArray<TPlugin>;
readonly eventManager: EventManager<TPlugin>;
/**
* Acquires an app-only Microsoft Graph token for a tenant, or `null` when the
* app has no credentials configured.
*/
readonly getAppGraphToken: (tenantId?: string) => Promise<IToken | null>;
/** Acquires a Microsoft Graph token for an Agentic User, or `null` when the app has no credentials or the identity is not user-backed. */
readonly getAgenticGraphToken: (identity: AgenticIdentity, tenantId?: string) => Promise<IToken | null>;
readonly activitySender: IActivitySender;
readonly api: ApiClient;
readonly client: HttpClient;
readonly storage: IStorage;
/**
* Gets the loader used to attach and persist state for each activity turn.
* The loader can become available after an OAuth flow is registered.
*/
readonly getStateLoader: () => TurnStateLoader | undefined;
readonly log: ILogger;
readonly getId: () => string | undefined;
/**
* Gets the connection name used by deprecated context OAuth fields.
*
* @deprecated Registered OAuth flows own their connection names.
*/
readonly getConnectionName: () => string;
/**
* Whether to proactively fetch the legacy default-flow token for each inbound
* activity. The result populates deprecated context OAuth fields.
*
* @deprecated Registered flows fetch tokens only when their methods are called.
*/
readonly shouldFetchUserToken: () => boolean;
/**
* Validates a connection selected through the deprecated activity-context
* OAuth helpers before any token service request is made.
*/
readonly validateOAuthConnection?: (connectionName: string, connectionNameProvided: boolean) => void;
/**
* Records which registered OAuth flow emitted a card through the deprecated
* activity-context sign-in helper.
*/
readonly onOAuthSignInInitiated?: (context: IActivityContext, connectionName: string, supportsSso: boolean) => void | Promise<void>;
/**
* Gets corrected status for all OAuth connections registered on the app.
*/
readonly getOAuthConnectionStatus?: (context: IActivityContext) => Promise<TokenStatus[]>;
readonly apiClientSettings?: ApiClientSettings;
readonly graphBaseUrl?: string;
/**
* Agent365 baggage settings, or `false` to disable the bridge.
*/
readonly agent365Baggage?: IAgent365BaggageOptions | false;
}
/**
* Encapsulates inbound activity processing: building the activity context,
* running the middleware/route chain, wiring streaming + send events, and
* producing the {@link InvokeResponse}.
*
* This replaces the `this: App`-bound `$process` free function. All of its
* collaborators are supplied via the constructor so the processor can be
* reasoned about (and tested) without reaching into `App` internals.
*/
export declare class ActivityProcessor<TPlugin extends IPlugin = IPlugin> {
private readonly options;
constructor(options: IActivityProcessorOptions<TPlugin>);
/**
* activity handler called when an inbound activity is received
* @param event the received activity event
*/
process(event: IActivityEvent): Promise<InvokeResponse>;
private executeTurnLifecycle;
private reportTurnError;
/**
* Runs the inbound turn inside an Agent365 baggage scope derived from the
* activity, unless the bridge is disabled.
*/
private withActivityBaggage;
/**
* fetch the user's token for the given channel/user, if signed in
*/
private getUserToken;
}