@microsoft/agents-hosting 0.1.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -0
- package/dist/src/activityHandler.d.ts +108 -0
- package/dist/src/activityHandler.js +395 -0
- package/dist/src/activityHandler.js.map +1 -0
- package/dist/src/agent-client/agentClient.d.ts +13 -0
- package/dist/src/agent-client/agentClient.js +75 -0
- package/dist/src/agent-client/agentClient.js.map +1 -0
- package/dist/src/agent-client/expressApi.d.ts +4 -0
- package/dist/src/agent-client/expressApi.js +50 -0
- package/dist/src/agent-client/expressApi.js.map +1 -0
- package/dist/src/agent-client/index.d.ts +2 -0
- package/dist/src/agent-client/index.js +19 -0
- package/dist/src/agent-client/index.js.map +1 -0
- package/dist/src/app/agentApplication.d.ts +47 -0
- package/dist/src/app/agentApplication.js +317 -0
- package/dist/src/app/agentApplication.js.map +1 -0
- package/dist/src/app/appRoute.d.ts +11 -0
- package/dist/src/app/appRoute.js +7 -0
- package/dist/src/app/appRoute.js.map +1 -0
- package/dist/src/app/applicationBuilder.d.ts +18 -0
- package/dist/src/app/applicationBuilder.js +37 -0
- package/dist/src/app/applicationBuilder.js.map +1 -0
- package/dist/src/app/applicationOptions.d.ts +19 -0
- package/dist/src/app/applicationOptions.js +7 -0
- package/dist/src/app/applicationOptions.js.map +1 -0
- package/dist/src/app/attachmentDownloader.d.ts +13 -0
- package/dist/src/app/attachmentDownloader.js +72 -0
- package/dist/src/app/attachmentDownloader.js.map +1 -0
- package/dist/src/app/conversationUpdateEvents.d.ts +5 -0
- package/dist/src/app/conversationUpdateEvents.js +7 -0
- package/dist/src/app/conversationUpdateEvents.js.map +1 -0
- package/dist/src/app/index.d.ts +10 -0
- package/dist/src/app/index.js +27 -0
- package/dist/src/app/index.js.map +1 -0
- package/dist/src/app/inputFileDownloader.d.ts +14 -0
- package/dist/src/app/inputFileDownloader.js +7 -0
- package/dist/src/app/inputFileDownloader.js.map +1 -0
- package/dist/src/app/memory.d.ts +10 -0
- package/dist/src/app/memory.js +7 -0
- package/dist/src/app/memory.js.map +1 -0
- package/dist/src/app/oauth/authenticationOptions.d.ts +7 -0
- package/dist/src/app/oauth/authenticationOptions.js +7 -0
- package/dist/src/app/oauth/authenticationOptions.js.map +1 -0
- package/dist/src/app/oauth/webChatOAuthFlowAppStyle.d.ts +11 -0
- package/dist/src/app/oauth/webChatOAuthFlowAppStyle.js +85 -0
- package/dist/src/app/oauth/webChatOAuthFlowAppStyle.js.map +1 -0
- package/dist/src/app/routeHandler.d.ts +7 -0
- package/dist/src/app/routeHandler.js +7 -0
- package/dist/src/app/routeHandler.js.map +1 -0
- package/dist/src/app/routeSelector.d.ts +7 -0
- package/dist/src/app/routeSelector.js +7 -0
- package/dist/src/app/routeSelector.js.map +1 -0
- package/dist/src/app/turnEvents.d.ts +5 -0
- package/dist/src/app/turnEvents.js +7 -0
- package/dist/src/app/turnEvents.js.map +1 -0
- package/dist/src/app/turnState.d.ts +85 -0
- package/dist/src/app/turnState.js +274 -0
- package/dist/src/app/turnState.js.map +1 -0
- package/dist/src/app/turnStateEntry.d.ts +17 -0
- package/dist/src/app/turnStateEntry.js +39 -0
- package/dist/src/app/turnStateEntry.js.map +1 -0
- package/dist/src/auth/authConfiguration.d.ts +29 -0
- package/dist/src/auth/authConfiguration.js +58 -0
- package/dist/src/auth/authConfiguration.js.map +1 -0
- package/dist/src/auth/authProvider.d.ts +17 -0
- package/dist/src/auth/authProvider.js +7 -0
- package/dist/src/auth/authProvider.js.map +1 -0
- package/dist/src/auth/index.d.ts +4 -0
- package/dist/src/auth/index.js +21 -0
- package/dist/src/auth/index.js.map +1 -0
- package/dist/src/auth/jwt-middleware.d.ts +13 -0
- package/dist/src/auth/jwt-middleware.js +97 -0
- package/dist/src/auth/jwt-middleware.js.map +1 -0
- package/dist/src/auth/msalTokenProvider.d.ts +53 -0
- package/dist/src/auth/msalTokenProvider.js +198 -0
- package/dist/src/auth/msalTokenProvider.js.map +1 -0
- package/dist/src/auth/request.d.ts +15 -0
- package/dist/src/auth/request.js +7 -0
- package/dist/src/auth/request.js.map +1 -0
- package/dist/src/baseAdapter.d.ts +88 -0
- package/dist/src/baseAdapter.js +94 -0
- package/dist/src/baseAdapter.js.map +1 -0
- package/dist/src/cards/animationCard.d.ts +36 -0
- package/dist/src/cards/animationCard.js +7 -0
- package/dist/src/cards/animationCard.js.map +1 -0
- package/dist/src/cards/audioCard.d.ts +36 -0
- package/dist/src/cards/audioCard.js +7 -0
- package/dist/src/cards/audioCard.js.map +1 -0
- package/dist/src/cards/cardFactory.d.ts +123 -0
- package/dist/src/cards/cardFactory.js +225 -0
- package/dist/src/cards/cardFactory.js.map +1 -0
- package/dist/src/cards/cardImage.d.ts +16 -0
- package/dist/src/cards/cardImage.js +7 -0
- package/dist/src/cards/cardImage.js.map +1 -0
- package/dist/src/cards/fact.d.ts +13 -0
- package/dist/src/cards/fact.js +7 -0
- package/dist/src/cards/fact.js.map +1 -0
- package/dist/src/cards/heroCard.d.ts +23 -0
- package/dist/src/cards/heroCard.js +7 -0
- package/dist/src/cards/heroCard.js.map +1 -0
- package/dist/src/cards/index.d.ts +17 -0
- package/dist/src/cards/index.js +34 -0
- package/dist/src/cards/index.js.map +1 -0
- package/dist/src/cards/mediaUrl.d.ts +17 -0
- package/dist/src/cards/mediaUrl.js +7 -0
- package/dist/src/cards/mediaUrl.js.map +1 -0
- package/dist/src/cards/o365ConnectorCard.d.ts +35 -0
- package/dist/src/cards/o365ConnectorCard.js +7 -0
- package/dist/src/cards/o365ConnectorCard.js.map +1 -0
- package/dist/src/cards/o365ConnectorCardActionBase.d.ts +22 -0
- package/dist/src/cards/o365ConnectorCardActionBase.js +7 -0
- package/dist/src/cards/o365ConnectorCardActionBase.js.map +1 -0
- package/dist/src/cards/o365ConnectorCardFact.d.ts +17 -0
- package/dist/src/cards/o365ConnectorCardFact.js +7 -0
- package/dist/src/cards/o365ConnectorCardFact.js.map +1 -0
- package/dist/src/cards/o365ConnectorCardImage.d.ts +17 -0
- package/dist/src/cards/o365ConnectorCardImage.js +7 -0
- package/dist/src/cards/o365ConnectorCardImage.js.map +1 -0
- package/dist/src/cards/o365ConnectorCardSection.d.ts +57 -0
- package/dist/src/cards/o365ConnectorCardSection.js +7 -0
- package/dist/src/cards/o365ConnectorCardSection.js.map +1 -0
- package/dist/src/cards/receiptCard.d.ts +44 -0
- package/dist/src/cards/receiptCard.js +7 -0
- package/dist/src/cards/receiptCard.js.map +1 -0
- package/dist/src/cards/receiptItem.d.ts +39 -0
- package/dist/src/cards/receiptItem.js +7 -0
- package/dist/src/cards/receiptItem.js.map +1 -0
- package/dist/src/cards/signinCard.d.ts +14 -0
- package/dist/src/cards/signinCard.js +5 -0
- package/dist/src/cards/signinCard.js.map +1 -0
- package/dist/src/cards/taskModuleAction.d.ts +43 -0
- package/dist/src/cards/taskModuleAction.js +30 -0
- package/dist/src/cards/taskModuleAction.js.map +1 -0
- package/dist/src/cards/thumbnailCard.d.ts +35 -0
- package/dist/src/cards/thumbnailCard.js +7 -0
- package/dist/src/cards/thumbnailCard.js.map +1 -0
- package/dist/src/cards/thumbnailUrl.d.ts +17 -0
- package/dist/src/cards/thumbnailUrl.js +7 -0
- package/dist/src/cards/thumbnailUrl.js.map +1 -0
- package/dist/src/cards/videoCard.d.ts +60 -0
- package/dist/src/cards/videoCard.js +7 -0
- package/dist/src/cards/videoCard.js.map +1 -0
- package/dist/src/claimsIdentity.d.ts +35 -0
- package/dist/src/claimsIdentity.js +43 -0
- package/dist/src/claimsIdentity.js.map +1 -0
- package/dist/src/cloudAdapter.d.ts +128 -0
- package/dist/src/cloudAdapter.js +376 -0
- package/dist/src/cloudAdapter.js.map +1 -0
- package/dist/src/connector-client/attachmentData.d.ts +25 -0
- package/dist/src/connector-client/attachmentData.js +7 -0
- package/dist/src/connector-client/attachmentData.js.map +1 -0
- package/dist/src/connector-client/attachmentInfo.d.ts +22 -0
- package/dist/src/connector-client/attachmentInfo.js +7 -0
- package/dist/src/connector-client/attachmentInfo.js.map +1 -0
- package/dist/src/connector-client/attachmentView.d.ts +17 -0
- package/dist/src/connector-client/attachmentView.js +7 -0
- package/dist/src/connector-client/attachmentView.js.map +1 -0
- package/dist/src/connector-client/connectorClient.d.ts +93 -0
- package/dist/src/connector-client/connectorClient.js +249 -0
- package/dist/src/connector-client/connectorClient.js.map +1 -0
- package/dist/src/connector-client/conversationMembers.d.ts +18 -0
- package/dist/src/connector-client/conversationMembers.js +7 -0
- package/dist/src/connector-client/conversationMembers.js.map +1 -0
- package/dist/src/connector-client/conversationParameters.d.ts +38 -0
- package/dist/src/connector-client/conversationParameters.js +7 -0
- package/dist/src/connector-client/conversationParameters.js.map +1 -0
- package/dist/src/connector-client/conversationResourceResponse.d.ts +21 -0
- package/dist/src/connector-client/conversationResourceResponse.js +7 -0
- package/dist/src/connector-client/conversationResourceResponse.js.map +1 -0
- package/dist/src/connector-client/conversationsResult.d.ts +18 -0
- package/dist/src/connector-client/conversationsResult.js +7 -0
- package/dist/src/connector-client/conversationsResult.js.map +1 -0
- package/dist/src/connector-client/index.d.ts +9 -0
- package/dist/src/connector-client/index.js +26 -0
- package/dist/src/connector-client/index.js.map +1 -0
- package/dist/src/connector-client/resourceResponse.d.ts +13 -0
- package/dist/src/connector-client/resourceResponse.js +7 -0
- package/dist/src/connector-client/resourceResponse.js.map +1 -0
- package/dist/src/index.d.ts +26 -0
- package/dist/src/index.js +45 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/invoke/adaptiveCardAuthentication.d.ts +10 -0
- package/dist/src/invoke/adaptiveCardAuthentication.js +7 -0
- package/dist/src/invoke/adaptiveCardAuthentication.js.map +1 -0
- package/dist/src/invoke/adaptiveCardInvokeResponse.d.ts +21 -0
- package/dist/src/invoke/adaptiveCardInvokeResponse.js +7 -0
- package/dist/src/invoke/adaptiveCardInvokeResponse.js.map +1 -0
- package/dist/src/invoke/adaptiveCardInvokeValue.d.ts +23 -0
- package/dist/src/invoke/adaptiveCardInvokeValue.js +7 -0
- package/dist/src/invoke/adaptiveCardInvokeValue.js.map +1 -0
- package/dist/src/invoke/index.d.ts +9 -0
- package/dist/src/invoke/index.js +26 -0
- package/dist/src/invoke/index.js.map +1 -0
- package/dist/src/invoke/invokeException.d.ts +24 -0
- package/dist/src/invoke/invokeException.js +35 -0
- package/dist/src/invoke/invokeException.js.map +1 -0
- package/dist/src/invoke/invokeResponse.d.ts +17 -0
- package/dist/src/invoke/invokeResponse.js +7 -0
- package/dist/src/invoke/invokeResponse.js.map +1 -0
- package/dist/src/invoke/searchInvokeOptions.d.ts +17 -0
- package/dist/src/invoke/searchInvokeOptions.js +7 -0
- package/dist/src/invoke/searchInvokeOptions.js.map +1 -0
- package/dist/src/invoke/searchInvokeResponse.d.ts +10 -0
- package/dist/src/invoke/searchInvokeResponse.js +7 -0
- package/dist/src/invoke/searchInvokeResponse.js.map +1 -0
- package/dist/src/invoke/searchInvokeValue.d.ts +26 -0
- package/dist/src/invoke/searchInvokeValue.js +7 -0
- package/dist/src/invoke/searchInvokeValue.js.map +1 -0
- package/dist/src/invoke/tokenExchangeInvokeRequest.d.ts +21 -0
- package/dist/src/invoke/tokenExchangeInvokeRequest.js +7 -0
- package/dist/src/invoke/tokenExchangeInvokeRequest.js.map +1 -0
- package/dist/src/logger.d.ts +12 -0
- package/dist/src/logger.js +42 -0
- package/dist/src/logger.js.map +1 -0
- package/dist/src/messageFactory.d.ts +62 -0
- package/dist/src/messageFactory.js +143 -0
- package/dist/src/messageFactory.js.map +1 -0
- package/dist/src/middlewareSet.d.ts +43 -0
- package/dist/src/middlewareSet.js +57 -0
- package/dist/src/middlewareSet.js.map +1 -0
- package/dist/src/oauth/index.d.ts +7 -0
- package/dist/src/oauth/index.js +24 -0
- package/dist/src/oauth/index.js.map +1 -0
- package/dist/src/oauth/oauthCard.d.ts +28 -0
- package/dist/src/oauth/oauthCard.js +5 -0
- package/dist/src/oauth/oauthCard.js.map +1 -0
- package/dist/src/oauth/signingResource.d.ts +19 -0
- package/dist/src/oauth/signingResource.js +5 -0
- package/dist/src/oauth/signingResource.js.map +1 -0
- package/dist/src/oauth/tokenExchangeRequest.d.ts +17 -0
- package/dist/src/oauth/tokenExchangeRequest.js +5 -0
- package/dist/src/oauth/tokenExchangeRequest.js.map +1 -0
- package/dist/src/oauth/tokenExchangeResource.d.ts +17 -0
- package/dist/src/oauth/tokenExchangeResource.js +5 -0
- package/dist/src/oauth/tokenExchangeResource.js.map +1 -0
- package/dist/src/oauth/tokenPostResource.d.ts +9 -0
- package/dist/src/oauth/tokenPostResource.js +5 -0
- package/dist/src/oauth/tokenPostResource.js.map +1 -0
- package/dist/src/oauth/userTokenClient.d.ts +49 -0
- package/dist/src/oauth/userTokenClient.js +117 -0
- package/dist/src/oauth/userTokenClient.js.map +1 -0
- package/dist/src/oauth/webChatOAuthFlow.d.ts +41 -0
- package/dist/src/oauth/webChatOAuthFlow.js +117 -0
- package/dist/src/oauth/webChatOAuthFlow.js.map +1 -0
- package/dist/src/state/agentState.d.ts +71 -0
- package/dist/src/state/agentState.js +122 -0
- package/dist/src/state/agentState.js.map +1 -0
- package/dist/src/state/agentStatePropertyAccesor.d.ts +39 -0
- package/dist/src/state/agentStatePropertyAccesor.js +60 -0
- package/dist/src/state/agentStatePropertyAccesor.js.map +1 -0
- package/dist/src/state/conversationState.d.ts +18 -0
- package/dist/src/state/conversationState.js +38 -0
- package/dist/src/state/conversationState.js.map +1 -0
- package/dist/src/state/index.d.ts +4 -0
- package/dist/src/state/index.js +21 -0
- package/dist/src/state/index.js.map +1 -0
- package/dist/src/state/userState.d.ts +18 -0
- package/dist/src/state/userState.js +38 -0
- package/dist/src/state/userState.js.map +1 -0
- package/dist/src/statusCodes.d.ts +19 -0
- package/dist/src/statusCodes.js +24 -0
- package/dist/src/statusCodes.js.map +1 -0
- package/dist/src/storage/index.d.ts +2 -0
- package/dist/src/storage/index.js +19 -0
- package/dist/src/storage/index.js.map +1 -0
- package/dist/src/storage/memoryStorage.d.ts +50 -0
- package/dist/src/storage/memoryStorage.js +100 -0
- package/dist/src/storage/memoryStorage.js.map +1 -0
- package/dist/src/storage/storage.d.ts +47 -0
- package/dist/src/storage/storage.js +7 -0
- package/dist/src/storage/storage.js.map +1 -0
- package/dist/src/tokenResponseEventName.d.ts +5 -0
- package/dist/src/tokenResponseEventName.js +9 -0
- package/dist/src/tokenResponseEventName.js.map +1 -0
- package/dist/src/transcript/consoleTranscriptLogger.d.ts +13 -0
- package/dist/src/transcript/consoleTranscriptLogger.js +21 -0
- package/dist/src/transcript/consoleTranscriptLogger.js.map +1 -0
- package/dist/src/transcript/index.d.ts +4 -0
- package/dist/src/transcript/index.js +21 -0
- package/dist/src/transcript/index.js.map +1 -0
- package/dist/src/transcript/transcriptLogger.d.ts +42 -0
- package/dist/src/transcript/transcriptLogger.js +3 -0
- package/dist/src/transcript/transcriptLogger.js.map +1 -0
- package/dist/src/transcript/transcriptLoggerMiddleware.d.ts +38 -0
- package/dist/src/transcript/transcriptLoggerMiddleware.js +126 -0
- package/dist/src/transcript/transcriptLoggerMiddleware.js.map +1 -0
- package/dist/src/transcript/transcriptStore.d.ts +30 -0
- package/dist/src/transcript/transcriptStore.js +3 -0
- package/dist/src/transcript/transcriptStore.js.map +1 -0
- package/dist/src/turnContext.d.ts +160 -0
- package/dist/src/turnContext.js +286 -0
- package/dist/src/turnContext.js.map +1 -0
- package/dist/src/turnContextStateCollection.d.ts +29 -0
- package/dist/src/turnContextStateCollection.js +56 -0
- package/dist/src/turnContextStateCollection.js.map +1 -0
- package/package.json +48 -0
- package/src/activityHandler.ts +461 -0
- package/src/agent-client/agentClient.ts +84 -0
- package/src/agent-client/expressApi.ts +59 -0
- package/src/agent-client/index.ts +2 -0
- package/src/app/agentApplication.ts +401 -0
- package/src/app/appRoute.ts +13 -0
- package/src/app/applicationBuilder.ts +42 -0
- package/src/app/applicationOptions.ts +21 -0
- package/src/app/attachmentDownloader.ts +83 -0
- package/src/app/conversationUpdateEvents.ts +8 -0
- package/src/app/index.ts +10 -0
- package/src/app/inputFileDownloader.ts +17 -0
- package/src/app/memory.ts +14 -0
- package/src/app/oauth/authenticationOptions.ts +8 -0
- package/src/app/oauth/webChatOAuthFlowAppStyle.ts +90 -0
- package/src/app/routeHandler.ts +9 -0
- package/src/app/routeSelector.ts +10 -0
- package/src/app/turnEvents.ts +6 -0
- package/src/app/turnState.ts +338 -0
- package/src/app/turnStateEntry.ts +46 -0
- package/src/auth/authConfiguration.ts +68 -0
- package/src/auth/authProvider.ts +19 -0
- package/src/auth/index.ts +4 -0
- package/src/auth/jwt-middleware.ts +99 -0
- package/src/auth/msalTokenProvider.ts +202 -0
- package/src/auth/request.ts +20 -0
- package/src/baseAdapter.ts +174 -0
- package/src/cards/animationCard.ts +38 -0
- package/src/cards/audioCard.ts +38 -0
- package/src/cards/cardFactory.ts +276 -0
- package/src/cards/cardImage.ts +18 -0
- package/src/cards/fact.ts +14 -0
- package/src/cards/heroCard.ts +25 -0
- package/src/cards/index.ts +17 -0
- package/src/cards/mediaUrl.ts +18 -0
- package/src/cards/o365ConnectorCard.ts +37 -0
- package/src/cards/o365ConnectorCardActionBase.ts +24 -0
- package/src/cards/o365ConnectorCardFact.ts +18 -0
- package/src/cards/o365ConnectorCardImage.ts +18 -0
- package/src/cards/o365ConnectorCardSection.ts +60 -0
- package/src/cards/receiptCard.ts +46 -0
- package/src/cards/receiptItem.ts +41 -0
- package/src/cards/signinCard.ts +18 -0
- package/src/cards/taskModuleAction.ts +61 -0
- package/src/cards/thumbnailCard.ts +37 -0
- package/src/cards/thumbnailUrl.ts +18 -0
- package/src/cards/videoCard.ts +62 -0
- package/src/claimsIdentity.ts +47 -0
- package/src/cloudAdapter.ts +431 -0
- package/src/connector-client/attachmentData.ts +26 -0
- package/src/connector-client/attachmentInfo.ts +24 -0
- package/src/connector-client/attachmentView.ts +18 -0
- package/src/connector-client/connectorClient.ts +295 -0
- package/src/connector-client/conversationMembers.ts +20 -0
- package/src/connector-client/conversationParameters.ts +40 -0
- package/src/connector-client/conversationResourceResponse.ts +22 -0
- package/src/connector-client/conversationsResult.ts +20 -0
- package/src/connector-client/index.ts +9 -0
- package/src/connector-client/resourceResponse.ts +14 -0
- package/src/index.ts +31 -0
- package/src/invoke/adaptiveCardAuthentication.ts +13 -0
- package/src/invoke/adaptiveCardInvokeResponse.ts +22 -0
- package/src/invoke/adaptiveCardInvokeValue.ts +25 -0
- package/src/invoke/index.ts +9 -0
- package/src/invoke/invokeException.ts +33 -0
- package/src/invoke/invokeResponse.ts +18 -0
- package/src/invoke/searchInvokeOptions.ts +18 -0
- package/src/invoke/searchInvokeResponse.ts +11 -0
- package/src/invoke/searchInvokeValue.ts +28 -0
- package/src/invoke/tokenExchangeInvokeRequest.ts +22 -0
- package/src/logger.ts +43 -0
- package/src/messageFactory.ts +177 -0
- package/src/middlewareSet.ts +76 -0
- package/src/oauth/index.ts +7 -0
- package/src/oauth/oauthCard.ts +32 -0
- package/src/oauth/signingResource.ts +23 -0
- package/src/oauth/tokenExchangeRequest.ts +20 -0
- package/src/oauth/tokenExchangeResource.ts +20 -0
- package/src/oauth/tokenPostResource.ts +12 -0
- package/src/oauth/userTokenClient.ts +116 -0
- package/src/oauth/webChatOAuthFlow.ts +123 -0
- package/src/state/agentState.ts +142 -0
- package/src/state/agentStatePropertyAccesor.ts +61 -0
- package/src/state/conversationState.ts +42 -0
- package/src/state/index.ts +4 -0
- package/src/state/userState.ts +43 -0
- package/src/statusCodes.ts +20 -0
- package/src/storage/index.ts +2 -0
- package/src/storage/memoryStorage.ts +105 -0
- package/src/storage/storage.ts +52 -0
- package/src/tokenResponseEventName.ts +6 -0
- package/src/transcript/consoleTranscriptLogger.ts +20 -0
- package/src/transcript/index.ts +4 -0
- package/src/transcript/transcriptLogger.ts +45 -0
- package/src/transcript/transcriptLoggerMiddleware.ts +151 -0
- package/src/transcript/transcriptStore.ts +38 -0
- package/src/turnContext.ts +335 -0
- package/src/turnContextStateCollection.ts +69 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright(c) Microsoft Corporation.All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { CardAction } from '@microsoft/agents-activity'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Represents a task module action.
|
|
10
|
+
*/
|
|
11
|
+
export class TaskModuleAction implements CardAction {
|
|
12
|
+
constructor (title: string, value: any) {
|
|
13
|
+
this.type = 'invoke'
|
|
14
|
+
this.title = title
|
|
15
|
+
let data: any
|
|
16
|
+
|
|
17
|
+
if (!value) {
|
|
18
|
+
data = JSON.parse('{}')
|
|
19
|
+
} else if (typeof value === 'object') {
|
|
20
|
+
data = value
|
|
21
|
+
} else {
|
|
22
|
+
data = JSON.parse(value)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
data.type = 'task/fetch'
|
|
26
|
+
this.value = data as string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The type of the action.
|
|
31
|
+
*/
|
|
32
|
+
type: string
|
|
33
|
+
/**
|
|
34
|
+
* The title of the action.
|
|
35
|
+
*/
|
|
36
|
+
title: string
|
|
37
|
+
/**
|
|
38
|
+
* The image associated with the action.
|
|
39
|
+
*/
|
|
40
|
+
image?: string | undefined
|
|
41
|
+
/**
|
|
42
|
+
* The text associated with the action.
|
|
43
|
+
*/
|
|
44
|
+
text?: string | undefined
|
|
45
|
+
/**
|
|
46
|
+
* The display text of the action.
|
|
47
|
+
*/
|
|
48
|
+
displayText?: string | undefined
|
|
49
|
+
/**
|
|
50
|
+
* The value of the action.
|
|
51
|
+
*/
|
|
52
|
+
value: unknown
|
|
53
|
+
/**
|
|
54
|
+
* The channel data of the action.
|
|
55
|
+
*/
|
|
56
|
+
channelData?: unknown
|
|
57
|
+
/**
|
|
58
|
+
* The alt text for the image.
|
|
59
|
+
*/
|
|
60
|
+
imageAltText?: string | undefined
|
|
61
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright(c) Microsoft Corporation.All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { CardAction } from '@microsoft/agents-activity'
|
|
7
|
+
import { CardImage } from './cardImage'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Represents a thumbnail card.
|
|
11
|
+
*/
|
|
12
|
+
export interface ThumbnailCard {
|
|
13
|
+
/**
|
|
14
|
+
* The title of the card.
|
|
15
|
+
*/
|
|
16
|
+
title: string
|
|
17
|
+
/**
|
|
18
|
+
* The subtitle of the card.
|
|
19
|
+
*/
|
|
20
|
+
subtitle: string
|
|
21
|
+
/**
|
|
22
|
+
* The text of the card.
|
|
23
|
+
*/
|
|
24
|
+
text: string
|
|
25
|
+
/**
|
|
26
|
+
* The images of the card.
|
|
27
|
+
*/
|
|
28
|
+
images: CardImage[]
|
|
29
|
+
/**
|
|
30
|
+
* The buttons of the card.
|
|
31
|
+
*/
|
|
32
|
+
buttons: CardAction[]
|
|
33
|
+
/**
|
|
34
|
+
* The tap action of the card.
|
|
35
|
+
*/
|
|
36
|
+
tap: CardAction
|
|
37
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright(c) Microsoft Corporation.All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Represents a thumbnail URL.
|
|
8
|
+
*/
|
|
9
|
+
export interface ThumbnailUrl {
|
|
10
|
+
/**
|
|
11
|
+
* The URL of the thumbnail.
|
|
12
|
+
*/
|
|
13
|
+
url: string;
|
|
14
|
+
/**
|
|
15
|
+
* The alternative text for the thumbnail.
|
|
16
|
+
*/
|
|
17
|
+
alt?: string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright(c) Microsoft Corporation.All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { CardAction } from '@microsoft/agents-activity'
|
|
7
|
+
import { MediaUrl } from './mediaUrl'
|
|
8
|
+
import { ThumbnailUrl } from './thumbnailUrl'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Represents a video card.
|
|
12
|
+
*/
|
|
13
|
+
export interface VideoCard {
|
|
14
|
+
/**
|
|
15
|
+
* The title of the video card.
|
|
16
|
+
*/
|
|
17
|
+
title: string
|
|
18
|
+
/**
|
|
19
|
+
* The subtitle of the video card.
|
|
20
|
+
*/
|
|
21
|
+
subtitle: string
|
|
22
|
+
/**
|
|
23
|
+
* The text of the video card.
|
|
24
|
+
*/
|
|
25
|
+
text: string
|
|
26
|
+
/**
|
|
27
|
+
* The image thumbnail of the video card.
|
|
28
|
+
*/
|
|
29
|
+
image: ThumbnailUrl
|
|
30
|
+
/**
|
|
31
|
+
* The media URLs of the video card.
|
|
32
|
+
*/
|
|
33
|
+
media: MediaUrl[]
|
|
34
|
+
/**
|
|
35
|
+
* The buttons of the video card.
|
|
36
|
+
*/
|
|
37
|
+
buttons: CardAction[]
|
|
38
|
+
/**
|
|
39
|
+
* Indicates whether the video card is shareable.
|
|
40
|
+
*/
|
|
41
|
+
shareable: boolean
|
|
42
|
+
/**
|
|
43
|
+
* Indicates whether the video card should auto-loop.
|
|
44
|
+
*/
|
|
45
|
+
autoloop: boolean
|
|
46
|
+
/**
|
|
47
|
+
* Indicates whether the video card should auto-start.
|
|
48
|
+
*/
|
|
49
|
+
autostart: boolean
|
|
50
|
+
/**
|
|
51
|
+
* The aspect ratio of the video card.
|
|
52
|
+
*/
|
|
53
|
+
aspect: string
|
|
54
|
+
/**
|
|
55
|
+
* The duration of the video card.
|
|
56
|
+
*/
|
|
57
|
+
duration: string
|
|
58
|
+
/**
|
|
59
|
+
* The value of the video card.
|
|
60
|
+
*/
|
|
61
|
+
value: any
|
|
62
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Represents a claim with a type and value.
|
|
8
|
+
*/
|
|
9
|
+
export interface Claim {
|
|
10
|
+
readonly type: string;
|
|
11
|
+
readonly value: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Represents an identity with a collection of claims.
|
|
16
|
+
*/
|
|
17
|
+
export class ClaimsIdentity {
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new instance of the ClaimsIdentity class.
|
|
20
|
+
* @param claims The collection of claims associated with the identity.
|
|
21
|
+
* @param authenticationType The type of authentication used, or a boolean indicating if the identity is authenticated.
|
|
22
|
+
*/
|
|
23
|
+
constructor (public readonly claims: Claim[], private readonly authenticationType?: string | boolean) {}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Indicates whether the identity is authenticated.
|
|
27
|
+
* @returns True if the identity is authenticated; otherwise, false.
|
|
28
|
+
*/
|
|
29
|
+
get isAuthenticated (): boolean {
|
|
30
|
+
if (typeof this.authenticationType === 'boolean') {
|
|
31
|
+
return this.authenticationType
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return this.authenticationType != null
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Gets the value of a claim by its type.
|
|
39
|
+
* @param claimType The type of the claim to retrieve.
|
|
40
|
+
* @returns The value of the claim, or null if the claim is not found.
|
|
41
|
+
*/
|
|
42
|
+
getClaimValue (claimType: string): string | null {
|
|
43
|
+
const claim = this.claims.find((c) => c.type === claimType)
|
|
44
|
+
|
|
45
|
+
return claim?.value ?? null
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { AgentHandler, INVOKE_RESPONSE_KEY } from './activityHandler'
|
|
7
|
+
import { BaseAdapter } from './baseAdapter'
|
|
8
|
+
import { TurnContext } from './turnContext'
|
|
9
|
+
import { Response } from 'express'
|
|
10
|
+
import { Request } from './auth/request'
|
|
11
|
+
import { ConnectorClient } from './connector-client/connectorClient'
|
|
12
|
+
import { AuthConfiguration } from './auth/authConfiguration'
|
|
13
|
+
import { AuthProvider } from './auth/authProvider'
|
|
14
|
+
import { Activity, ActivityEventNames, ActivityTypes, Channels, ConversationReference, DeliveryModes } from '@microsoft/agents-activity'
|
|
15
|
+
import { ResourceResponse } from './connector-client/resourceResponse'
|
|
16
|
+
import { MsalTokenProvider } from './auth/msalTokenProvider'
|
|
17
|
+
import { ConversationParameters } from './connector-client/conversationParameters'
|
|
18
|
+
import * as uuid from 'uuid'
|
|
19
|
+
import { debug } from './logger'
|
|
20
|
+
import { StatusCodes } from './statusCodes'
|
|
21
|
+
import { InvokeResponse } from './invoke/invokeResponse'
|
|
22
|
+
import { AttachmentInfo } from './connector-client/attachmentInfo'
|
|
23
|
+
import { AttachmentData } from './connector-client/attachmentData'
|
|
24
|
+
|
|
25
|
+
const logger = debug('agents:cloud-adapter')
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Adapter for handling agent interactions.
|
|
29
|
+
*/
|
|
30
|
+
export class CloudAdapter extends BaseAdapter {
|
|
31
|
+
public connectorClient!: ConnectorClient
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Creates an instance of CloudAdapter.
|
|
35
|
+
* @param authConfig - The authentication configuration.
|
|
36
|
+
* @param authProvider - The authentication provider.
|
|
37
|
+
*/
|
|
38
|
+
constructor (authConfig: AuthConfiguration, authProvider?: AuthProvider) {
|
|
39
|
+
super()
|
|
40
|
+
|
|
41
|
+
this.authConfig = authConfig
|
|
42
|
+
|
|
43
|
+
if (authProvider === undefined) {
|
|
44
|
+
this.authProvider = new MsalTokenProvider()
|
|
45
|
+
} else {
|
|
46
|
+
this.authProvider = authProvider
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
protected async createConnectorClient (
|
|
51
|
+
serviceUrl: string,
|
|
52
|
+
scope: string
|
|
53
|
+
): Promise<ConnectorClient> {
|
|
54
|
+
return ConnectorClient.createClientWithAuthAsync(
|
|
55
|
+
serviceUrl,
|
|
56
|
+
this.authConfig,
|
|
57
|
+
this.authProvider,
|
|
58
|
+
scope
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
protected setConnectorClient (
|
|
63
|
+
context: TurnContext
|
|
64
|
+
) {
|
|
65
|
+
context.turnState.set('connectorClient', this.connectorClient)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Creates a TurnContext for the given activity and logic.
|
|
70
|
+
* @param activity - The activity to process.
|
|
71
|
+
* @param logic - The logic to execute.
|
|
72
|
+
* @returns The created TurnContext.
|
|
73
|
+
*/
|
|
74
|
+
createTurnContext (activity: Activity, logic: AgentHandler): TurnContext {
|
|
75
|
+
return new TurnContext(this, activity)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async createTurnContextWithScope (activity: Activity, logic: AgentHandler, scope: string): Promise<TurnContext> {
|
|
79
|
+
this.connectorClient = await ConnectorClient.createClientWithAuthAsync(activity.serviceUrl!, this.authConfig, this.authProvider, scope)
|
|
80
|
+
return new TurnContext(this, activity)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Sends multiple activities to the conversation.
|
|
85
|
+
* @param context - The TurnContext for the current turn.
|
|
86
|
+
* @param activities - The activities to send.
|
|
87
|
+
* @returns A promise representing the array of ResourceResponses for the sent activities.
|
|
88
|
+
*/
|
|
89
|
+
async sendActivities (context: TurnContext, activities: Activity[]): Promise<ResourceResponse[]> {
|
|
90
|
+
if (!context) {
|
|
91
|
+
throw new TypeError('`context` parameter required')
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (!activities) {
|
|
95
|
+
throw new TypeError('`activities` parameter required')
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (activities.length === 0) {
|
|
99
|
+
throw new Error('Expecting one or more activities, but the array was empty.')
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const responses: ResourceResponse[] = []
|
|
103
|
+
for (const activity of activities) {
|
|
104
|
+
delete activity.id
|
|
105
|
+
let response: ResourceResponse = { id: '' }
|
|
106
|
+
|
|
107
|
+
if (activity.type === ActivityTypes.Delay) {
|
|
108
|
+
await setTimeout(() => { }, typeof activity.value === 'number' ? activity.value : 1000)
|
|
109
|
+
} else if (activity.type === ActivityTypes.InvokeResponse) {
|
|
110
|
+
context.turnState.set(INVOKE_RESPONSE_KEY, activity)
|
|
111
|
+
} else if (activity.type === ActivityTypes.Trace && activity.channelId !== Channels.Emulator) {
|
|
112
|
+
// no-op
|
|
113
|
+
} else {
|
|
114
|
+
if (!activity.serviceUrl || (activity.conversation == null) || !activity.conversation.id) {
|
|
115
|
+
throw new Error('Invalid activity object')
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (activity.replyToId) {
|
|
119
|
+
response = await this.connectorClient.replyToActivityAsync(activity.conversation.id, activity.replyToId, activity)
|
|
120
|
+
} else {
|
|
121
|
+
response = await this.connectorClient.sendToConversationAsync(activity.conversation.id, activity)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (!response) {
|
|
126
|
+
response = { id: activity.id ?? '' }
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
responses.push(response)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return responses
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Replies to an activity.
|
|
137
|
+
* @param activity - The activity to reply to.
|
|
138
|
+
* @returns A promise representing the ResourceResponse for the sent activity.
|
|
139
|
+
*/
|
|
140
|
+
async replyToActivity (activity: Activity): Promise<ResourceResponse> {
|
|
141
|
+
if (!activity.serviceUrl || (activity.conversation == null) || !activity.conversation.id || !activity.id) {
|
|
142
|
+
throw new Error('Invalid activity object')
|
|
143
|
+
}
|
|
144
|
+
return await this.connectorClient.replyToActivityAsync(activity.conversation.id, activity.id, activity)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Processes an incoming request and sends the response.
|
|
149
|
+
* @param request - The incoming request.
|
|
150
|
+
* @param res - The response to send.
|
|
151
|
+
* @param logic - The logic to execute.
|
|
152
|
+
*/
|
|
153
|
+
public async process (
|
|
154
|
+
request: Request,
|
|
155
|
+
res: Response,
|
|
156
|
+
logic: (context: TurnContext) => Promise<void>): Promise<void> {
|
|
157
|
+
const end = (status: StatusCodes, body?: unknown, isInvokeResponseOrExpectReplies: boolean = false) => {
|
|
158
|
+
res.status(status)
|
|
159
|
+
if (isInvokeResponseOrExpectReplies) {
|
|
160
|
+
res.setHeader('content-type', 'application/json')
|
|
161
|
+
}
|
|
162
|
+
if (body) {
|
|
163
|
+
res.send(body)
|
|
164
|
+
}
|
|
165
|
+
res.end()
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const activity = Activity.fromObject(request.body!)
|
|
169
|
+
if (!this.isValidChannelActivity(activity)) {
|
|
170
|
+
return end(StatusCodes.BAD_REQUEST)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
logger.debug('Received activity: ', activity)
|
|
174
|
+
|
|
175
|
+
if (
|
|
176
|
+
activity?.type === ActivityTypes.InvokeResponse ||
|
|
177
|
+
activity?.type === ActivityTypes.Invoke ||
|
|
178
|
+
activity?.deliveryMode === DeliveryModes.ExpectReplies
|
|
179
|
+
) {
|
|
180
|
+
const context = this.createTurnContext(activity, logic)
|
|
181
|
+
await this.runMiddleware(context, logic)
|
|
182
|
+
const invokeResponse = this.processTurnResults(context)
|
|
183
|
+
return end(invokeResponse?.status ?? StatusCodes.OK, JSON.stringify(invokeResponse?.body), true)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const scope = request.user?.azp ?? request.user?.appid ?? 'https://api.botframework.com'
|
|
187
|
+
logger.debug('Creating connector client with scope: ', scope)
|
|
188
|
+
this.connectorClient = await this.createConnectorClient(activity.serviceUrl!, scope)
|
|
189
|
+
|
|
190
|
+
const context = this.createTurnContext(activity, logic)
|
|
191
|
+
this.setConnectorClient(context)
|
|
192
|
+
await this.runMiddleware(context, logic)
|
|
193
|
+
const invokeResponse = this.processTurnResults(context)
|
|
194
|
+
|
|
195
|
+
return end(invokeResponse?.status ?? StatusCodes.OK, invokeResponse?.body)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
private isValidChannelActivity (activity: Activity): Boolean {
|
|
199
|
+
if (activity == null) {
|
|
200
|
+
logger.warn('BadRequest: Missing activity')
|
|
201
|
+
return false
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (activity.type == null || activity.type === '') {
|
|
205
|
+
logger.warn('BadRequest: Missing activity type')
|
|
206
|
+
return false
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (activity.conversation?.id == null || activity.conversation?.id === '') {
|
|
210
|
+
logger.warn('BadRequest: Missing conversation.Id')
|
|
211
|
+
return false
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return true
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Updates an activity.
|
|
219
|
+
* @param context - The TurnContext for the current turn.
|
|
220
|
+
* @param activity - The activity to update.
|
|
221
|
+
* @returns A promise representing the ResourceResponse for the updated activity.
|
|
222
|
+
*/
|
|
223
|
+
async updateActivity (context: TurnContext, activity: Activity): Promise<ResourceResponse | void> {
|
|
224
|
+
if (!context) {
|
|
225
|
+
throw new TypeError('`context` parameter required')
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (!activity) {
|
|
229
|
+
throw new TypeError('`activity` parameter required')
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (!activity.serviceUrl || (activity.conversation == null) || !activity.conversation.id || !activity.id) {
|
|
233
|
+
throw new Error('Invalid activity object')
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const response = await this.connectorClient.updateActivityAsync(
|
|
237
|
+
activity.conversation.id,
|
|
238
|
+
activity.id,
|
|
239
|
+
activity
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
return response.id ? { id: response.id } : undefined
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Deletes an activity.
|
|
247
|
+
* @param context - The TurnContext for the current turn.
|
|
248
|
+
* @param reference - The conversation reference of the activity to delete.
|
|
249
|
+
* @returns A promise representing the completion of the delete operation.
|
|
250
|
+
*/
|
|
251
|
+
async deleteActivity (context: TurnContext, reference: Partial<ConversationReference>): Promise<void> {
|
|
252
|
+
if (!context) {
|
|
253
|
+
throw new TypeError('`context` parameter required')
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (!reference || !reference.serviceUrl || (reference.conversation == null) || !reference.conversation.id || !reference.activityId) {
|
|
257
|
+
throw new Error('Invalid conversation reference object')
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
await this.connectorClient.deleteActivityAsync(reference.conversation.id, reference.activityId)
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Continues a conversation.
|
|
265
|
+
* @param reference - The conversation reference to continue.
|
|
266
|
+
* @param logic - The logic to execute.
|
|
267
|
+
* @returns A promise representing the completion of the continue operation.
|
|
268
|
+
*/
|
|
269
|
+
async continueConversation (reference: ConversationReference, logic: (revocableContext: TurnContext) => Promise<void>, isResponse: Boolean = false): Promise<void> {
|
|
270
|
+
if (!reference || !reference.serviceUrl || (reference.conversation == null) || !reference.conversation.id) {
|
|
271
|
+
throw new Error('Invalid conversation reference object')
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
let context
|
|
275
|
+
if (isResponse) {
|
|
276
|
+
context = await this.createTurnContextWithScope(Activity.getContinuationActivity(reference), logic, 'https://api.botframework.com')
|
|
277
|
+
} else {
|
|
278
|
+
context = this.createTurnContext(Activity.getContinuationActivity(reference), logic)
|
|
279
|
+
}
|
|
280
|
+
await this.runMiddleware(context, logic)
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Processes the turn results and returns an InvokeResponse if applicable.
|
|
285
|
+
* @param context - The TurnContext for the current turn.
|
|
286
|
+
* @returns The InvokeResponse if applicable, otherwise undefined.
|
|
287
|
+
*/
|
|
288
|
+
protected processTurnResults (context: TurnContext): InvokeResponse | undefined {
|
|
289
|
+
// Handle ExpectedReplies scenarios where all activities have been buffered and sent back at once in an invoke response.
|
|
290
|
+
if (context.activity.deliveryMode === DeliveryModes.ExpectReplies) {
|
|
291
|
+
return {
|
|
292
|
+
status: StatusCodes.OK,
|
|
293
|
+
body: {
|
|
294
|
+
activities: context.bufferedReplyActivities
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Handle Invoke scenarios where the agent will return a specific body and return code.
|
|
300
|
+
if (context.activity.type === ActivityTypes.Invoke) {
|
|
301
|
+
const activityInvokeResponse = context.turnState.get<Activity>(INVOKE_RESPONSE_KEY)
|
|
302
|
+
if (!activityInvokeResponse) {
|
|
303
|
+
return { status: StatusCodes.NOT_IMPLEMENTED }
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
return activityInvokeResponse.value as InvokeResponse
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// No body to return.
|
|
310
|
+
return undefined
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Creates an activity to represent the result of creating a conversation.
|
|
315
|
+
* @param createdConversationId - The ID of the created conversation.
|
|
316
|
+
* @param channelId - The channel ID.
|
|
317
|
+
* @param serviceUrl - The service URL.
|
|
318
|
+
* @param conversationParameters - The conversation parameters.
|
|
319
|
+
* @returns The created activity.
|
|
320
|
+
*/
|
|
321
|
+
protected createCreateActivity (
|
|
322
|
+
createdConversationId: string | undefined,
|
|
323
|
+
channelId: string,
|
|
324
|
+
serviceUrl: string,
|
|
325
|
+
conversationParameters: ConversationParameters
|
|
326
|
+
): Activity {
|
|
327
|
+
// Create a conversation update activity to represent the result.
|
|
328
|
+
const activity = new Activity(ActivityTypes.Event)
|
|
329
|
+
|
|
330
|
+
activity.name = ActivityEventNames.CreateConversation
|
|
331
|
+
activity.channelId = channelId
|
|
332
|
+
activity.serviceUrl = serviceUrl
|
|
333
|
+
activity.id = createdConversationId ?? uuid.v4()
|
|
334
|
+
activity.conversation = {
|
|
335
|
+
conversationType: undefined,
|
|
336
|
+
id: createdConversationId!,
|
|
337
|
+
isGroup: conversationParameters.isGroup,
|
|
338
|
+
name: undefined,
|
|
339
|
+
tenantId: conversationParameters.tenantId,
|
|
340
|
+
}
|
|
341
|
+
activity.channelData = conversationParameters.channelData
|
|
342
|
+
activity.recipient = conversationParameters.bot
|
|
343
|
+
|
|
344
|
+
return activity
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Creates a conversation.
|
|
349
|
+
* @param agentAppId - The agent application ID.
|
|
350
|
+
* @param channelId - The channel ID.
|
|
351
|
+
* @param serviceUrl - The service URL.
|
|
352
|
+
* @param audience - The audience.
|
|
353
|
+
* @param conversationParameters - The conversation parameters.
|
|
354
|
+
* @param logic - The logic to execute.
|
|
355
|
+
* @returns A promise representing the completion of the create operation.
|
|
356
|
+
*/
|
|
357
|
+
async createConversationAsync (
|
|
358
|
+
agentAppId: string,
|
|
359
|
+
channelId: string,
|
|
360
|
+
serviceUrl: string,
|
|
361
|
+
audience: string,
|
|
362
|
+
conversationParameters: ConversationParameters,
|
|
363
|
+
logic: (context: TurnContext) => Promise<void>
|
|
364
|
+
): Promise<void> {
|
|
365
|
+
if (typeof serviceUrl !== 'string' || !serviceUrl) {
|
|
366
|
+
throw new TypeError('`serviceUrl` must be a non-empty string')
|
|
367
|
+
}
|
|
368
|
+
if (!conversationParameters) throw new TypeError('`conversationParameters` must be defined')
|
|
369
|
+
if (!logic) throw new TypeError('`logic` must be defined')
|
|
370
|
+
|
|
371
|
+
const restClient = await this.createConnectorClient(serviceUrl, audience)
|
|
372
|
+
const createConversationResult = await restClient.createConversationAsync(conversationParameters)
|
|
373
|
+
const createActivity = this.createCreateActivity(
|
|
374
|
+
createConversationResult.id,
|
|
375
|
+
channelId,
|
|
376
|
+
serviceUrl,
|
|
377
|
+
conversationParameters
|
|
378
|
+
)
|
|
379
|
+
const context = new TurnContext(this, createActivity)
|
|
380
|
+
await this.runMiddleware(context, logic)
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Uploads an attachment.
|
|
385
|
+
* @param conversationId - The conversation ID.
|
|
386
|
+
* @param attachmentData - The attachment data.
|
|
387
|
+
* @returns A promise representing the ResourceResponse for the uploaded attachment.
|
|
388
|
+
*/
|
|
389
|
+
async uploadAttachment (conversationId: string, attachmentData: AttachmentData): Promise<ResourceResponse> {
|
|
390
|
+
if (conversationId === undefined) {
|
|
391
|
+
throw new Error('conversationId is required')
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
if (attachmentData === undefined) {
|
|
395
|
+
throw new Error('attachmentData is required')
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
return await this.connectorClient.uploadAttachment(conversationId, attachmentData)
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Gets attachment information.
|
|
403
|
+
* @param attachmentId - The attachment ID.
|
|
404
|
+
* @returns A promise representing the AttachmentInfo for the requested attachment.
|
|
405
|
+
*/
|
|
406
|
+
async getAttachmentInfo (attachmentId: string): Promise<AttachmentInfo> {
|
|
407
|
+
if (attachmentId === undefined) {
|
|
408
|
+
throw new Error('attachmentId is required')
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
return await this.connectorClient.getAttachmentInfo(attachmentId)
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Gets an attachment.
|
|
416
|
+
* @param attachmentId - The attachment ID.
|
|
417
|
+
* @param viewId - The view ID.
|
|
418
|
+
* @returns A promise representing the NodeJS.ReadableStream for the requested attachment.
|
|
419
|
+
*/
|
|
420
|
+
async getAttachment (attachmentId: string, viewId: string): Promise<NodeJS.ReadableStream> {
|
|
421
|
+
if (attachmentId === undefined) {
|
|
422
|
+
throw new Error('attachmentId is required')
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
if (viewId === undefined) {
|
|
426
|
+
throw new Error('viewId is required')
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
return await this.connectorClient.getAttachment(attachmentId, viewId)
|
|
430
|
+
}
|
|
431
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Represents the data of an attachment.
|
|
8
|
+
*/
|
|
9
|
+
export interface AttachmentData {
|
|
10
|
+
/**
|
|
11
|
+
* The type of the attachment.
|
|
12
|
+
*/
|
|
13
|
+
type: string;
|
|
14
|
+
/**
|
|
15
|
+
* The name of the attachment.
|
|
16
|
+
*/
|
|
17
|
+
name: string;
|
|
18
|
+
/**
|
|
19
|
+
* The original data of the attachment in Base64 format.
|
|
20
|
+
*/
|
|
21
|
+
originalBase64: Uint8Array;
|
|
22
|
+
/**
|
|
23
|
+
* The thumbnail data of the attachment in Base64 format.
|
|
24
|
+
*/
|
|
25
|
+
thumbnailBase64: Uint8Array;
|
|
26
|
+
}
|