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

88 lines (87 loc) • 4.35 kB
import { Client, IMessageActivityInput, MessageActivityInput, SentActivity, Step } from '@microsoft/teams.api'; import { EventEmitter } from '@microsoft/teams.common'; /** * Reply chain (thread) of a chat that a Plan completion is posted to, as for `ctx.send`. * `chatOrChannelId` is `channelData.chat.id` and `replyChainId` is `channelData.replyChain.id`. * * @experimental This API is in preview and may change in the future. * Diagnostic: ExperimentalTeamsPlan */ export type PlanReplyChain = { /** The chat id, `channelData.chat.id`. Not `conversation.id`. */ readonly chatOrChannelId: string; /** The id of the message at the root of the reply chain, `channelData.replyChain.id`. */ readonly replyChainId: string; }; /** * Bind a Plan to its originating prompt and inject the runtime client. * * @experimental This API is in preview and may change in the future. * Diagnostic: ExperimentalTeamsPlan */ export type PlanOptions = { /** Conversation ID, including any thread suffix, used for typing updates and for completion unless `replyChain` is set. */ readonly conversationId: string; /** Original prompt activity ID, not a later event, answer, or stream ID. */ readonly replyToId: string; /** * Reply chain (thread) of a chat that the completion is posted to, as for `ctx.send`. * `chatOrChannelId` is `channelData.chat.id` and `replyChainId` is `channelData.replyChain.id`. * Omit it when `conversationId` already identifies the thread, as in a channel, or when the prompt is not inside a thread. */ readonly replyChain?: PlanReplyChain; /** Runtime-only client, already scoped to the conversation's service URL and caller. */ readonly apiClient: Client; }; /** * Sends prompt-bound Plan activities; the application owns ordering and concurrency. * Serialize the IDs with JSON.stringify() and inject a client when reconstructing. * * Targeted Plan scenarios are not supported. * Plans use ordinary create routing, and completion() does not inherit * targeting from the originating context. * * In a chat thread, complete() is posted to the reply chain like `ctx.send`. * Typing updates (start, update, stop, error) are sent to the conversation, as `ctx.send` does for typing activities. * * @experimental This API is in preview and may change in the future. * Diagnostic: ExperimentalTeamsPlan */ export declare class Plan { /** * Emits the SentActivity once after a successful send, before the method returns. * Listeners are runtime-only and are not serialized. */ readonly events: EventEmitter<{ sent: SentActivity; }>; /** Conversation ID to which this Plan is bound. */ readonly conversationId: string; /** Original prompt ID to which all Plan activities reply. */ readonly replyToId: string; /** Reply chain (thread) to which the completion is posted, if any. */ readonly replyChain?: PlanReplyChain; private readonly api; /** Create a Plan from saved IDs and a configured client; no request or client cloning occurs. */ constructor(options: PlanOptions); /** Serialize only the prompt binding and its placement, excluding the client, credentials, and listeners. */ toJSON(): Pick<PlanOptions, 'conversationId' | 'replyToId' | 'replyChain'>; /** Start the bound Plan with the supplied ordered steps; API failures propagate. */ start(steps: readonly Step[]): Promise<void>; /** Send new or changed steps, with versions incremented by the application. */ update(steps: readonly Step[]): Promise<void>; /** Stop the displayed Plan without canceling application-owned work. */ stop(): Promise<void>; /** Report a failed Plan without canceling application-owned work. */ error(): Promise<void>; /** * Build a fresh completion message without sending or changing this Plan. * Emit it last on a stream for the same conversation, then explicitly close the stream. * The original prompt ID is preserved; use the returned builder to add final metadata. */ completion(): MessageActivityInput; /** Complete with an answer, preserving metadata and rejecting non-complete Plan operations. */ complete(message: string | IMessageActivityInput): Promise<SentActivity>; private sendUpdate; private send; }