UNPKG

@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

98 lines (97 loc) • 3.77 kB
import { ActivityLike, DeprecatedInputActivity, SentActivity } from '@microsoft/teams.api'; import { ILogger } from '@microsoft/teams.common'; import { ApiClient, GraphClient } from '../api'; import { IActivitySender } from '../types'; import { IClientContext } from './client'; export interface IFunctionContext<T = any> extends IClientContext { /** * the api client */ api: ApiClient; /** * the app graph client */ appGraph: GraphClient; /** * the app logger instance */ log: ILogger; /** * the function payload */ data: T; /** * Attempts to find the ID of the conversation in which the app is being used, and verifies that the bot and the * user making the function call are both present in the conversation. Depending on the conversation type, this * is the ID of a chat (for group chats, 1:1 chats and channel meetings), a channel, a meeting, or a user-bot * conversation (when the app is hosted in personal scope). * Returns undefined if the conversation ID cannot be determined or is invalid. */ getCurrentConversationId: () => Promise<string | undefined>; /** * send an activity to the current conversation. * Returns null if the conversation ID cannot be determined or is invalid. * @param activity activity to send */ /** * @deprecated Use MessageActivityInput or TypingActivityInput instead. */ send(activity: DeprecatedInputActivity): Promise<SentActivity | null>; send(activity: ActivityLike): Promise<SentActivity | null>; send(activity: ActivityLike | DeprecatedInputActivity): Promise<SentActivity | null>; } /** * Options used to construct a {@link FunctionContext}. The owning `App` supplies * the client context (resolved from the request's auth token) plus the * collaborators the context needs to resolve a conversation and send activities. */ export type IFunctionContextOptions<T = any> = IClientContext & { readonly api: ApiClient; readonly appGraph: GraphClient; readonly log: ILogger; readonly data: T; readonly activitySender: IActivitySender; /** the bot/app id (credentials clientId) used as the sender; undefined when no credentials are set */ readonly botId?: string; }; /** * Context handed to a remotely-callable function (`app.function`). * * Like {@link ActivityContext}, this is a "smart" context: it owns conversation * resolution and sending rather than having `App` wire those up at registration. * That keeps `App.function` thin and mirrors the Python SDK's `FunctionContext`. */ export declare class FunctionContext<T = any> implements IFunctionContext<T> { appId?: string; appSessionId: string; tenantId: string; userId: string; userName: string; teamId?: string; messageId?: string; channelId?: string; chatId?: string; meetingId?: string; pageId: string; subPageId?: string; authToken: string; api: ApiClient; appGraph: GraphClient; log: ILogger; data: T; readonly getCurrentConversationId: () => Promise<string | undefined>; private readonly activitySender; private readonly botId?; constructor(options: IFunctionContextOptions<T>); /** * send an activity to the current conversation. * Returns null if the conversation ID cannot be determined or is invalid. * @param activity activity to send */ /** * @deprecated Use MessageActivityInput or TypingActivityInput instead. */ send(activity: DeprecatedInputActivity): Promise<SentActivity | null>; send(activity: ActivityLike): Promise<SentActivity | null>; send(activity: ActivityLike | DeprecatedInputActivity): Promise<SentActivity | null>; }