@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
143 lines (142 loc) • 5.07 kB
TypeScript
import { Activity, ActivityLike, ConversationReference, InvokeResponse, SentActivity, TokenExchangeResource, TokenPostResource } from '@microsoft/teams.api';
import { ILogger } from '@microsoft/teams.common/logging';
import { IStorage } from '@microsoft/teams.common/storage';
import { ApiClient, GraphClient } from '../api';
import { ISender, IStreamer } from '../types';
export interface IBaseActivityContextOptions<T extends Activity = Activity, TExtraCtx extends Record<string, any> = Record<string, any>> {
/**
* the app id of the bot
*/
appId: string;
/**
* the inbound activity
*/
activity: T;
/**
* the inbound activity conversation reference
*/
ref: ConversationReference;
/**
* the app logger instance
*/
log: ILogger;
/**
* the api client
*/
api: ApiClient;
/**
* the app graph client
*/
appGraph: GraphClient;
/**
* the user graph client
*/
userGraph: GraphClient;
/**
* app storage instance
*/
storage: IStorage;
/**
* whether the user has provided
* their MSGraph credentials for use
* via `api.user.*`
*/
isSignedIn?: boolean;
/**
* the default connection name to use for the app
* @default `graph`
*/
connectionName: string;
/**
* the user token for the activity context
*/
userToken?: string;
/**
* extra data
*/
[key: string]: any;
/**
* call the next event/middleware handler
*/
next: (context?: IActivityContext & TExtraCtx) => (void | InvokeResponse) | Promise<void | InvokeResponse>;
}
export type IActivityContextOptions<T extends Activity = Activity, TExtraCtx extends Record<string, any> = Record<string, any>> = IBaseActivityContextOptions<T, TExtraCtx> & TExtraCtx;
type SignInOptions = {
/**
* The text to display on the oauth card
* @default `Please Sign In...`
*/
oauthCardText: string;
/**
* The text to display on the sign in button
* @default `Sign In`
*/
signInButtonText: string;
/**
* The sign in link to use in the card
*/
signInLink?: string;
/**
* The connection name to use
*/
connectionName?: string;
/**
* Construct your own sign in activity
* By default, we create a simple oauth card with a sign in button.
* Only use this if you need to fully customize the sign in experience.
*/
overrideSignInActivity?: (tokenExchangeResource?: TokenExchangeResource, tokenPostResource?: TokenPostResource, signInLink?: string) => ActivityLike;
};
export interface IBaseActivityContext<T extends Activity = Activity, TExtraCtx extends Record<string, any> = Record<string, any>> extends IBaseActivityContextOptions<T, TExtraCtx> {
/**
* a stream that can emit activity chunks
*/
stream: IStreamer;
/**
* send an activity to the conversation
* @param activity activity to send
* @param conversationRef optional conversation reference to send the activity to. By default, it will use the activity's conversation reference.
*/
send: (activity: ActivityLike, conversationRef?: ConversationReference) => Promise<SentActivity>;
/**
* reply to the inbound activity
* @param activity activity to send
*/
reply: (activity: ActivityLike) => Promise<SentActivity>;
/**
* trigger user signin flow for the activity sender
* @param options options for the signin flow
*/
signin: (options?: Partial<SignInOptions>) => Promise<string | undefined>;
/**
* sign the activity sender out
* @param name auth connection name, defaults to `graph`
*/
signout: (name?: string) => Promise<void>;
}
export type IActivityContext<T extends Activity = Activity, TExtraContext = unknown> = IBaseActivityContext<T> & (TExtraContext extends Record<string, any> ? TExtraContext : {});
export declare class ActivityContext<T extends Activity = Activity, TExtraCtx extends {} = {}> implements IBaseActivityContext<T, TExtraCtx> {
appId: string;
activity: T;
ref: ConversationReference;
log: ILogger;
api: ApiClient;
appGraph: GraphClient;
userGraph: GraphClient;
storage: IStorage;
stream: IStreamer;
isSignedIn?: boolean;
connectionName: string;
next: (context?: IActivityContext) => (void | InvokeResponse) | Promise<void | InvokeResponse>;
[key: string]: any;
protected _plugin: ISender;
protected _next?: (context?: IActivityContext) => (void | InvokeResponse) | Promise<void | InvokeResponse>;
constructor(plugin: ISender, value: IBaseActivityContextOptions);
send(activity: ActivityLike, conversationRef?: ConversationReference): Promise<SentActivity>;
reply(activity: ActivityLike): Promise<SentActivity>;
signin(options?: Partial<SignInOptions>): Promise<string | undefined>;
signout(connectionName?: string): Promise<void>;
toInterface(): IActivityContext;
private buildBlockQuoteForActivity;
}
export {};