@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
99 lines (98 loc) • 3.4 kB
TypeScript
import { CloudEnvironment, Credentials, InvokeResponse, IToken } from '@microsoft/teams.api';
import { ILogger } from '@microsoft/teams.common';
import { IActivityEvent, ICoreActivity } from '../events';
import { InboundActivityTokenValidator } from '../middleware/auth/inbound-activity-token-validator';
import { HttpMethod, IHttpServerAdapter, IHttpServerRequest, IHttpServerResponse, HttpRouteHandler } from './adapter';
type AuthResult = {
success: true;
token: IToken;
} | {
success: false;
error: string;
};
export type HttpServerOptions = {
/**
* Dangerously allow incoming HTTP requests without Teams service token validation.
*/
readonly dangerouslyAllowUnauthenticatedRequests?: boolean;
readonly logger?: ILogger;
/**
* URL path for the Teams messaging endpoint
*/
readonly messagingEndpoint: string;
};
/**
* Public interface for HttpServer, exposed via DI for plugins
*/
export interface IHttpServer {
handleRequest(request: IHttpServerRequest): Promise<IHttpServerResponse>;
readonly adapter: IHttpServerAdapter;
readonly messagingEndpoint: string;
}
/**
* Configurable HTTP server for receiving Teams activities
*/
export declare class HttpServer implements IHttpServer {
/**
* Callback invoked when a valid activity request arrives
* App should set this to process activities
*/
onRequest?: (event: IActivityEvent) => Promise<InvokeResponse>;
protected logger: ILogger;
protected credentials?: Credentials;
protected cloud?: CloudEnvironment;
protected initialized: boolean;
protected serviceTokenValidator?: InboundActivityTokenValidator;
private dangerouslyAllowUnauthenticatedRequests;
private _adapter;
private _messagingEndpoint;
/**
* Get the underlying adapter
* Useful for plugins that need adapter-specific features
*/
get adapter(): IHttpServerAdapter;
/**
* Get the messaging endpoint path
*/
get messagingEndpoint(): string;
constructor(adapter: IHttpServerAdapter, options: HttpServerOptions);
/**
* Initialize the server with dependencies and register routes.
* Can be called multiple times - only initializes once
* Called by App.initialize()
*/
initialize(deps: {
credentials?: Credentials;
cloud?: CloudEnvironment;
}): Promise<void>;
/**
* Start the HTTP server
* Called by App.start()
*/
start(port: number | string): Promise<void>;
/**
* Stop the HTTP server
* Called by App.stop() if implemented
*/
stop(): Promise<void>;
/**
* Register a route handler with the adapter
* Used by app.function() and other app methods
*/
registerRoute(method: HttpMethod, path: string, handler: HttpRouteHandler): void;
/**
* Serve static files from a directory
* Used by app.tab() and other app methods
*/
serveStatic(path: string, directory: string): void;
/**
* Handle incoming activity request
* Validates the inbound JWT, dispatches to the app, and returns the response.
*/
handleRequest(request: IHttpServerRequest): Promise<IHttpServerResponse>;
/**
* Authorize the request by validating the JWT token.
*/
protected authorize(headers: Record<string, string | string[]>, body: ICoreActivity): Promise<AuthResult>;
}
export {};