Documentation - v1.2.0-alpha.3
    Preparing search index...

    Module @microsoft/agents-hosting

    microsoft/agents-hosting

    The @microsoft/agents-hosting package provides the necessary tools and components to create and host Microsoft Agents. This package includes a compatible API to migrate a bot using botbuilder from the BotFramework SDK.

    To install the package:

    npm install @microsoft/agents-hosting
    
    import { AgentApplication, MemoryStorage, TurnContext, TurnState } from '@microsoft/agents-hosting'

    const echo = new AgentApplication<TurnState>({ storage: new MemoryStorage() })
    echo.onConversationUpdate('membersAdded', async (context: TurnContext) => {
    await context.sendActivity('Welcome to the Echo sample, send a message to see the echo feature in action.')
    })
    echo.onActivity('message', async (context: TurnContext, state: TurnState) => {
    let counter: number = state.getValue('conversation.counter') || 0
    await context.sendActivity(`[${counter++}]You said: ${context.activity.text}`)
    state.setValue('conversation.counter', counter)
    })

    Create an Echo bot using the ActivityHandler

    // myHandler.ts
    import { ActivityHandler, MessageFactory } from '@microsoft/agents-hosting'

    export class MyHandler extends ActivityHandler {
    constructor () {
    super()
    this.onMessage(async (context, next) => {
    const replyText = `Agent: ${context.activity.text}`
    await context.sendActivity(MessageFactory.text(replyText))
    await next()
    })
    }
    }

    Host the bot with express

    // index.ts
    import express, { Response } from 'express'
    import { Request, CloudAdapter, authorizeJWT, AuthConfiguration, loadAuthConfigFromEnv } from '@microsoft/agents-hosting'
    import { EchoBot } from './myHandler'

    const authConfig: AuthConfiguration = loadAuthConfigFromEnv()

    const adapter = new CloudAdapter(authConfig)
    const myHandler = new MyHandler()

    const app = express()

    app.use(express.json())
    app.use(authorizeJWT(authConfig))

    app.post('/api/messages', async (req: Request, res: Response) => {
    await adapter.process(req, res, async (context) => await myHandler.run(context))
    })

    Enumerations

    AdaptiveCardActionExecuteResponseType
    RouteRank
    StatusCodes
    StreamingResponseResult

    Classes

    ActivityHandler
    AdaptiveCardsActions
    AgentApplication
    AgentApplicationBuilder
    AgentClient
    AgentExtension
    AgentState
    AgentStatePropertyAccessor
    AttachmentDownloader
    BaseAdapter
    CardFactory
    CloudAdapter
    ConnectorClient
    ConsoleTranscriptLogger
    ConversationState
    FileStorage
    HeaderPropagation
    InvokeException
    MemoryStorage
    MessageFactory
    MiddlewareSet
    MsalConnectionManager
    MsalTokenCredential
    MsalTokenProvider
    RouteList
    StreamingResponse
    TaskModuleAction
    TeamsAttachmentDownloader
    TranscriptLoggerMiddleware
    TurnContext
    TurnContextStateCollection
    TurnState
    TurnStateEntry
    UserState
    UserTokenClient

    Interfaces

    AadResourceUrls
    AdaptiveCard
    AdaptiveCardAuthentication
    AdaptiveCardInvokeResponse
    AdaptiveCardInvokeValue
    AdaptiveCardSearchResult
    AdaptiveCardsOptions
    AdaptiveCardsSearchParams
    AgentApplicationOptions
    AgentClientConfig
    AnimationCard
    AppMemory
    AppRoute
    AttachmentData
    AttachmentInfo
    AttachmentView
    AudioCard
    AuthConfiguration
    Authorization
    AuthProvider
    CachedAgentState
    CardImage
    Citation
    ConnectionMapItem
    ConversationData
    ConversationMembers
    ConversationResourceResponse
    ConversationsResult
    CustomKey
    DefaultConversationState
    DefaultUserState
    Fact
    HeaderPropagationCollection
    HeaderPropagationDefinition
    HeroCard
    InputFile
    InputFileDownloader
    InvokeResponse
    MediaUrl
    Middleware
    O365ConnectorCard
    O365ConnectorCardActionBase
    O365ConnectorCardFact
    O365ConnectorCardImage
    O365ConnectorCardSection
    OAuthCard
    PagedResult
    Query
    ReceiptCard
    ReceiptItem
    Request
    ResourceResponse
    SearchInvokeOptions
    SearchInvokeResponse
    SearchInvokeValue
    SignInResource
    StatePropertyAccessor
    Storage
    StoreItem
    StoreItems
    ThumbnailCard
    ThumbnailUrl
    TokenExchangeInvokeRequest
    TokenExchangeInvokeResponse
    TokenExchangeRequest
    TokenExchangeResource
    TokenOrSinginResourceResponse
    TokenPostResource
    TokenResponse
    TokenStatus
    TranscriptInfo
    TranscriptLogger
    TranscriptStore
    VideoCard

    Type Aliases

    ActivityImageType
    AgentHandler
    ApplicationEventHandler
    ConversationUpdateEvents
    DeleteActivityHandler
    MiddlewareHandler
    O365ConnectorCardActionType
    RouteHandler
    RouteSelector
    Selector
    SendActivitiesHandler
    StorageKeyFactory
    TurnEvents
    UpdateActivityHandler

    Variables

    ACTION_INVOKE_NAME
    adaptiveCardsSearchParamsZodSchema
    AgentCallbackHandlerKey
    ApxDevScope
    ApxDoDScope
    ApxGallatinScope
    ApxGCCHScope
    ApxGCCScope
    ApxLocalScope
    ApxProductionScope
    HostingErrors
    INVOKE_RESPONSE_KEY
    loadPrevAuthConfigFromEnv

    Functions

    authorizeJWT
    configureResponseController
    getAuthConfigWithDefaults
    getProductInfo
    loadAuthConfigFromEnv