UNPKG

@microsoft/agents-hosting-teams

Version:

Microsoft 365 Agents SDK for JavaScript

101 lines (100 loc) 6.24 kB
/** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ import { Activity } from '@microsoft/agents-activity'; import { RouteSelector, TurnContext, TurnState } from '@microsoft/agents-hosting'; import { TeamsApplication } from '../teamsApplication'; import { TaskModuleTaskInfo } from '../../task/taskModuleTaskInfo'; import { MessagingExtensionResult } from '../../messaging-extension/messagingExtensionResult'; import { Query } from '../query'; /** * The MessageExtensions class provides methods to handle various messaging extension scenarios in a Teams application. * It allows developers to define handlers for different invoke activities such as queries, task fetches, and message previews. * @template TState - The type of the TurnState used in the application. */ export declare class MessageExtensions<TState extends TurnState> { private readonly _app; /** * Creates an instance of MessageExtensions. * @param app - The TeamsApplication instance to associate with this MessageExtensions instance. */ constructor(app: TeamsApplication<TState>); /** * Registers a handler for the anonymous query link invoke activity. * @param handler - A function to handle the anonymous query link. * @returns The TeamsApplication instance. */ anonymousQueryLink(handler: (context: TurnContext, state: TState, url: string) => Promise<MessagingExtensionResult>): TeamsApplication<TState>; /** * Registers a handler for editing a message preview. * @param commandId - The command ID(s) or selector(s) to match the activity. * @param handler - A function to handle the message preview edit. * @returns The TeamsApplication instance. */ messagePreviewEdit(commandId: string | RegExp | RouteSelector | (string | RegExp | RouteSelector)[], handler: (context: TurnContext, state: TState, previewActivity: Partial<Activity>) => Promise<MessagingExtensionResult | TaskModuleTaskInfo | string | null | undefined>): TeamsApplication<TState>; /** * Registers a handler for sending a message preview. * @param commandId - The command ID(s) or selector(s) to match the activity. * @param handler - A function to handle the message preview send. * @returns The TeamsApplication instance. */ messagePreviewSend(commandId: string | RegExp | RouteSelector | (string | RegExp | RouteSelector)[], handler: (context: TurnContext, state: TState, previewActivity: Partial<Activity>) => Promise<void>): TeamsApplication<TState>; /** * Registers a handler for fetching a task module. * @param commandId - The command ID(s) or selector(s) to match the activity. * @param handler - A function to handle the task fetch. * @returns The TeamsApplication instance. */ fetchTask(commandId: string | RegExp | RouteSelector | (string | RegExp | RouteSelector)[], handler: (context: TurnContext, state: TState) => Promise<TaskModuleTaskInfo | string>): TeamsApplication<TState>; /** * Registers a handler for a query invoke activity. * @param commandId - The command ID(s) or selector(s) to match the activity. * @param handler - A function to handle the query. * @returns The TeamsApplication instance. */ query<TParams extends Record<string, any> = Record<string, any>>(commandId: string | RegExp | RouteSelector | (string | RegExp | RouteSelector)[], handler: (context: TurnContext, state: TState, query: Query<TParams>) => Promise<MessagingExtensionResult>): TeamsApplication<TState>; /** * Registers a handler for a query link invoke activity. * @param handler - A function to handle the query link. * @returns The TeamsApplication instance. */ queryLink(handler: (context: TurnContext, state: TState, url: string) => Promise<MessagingExtensionResult>): TeamsApplication<TState>; /** * Registers a handler for selecting an item in a messaging extension. * @param handler - A function to handle the item selection. * @returns The TeamsApplication instance. */ selectItem<TItem extends Record<string, any> = Record<string, any>>(handler: (context: TurnContext, state: TState, item: TItem) => Promise<MessagingExtensionResult>): TeamsApplication<TState>; /** * Registers a handler for submitting an action in a messaging extension. * @param commandId - The command ID(s) or selector(s) to match the activity. * @param handler - A function to handle the action submission. * @returns The TeamsApplication instance. */ submitAction<TData extends Record<string, any>>(commandId: string | RegExp | RouteSelector | (string | RegExp | RouteSelector)[], handler: (context: TurnContext, state: TState, data: TData) => Promise<MessagingExtensionResult | TaskModuleTaskInfo | string | null | undefined>): TeamsApplication<TState>; /** * Sends a response for a submit action invoke activity. * @param context - The TurnContext of the activity. * @param result - The result to send in the response. */ private returnSubmitActionResponse; /** * Registers a handler for querying a URL setting in a messaging extension. * @param handler - A function to handle the URL setting query. * @returns The TeamsApplication instance. */ queryUrlSetting(handler: (context: TurnContext, state: TState) => Promise<MessagingExtensionResult>): TeamsApplication<TState>; /** * Registers a handler for configuring settings in a messaging extension. * @param handler - A function to handle the settings configuration. * @returns The TeamsApplication instance. */ configureSettings<TData extends Record<string, any>>(handler: (context: TurnContext, state: TState, settings: TData) => Promise<void>): TeamsApplication<TState>; /** * Registers a handler for handling button clicks in a messaging extension card. * @param handler - A function to handle the button click. * @returns The TeamsApplication instance. */ handleOnButtonClicked<TData extends Record<string, any>>(handler: (context: TurnContext, state: TState, data: TData) => Promise<void>): TeamsApplication<TState>; }