@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,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Represents a token exchange invoke request.
|
|
8
|
+
*/
|
|
9
|
+
export interface TokenExchangeInvokeRequest {
|
|
10
|
+
/**
|
|
11
|
+
* The unique identifier for the request.
|
|
12
|
+
*/
|
|
13
|
+
id: string
|
|
14
|
+
/**
|
|
15
|
+
* The name of the connection.
|
|
16
|
+
*/
|
|
17
|
+
connectionName: string
|
|
18
|
+
/**
|
|
19
|
+
* The token to be exchanged.
|
|
20
|
+
*/
|
|
21
|
+
token: string
|
|
22
|
+
}
|
package/src/logger.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import createDebug, { Debugger } from 'debug'
|
|
2
|
+
|
|
3
|
+
class Logger {
|
|
4
|
+
private loggers: { [level: string]: Debugger } = {}
|
|
5
|
+
private readonly levelColors: { [level: string]: string } = {
|
|
6
|
+
info: '2', // Green
|
|
7
|
+
warn: '3', // Yellow
|
|
8
|
+
error: '1', // Red
|
|
9
|
+
debug: '4' // Blue
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
constructor (namespace: string = '') {
|
|
13
|
+
this.initializeLoggers(namespace)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
private initializeLoggers (namespace: string) {
|
|
17
|
+
for (const level of Object.keys(this.levelColors)) {
|
|
18
|
+
const logger = createDebug(`${namespace}:${level}`)
|
|
19
|
+
logger.color = this.levelColors[level]
|
|
20
|
+
this.loggers[level] = logger
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
info (message: string, ...args: any[]) {
|
|
25
|
+
this.loggers.info(message, ...args)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
warn (message: string, ...args: any[]) {
|
|
29
|
+
this.loggers.warn(message, ...args)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
error (message: string, ...args: any[]) {
|
|
33
|
+
this.loggers.error(message, ...args)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
debug (message: string, ...args: any[]) {
|
|
37
|
+
this.loggers.debug(message, ...args)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function debug (namespace: string): Logger {
|
|
42
|
+
return new Logger(namespace)
|
|
43
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */
|
|
2
|
+
import { ActionTypes, Activity, ActivityTypes, Attachment, AttachmentLayoutTypes, CardAction, InputHints, SuggestedActions } from '@microsoft/agents-activity'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A factory class for creating various types of message activities.
|
|
6
|
+
*/
|
|
7
|
+
export class MessageFactory {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a text message activity.
|
|
10
|
+
* @param text The text of the message.
|
|
11
|
+
* @param speak (Optional) The text to be spoken by the agent.
|
|
12
|
+
* @param inputHint (Optional) The input hint for the message.
|
|
13
|
+
* @returns The created text message activity.
|
|
14
|
+
*/
|
|
15
|
+
static text (text: string, speak?: string, inputHint?: InputHints | string): Activity {
|
|
16
|
+
let msgObj = {}
|
|
17
|
+
msgObj = {
|
|
18
|
+
type: ActivityTypes.Message,
|
|
19
|
+
text,
|
|
20
|
+
inputHint: inputHint || InputHints.AcceptingInput
|
|
21
|
+
}
|
|
22
|
+
if (speak) {
|
|
23
|
+
msgObj = { ...msgObj, speak }
|
|
24
|
+
}
|
|
25
|
+
const msg = Activity.fromObject(msgObj)
|
|
26
|
+
return msg
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Creates a message activity with suggested actions.
|
|
31
|
+
* @param actions The suggested actions.
|
|
32
|
+
* @param text (Optional) The text of the message.
|
|
33
|
+
* @param speak (Optional) The text to be spoken by the agent.
|
|
34
|
+
* @param inputHint (Optional) The input hint for the message.
|
|
35
|
+
* @returns The created message activity with suggested actions.
|
|
36
|
+
*/
|
|
37
|
+
static suggestedActions (
|
|
38
|
+
actions: Array<CardAction | string>,
|
|
39
|
+
text?: string,
|
|
40
|
+
speak?: string,
|
|
41
|
+
inputHint?: InputHints | string
|
|
42
|
+
): Activity {
|
|
43
|
+
const formattedActions: CardAction[] = (actions || []).map((action) => {
|
|
44
|
+
if (typeof action === 'object') {
|
|
45
|
+
return action
|
|
46
|
+
} else {
|
|
47
|
+
return {
|
|
48
|
+
type: ActionTypes.ImBack,
|
|
49
|
+
value: { text: action.toString() },
|
|
50
|
+
title: action.toString(),
|
|
51
|
+
channelData: undefined
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
const msgObj = {
|
|
56
|
+
type: ActivityTypes.Message,
|
|
57
|
+
inputHint: inputHint || InputHints.AcceptingInput,
|
|
58
|
+
suggestedActions: { actions: formattedActions, to: [] } as SuggestedActions
|
|
59
|
+
}
|
|
60
|
+
const msg = Activity.fromObject(msgObj)
|
|
61
|
+
if (text) {
|
|
62
|
+
msg.text = text
|
|
63
|
+
}
|
|
64
|
+
if (speak) {
|
|
65
|
+
msg.speak = speak
|
|
66
|
+
}
|
|
67
|
+
return msg
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Creates a message activity with a single attachment.
|
|
72
|
+
* @param attachment The attachment to include in the message.
|
|
73
|
+
* @param text (Optional) The text of the message.
|
|
74
|
+
* @param speak (Optional) The text to be spoken by the agent.
|
|
75
|
+
* @param inputHint (Optional) The input hint for the message.
|
|
76
|
+
* @returns The created message activity with an attachment.
|
|
77
|
+
*/
|
|
78
|
+
static attachment (
|
|
79
|
+
attachment: Attachment,
|
|
80
|
+
text?: string,
|
|
81
|
+
speak?: string,
|
|
82
|
+
inputHint?: InputHints | string
|
|
83
|
+
): Activity {
|
|
84
|
+
return attachmentActivity(AttachmentLayoutTypes.List, [attachment], text, speak, inputHint)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Creates a message activity with a list of attachments.
|
|
89
|
+
* @param attachments The list of attachments to include in the message.
|
|
90
|
+
* @param text (Optional) The text of the message.
|
|
91
|
+
* @param speak (Optional) The text to be spoken by the agent.
|
|
92
|
+
* @param inputHint (Optional) The input hint for the message.
|
|
93
|
+
* @returns The created message activity with a list of attachments.
|
|
94
|
+
*/
|
|
95
|
+
static list (
|
|
96
|
+
attachments: Attachment[],
|
|
97
|
+
text?: string,
|
|
98
|
+
speak?: string,
|
|
99
|
+
inputHint?: InputHints | string
|
|
100
|
+
): Activity {
|
|
101
|
+
return attachmentActivity(AttachmentLayoutTypes.List, attachments, text, speak, inputHint)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Creates a message activity with a carousel of attachments.
|
|
106
|
+
* @param attachments The list of attachments to include in the carousel.
|
|
107
|
+
* @param text (Optional) The text of the message.
|
|
108
|
+
* @param speak (Optional) The text to be spoken by the agent.
|
|
109
|
+
* @param inputHint (Optional) The input hint for the message.
|
|
110
|
+
* @returns The created message activity with a carousel of attachments.
|
|
111
|
+
*/
|
|
112
|
+
static carousel (
|
|
113
|
+
attachments: Attachment[],
|
|
114
|
+
text?: string,
|
|
115
|
+
speak?: string,
|
|
116
|
+
inputHint?: InputHints | string
|
|
117
|
+
): Activity {
|
|
118
|
+
return attachmentActivity(AttachmentLayoutTypes.Carousel, attachments, text, speak, inputHint)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Creates a message activity with content from a URL.
|
|
123
|
+
* @param url The URL of the content.
|
|
124
|
+
* @param contentType The content type of the attachment.
|
|
125
|
+
* @param name (Optional) The name of the attachment.
|
|
126
|
+
* @param text (Optional) The text of the message.
|
|
127
|
+
* @param speak (Optional) The text to be spoken by the agent.
|
|
128
|
+
* @param inputHint (Optional) The input hint for the message.
|
|
129
|
+
* @returns The created message activity with content from a URL.
|
|
130
|
+
*/
|
|
131
|
+
static contentUrl (
|
|
132
|
+
url: string,
|
|
133
|
+
contentType: string,
|
|
134
|
+
name?: string,
|
|
135
|
+
text?: string,
|
|
136
|
+
speak?: string,
|
|
137
|
+
inputHint?: InputHints | string
|
|
138
|
+
): Activity {
|
|
139
|
+
const a: Attachment = { contentType, contentUrl: url }
|
|
140
|
+
if (name) {
|
|
141
|
+
a.name = name
|
|
142
|
+
}
|
|
143
|
+
return attachmentActivity(AttachmentLayoutTypes.List, [a], text, speak, inputHint)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Creates a message activity with attachments.
|
|
149
|
+
* @param attachmentLayout The layout for the attachments.
|
|
150
|
+
* @param attachments The list of attachments to include in the message.
|
|
151
|
+
* @param text (Optional) The text of the message.
|
|
152
|
+
* @param speak (Optional) The text to be spoken by the agent.
|
|
153
|
+
* @param inputHint (Optional) The input hint for the message.
|
|
154
|
+
* @returns The created message activity with attachments.
|
|
155
|
+
*/
|
|
156
|
+
function attachmentActivity (
|
|
157
|
+
attachmentLayout: AttachmentLayoutTypes,
|
|
158
|
+
attachments: Attachment[],
|
|
159
|
+
text?: string,
|
|
160
|
+
speak?: string,
|
|
161
|
+
inputHint?: InputHints | string
|
|
162
|
+
): Activity {
|
|
163
|
+
const msgObj = {
|
|
164
|
+
type: ActivityTypes.Message,
|
|
165
|
+
attachmentLayout,
|
|
166
|
+
attachments,
|
|
167
|
+
inputHint: inputHint || InputHints.AcceptingInput
|
|
168
|
+
}
|
|
169
|
+
const msg = Activity.fromObject(msgObj)
|
|
170
|
+
if (text) {
|
|
171
|
+
msg.text = text
|
|
172
|
+
}
|
|
173
|
+
if (speak) {
|
|
174
|
+
msg.speak = speak
|
|
175
|
+
}
|
|
176
|
+
return msg
|
|
177
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */
|
|
2
|
+
import { TurnContext } from './turnContext'
|
|
3
|
+
import { debug } from './logger'
|
|
4
|
+
|
|
5
|
+
const logger = debug('agents:middleware')
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Interface for middleware.
|
|
9
|
+
*/
|
|
10
|
+
export interface Middleware {
|
|
11
|
+
onTurn: (context: TurnContext, next: () => Promise<void>) => Promise<void>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Type for middleware handler.
|
|
16
|
+
*/
|
|
17
|
+
export type MiddlewareHandler = (context: TurnContext, next: () => Promise<void>) => Promise<void>
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Represents a set of middleware.
|
|
21
|
+
*/
|
|
22
|
+
export class MiddlewareSet implements Middleware {
|
|
23
|
+
private readonly middleware: MiddlewareHandler[] = []
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Initializes a new instance of the MiddlewareSet class.
|
|
27
|
+
* @param middlewares The middleware handlers or middleware objects to use.
|
|
28
|
+
*/
|
|
29
|
+
constructor (...middlewares: Array<MiddlewareHandler | Middleware>) {
|
|
30
|
+
this.use(...middlewares)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Handles the turn of the middleware.
|
|
35
|
+
* @param context The turn context.
|
|
36
|
+
* @param next The next function to call.
|
|
37
|
+
* @returns A promise representing the asynchronous operation.
|
|
38
|
+
*/
|
|
39
|
+
async onTurn (context: TurnContext, next: () => Promise<void>): Promise<void> {
|
|
40
|
+
return await this.run(context, next)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Adds middleware to the set.
|
|
45
|
+
* @param middlewares The middleware handlers or middleware objects to add.
|
|
46
|
+
* @returns The current MiddlewareSet instance.
|
|
47
|
+
*/
|
|
48
|
+
use (...middlewares: Array<MiddlewareHandler | Middleware>): this {
|
|
49
|
+
middlewares.forEach((plugin) => {
|
|
50
|
+
if (typeof plugin === 'function' || (typeof plugin === 'object' && plugin.onTurn)) {
|
|
51
|
+
this.middleware.push(
|
|
52
|
+
typeof plugin === 'function' ? plugin : async (context, next) => await plugin.onTurn(context, next)
|
|
53
|
+
)
|
|
54
|
+
} else {
|
|
55
|
+
throw new Error('MiddlewareSet.use(): invalid plugin type being added.')
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
return this
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Runs the middleware chain.
|
|
63
|
+
* @param context The turn context.
|
|
64
|
+
* @param next The next function to call.
|
|
65
|
+
* @returns A promise representing the asynchronous operation.
|
|
66
|
+
*/
|
|
67
|
+
async run (context: TurnContext, next: () => Promise<void>): Promise<void> {
|
|
68
|
+
return await this.middleware.reduceRight<() => Promise<void>>(
|
|
69
|
+
(nextHandler, currentHandler) => async () => await currentHandler(context, nextHandler),
|
|
70
|
+
next
|
|
71
|
+
)().catch(err => {
|
|
72
|
+
logger.error('Error in middleware chain:', err)
|
|
73
|
+
throw err
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
import { CardAction } from '@microsoft/agents-activity'
|
|
5
|
+
import { TokenExchangeResource } from './tokenExchangeResource'
|
|
6
|
+
import { TokenPostResource } from './tokenPostResource'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Represents an OAuth card.
|
|
10
|
+
*/
|
|
11
|
+
export interface OAuthCard {
|
|
12
|
+
/**
|
|
13
|
+
* The buttons associated with the OAuth card.
|
|
14
|
+
*/
|
|
15
|
+
buttons: CardAction[]
|
|
16
|
+
/**
|
|
17
|
+
* The connection name for the OAuth card.
|
|
18
|
+
*/
|
|
19
|
+
connectionName: string
|
|
20
|
+
/**
|
|
21
|
+
* The text content of the OAuth card.
|
|
22
|
+
*/
|
|
23
|
+
text: string
|
|
24
|
+
/**
|
|
25
|
+
* The token exchange resource for the OAuth card.
|
|
26
|
+
*/
|
|
27
|
+
tokenExchangeResource: TokenExchangeResource
|
|
28
|
+
/**
|
|
29
|
+
* The token post resource for the OAuth card.
|
|
30
|
+
*/
|
|
31
|
+
tokenPostResource: TokenPostResource
|
|
32
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
import { TokenExchangeResource } from './tokenExchangeResource'
|
|
5
|
+
import { TokenPostResource } from './tokenPostResource'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Represents a resource for signing in.
|
|
9
|
+
*/
|
|
10
|
+
export interface SigningResource {
|
|
11
|
+
/**
|
|
12
|
+
* The link for signing in.
|
|
13
|
+
*/
|
|
14
|
+
singingLink: string,
|
|
15
|
+
/**
|
|
16
|
+
* The resource for token exchange.
|
|
17
|
+
*/
|
|
18
|
+
tokenExchangeResource: TokenExchangeResource,
|
|
19
|
+
/**
|
|
20
|
+
* The resource for token post.
|
|
21
|
+
*/
|
|
22
|
+
tokenPostResource: TokenPostResource
|
|
23
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Represents a request for exchanging tokens.
|
|
6
|
+
*/
|
|
7
|
+
export interface TokenExchangeRequest {
|
|
8
|
+
/**
|
|
9
|
+
* The URI for the token exchange request.
|
|
10
|
+
*/
|
|
11
|
+
uri?: string
|
|
12
|
+
/**
|
|
13
|
+
* The token to be exchanged.
|
|
14
|
+
*/
|
|
15
|
+
token?: string
|
|
16
|
+
/**
|
|
17
|
+
* The ID associated with the token exchange request.
|
|
18
|
+
*/
|
|
19
|
+
id?: string
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Represents a resource for exchanging tokens.
|
|
6
|
+
*/
|
|
7
|
+
export interface TokenExchangeResource {
|
|
8
|
+
/**
|
|
9
|
+
* The ID of the token exchange resource.
|
|
10
|
+
*/
|
|
11
|
+
id?: string
|
|
12
|
+
/**
|
|
13
|
+
* The URI of the token exchange resource.
|
|
14
|
+
*/
|
|
15
|
+
uri?: string
|
|
16
|
+
/**
|
|
17
|
+
* The provider ID for the token exchange resource.
|
|
18
|
+
*/
|
|
19
|
+
providerId?: string
|
|
20
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Represents a resource for posting tokens.
|
|
6
|
+
*/
|
|
7
|
+
export interface TokenPostResource {
|
|
8
|
+
/**
|
|
9
|
+
* The SAS URL for the token post resource.
|
|
10
|
+
*/
|
|
11
|
+
sasUrl?: string
|
|
12
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
import axios, { AxiosInstance } from 'axios'
|
|
5
|
+
import { SigningResource } from './signingResource'
|
|
6
|
+
import { Activity } from '@microsoft/agents-activity'
|
|
7
|
+
import { debug } from '../logger'
|
|
8
|
+
import { TokenExchangeRequest } from './tokenExchangeRequest'
|
|
9
|
+
|
|
10
|
+
const logger = debug('agents:userTokenClient')
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Client for managing user tokens.
|
|
14
|
+
*/
|
|
15
|
+
export class UserTokenClient {
|
|
16
|
+
client: AxiosInstance
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new instance of UserTokenClient.
|
|
20
|
+
* @param token The token to use for authentication.
|
|
21
|
+
*/
|
|
22
|
+
constructor (token: string) {
|
|
23
|
+
const baseURL = 'https://api.botframework.com'
|
|
24
|
+
const axiosInstance = axios.create({
|
|
25
|
+
baseURL,
|
|
26
|
+
headers: {
|
|
27
|
+
Accept: 'application/json'
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
axiosInstance.defaults.headers.common.Authorization = `Bearer ${token}`
|
|
31
|
+
this.client = axiosInstance
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Gets the user token.
|
|
36
|
+
* @param connectionName The connection name.
|
|
37
|
+
* @param channelId The channel ID.
|
|
38
|
+
* @param userId The user ID.
|
|
39
|
+
* @param code The optional code.
|
|
40
|
+
* @returns A promise that resolves to the user token.
|
|
41
|
+
*/
|
|
42
|
+
async getUserToken (connectionName: string, channelId: string, userId: string, code?: string) {
|
|
43
|
+
try {
|
|
44
|
+
const params = { connectionName, channelId, userId, code }
|
|
45
|
+
const response = await this.client.get('/api/usertoken/GetToken', { params })
|
|
46
|
+
return response.data
|
|
47
|
+
} catch (error: any) {
|
|
48
|
+
if (error.response?.status !== 404) {
|
|
49
|
+
logger.error(error)
|
|
50
|
+
}
|
|
51
|
+
return null
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Signs the user out.
|
|
57
|
+
* @param userId The user ID.
|
|
58
|
+
* @param connectionName The connection name.
|
|
59
|
+
* @param channelId The channel ID.
|
|
60
|
+
* @returns A promise that resolves when the sign-out operation is complete.
|
|
61
|
+
*/
|
|
62
|
+
async signOut (userId: string, connectionName: string, channelId: string) {
|
|
63
|
+
try {
|
|
64
|
+
const params = { userId, connectionName, channelId }
|
|
65
|
+
const response = await this.client.delete('/api/usertoken/SignOut', { params })
|
|
66
|
+
return response.data
|
|
67
|
+
} catch (error: any) {
|
|
68
|
+
logger.error(error)
|
|
69
|
+
return null
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Gets the sign-in resource.
|
|
75
|
+
* @param appId The application ID.
|
|
76
|
+
* @param cnxName The connection name.
|
|
77
|
+
* @param activity The activity.
|
|
78
|
+
* @returns A promise that resolves to the signing resource.
|
|
79
|
+
*/
|
|
80
|
+
async getSignInResource (appId: string, cnxName: string, activity: Activity) : Promise<SigningResource> {
|
|
81
|
+
try {
|
|
82
|
+
const tokenExchangeState = {
|
|
83
|
+
ConnectionName: cnxName,
|
|
84
|
+
Conversation: activity.getConversationReference(),
|
|
85
|
+
RelatesTo: activity.RelatesTo,
|
|
86
|
+
MsAppId: appId
|
|
87
|
+
}
|
|
88
|
+
const state = Buffer.from(JSON.stringify(tokenExchangeState)).toString('base64')
|
|
89
|
+
const params = { state }
|
|
90
|
+
const response = await this.client.get('/api/botsignin/GetSignInResource', { params })
|
|
91
|
+
return response.data as SigningResource
|
|
92
|
+
} catch (error: any) {
|
|
93
|
+
logger.error(error)
|
|
94
|
+
throw error
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Exchanges the token.
|
|
100
|
+
* @param userId The user ID.
|
|
101
|
+
* @param connectionName The connection name.
|
|
102
|
+
* @param channelId The channel ID.
|
|
103
|
+
* @param tokenExchangeRequest The token exchange request.
|
|
104
|
+
* @returns A promise that resolves to the exchanged token.
|
|
105
|
+
*/
|
|
106
|
+
async exchangeTokenAsync (userId: string, connectionName: string, channelId: string, tokenExchangeRequest: TokenExchangeRequest) {
|
|
107
|
+
try {
|
|
108
|
+
const params = { userId, connectionName, channelId }
|
|
109
|
+
const response = await this.client.post('/api/usertoken/exchange', tokenExchangeRequest, { params })
|
|
110
|
+
return response.data
|
|
111
|
+
} catch (error: any) {
|
|
112
|
+
logger.error(error)
|
|
113
|
+
return null
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
import { Attachment } from '@microsoft/agents-activity'
|
|
5
|
+
import { UserTokenClient } from './userTokenClient'
|
|
6
|
+
import { CloudAdapter } from '../cloudAdapter'
|
|
7
|
+
import { CardFactory } from '../cards/cardFactory'
|
|
8
|
+
import { AgentStatePropertyAccessor } from '../state/agentStatePropertyAccesor'
|
|
9
|
+
import { UserState } from '../state/userState'
|
|
10
|
+
import { TurnContext } from '../turnContext'
|
|
11
|
+
import { MessageFactory } from '../messageFactory'
|
|
12
|
+
import { debug } from '../logger'
|
|
13
|
+
|
|
14
|
+
const logger = debug('agents:web-chat-oauth-flow')
|
|
15
|
+
|
|
16
|
+
class FlowState {
|
|
17
|
+
public flowStarted: boolean = false
|
|
18
|
+
public userToken: string = ''
|
|
19
|
+
public flowExpires: number = 0
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Manages the OAuth flow for Web Chat.
|
|
24
|
+
*/
|
|
25
|
+
export class WebChatOAuthFlow {
|
|
26
|
+
userTokenClient?: UserTokenClient
|
|
27
|
+
state: FlowState | null
|
|
28
|
+
flowStateAccessor: AgentStatePropertyAccessor<FlowState | null>
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new instance of WebChatOAuthFlow.
|
|
32
|
+
* @param userState The user state.
|
|
33
|
+
*/
|
|
34
|
+
constructor (userState: UserState) {
|
|
35
|
+
this.state = null
|
|
36
|
+
this.flowStateAccessor = userState.createProperty('flowState')
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Gets the OAuth token.
|
|
41
|
+
* @param context The turn context.
|
|
42
|
+
* @returns A promise that resolves to the user token.
|
|
43
|
+
*/
|
|
44
|
+
public async getOAuthToken (context: TurnContext) : Promise<string> {
|
|
45
|
+
this.state = await this.getUserState(context)
|
|
46
|
+
if (this.state!.userToken !== '') {
|
|
47
|
+
return this.state.userToken
|
|
48
|
+
}
|
|
49
|
+
if (this.state?.flowExpires !== 0 && Date.now() > this.state.flowExpires) {
|
|
50
|
+
logger.warn('Sign-in flow expired')
|
|
51
|
+
this.state.flowStarted = false
|
|
52
|
+
this.state.userToken = ''
|
|
53
|
+
await context.sendActivity(MessageFactory.text('Sign-in session expired. Please try again.'))
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let retVal: string = ''
|
|
57
|
+
const authConfig = context.adapter.authConfig
|
|
58
|
+
if (authConfig.connectionName === undefined) {
|
|
59
|
+
throw new Error('connectionName is not set in the auth config, review your environment variables')
|
|
60
|
+
}
|
|
61
|
+
const adapter = context.adapter as CloudAdapter
|
|
62
|
+
const scope = 'https://api.botframework.com'
|
|
63
|
+
const accessToken = await adapter.authProvider.getAccessToken(authConfig, scope)
|
|
64
|
+
this.userTokenClient = new UserTokenClient(accessToken)
|
|
65
|
+
|
|
66
|
+
if (this.state!.flowStarted === true) {
|
|
67
|
+
const userToken = await this.userTokenClient.getUserToken(authConfig.connectionName!, context.activity.channelId!, context.activity.from?.id!)
|
|
68
|
+
if (userToken !== null) {
|
|
69
|
+
logger.info('Token obtained')
|
|
70
|
+
this.state.userToken = userToken.token
|
|
71
|
+
this.state.flowStarted = false
|
|
72
|
+
} else {
|
|
73
|
+
const code = context.activity.text as string
|
|
74
|
+
const userToken = await this.userTokenClient!.getUserToken(authConfig.connectionName!, context.activity.channelId!, context.activity.from?.id!, code)
|
|
75
|
+
if (userToken !== null) {
|
|
76
|
+
logger.info('Token obtained with code')
|
|
77
|
+
this.state.userToken = userToken.token
|
|
78
|
+
this.state.flowStarted = false
|
|
79
|
+
} else {
|
|
80
|
+
logger.error('Sign in failed')
|
|
81
|
+
await context.sendActivity(MessageFactory.text('Sign in failed'))
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
retVal = this.state.userToken
|
|
85
|
+
} else if (this.state!.flowStarted === false) {
|
|
86
|
+
const signingResource = await this.userTokenClient.getSignInResource(authConfig.clientId!, authConfig.connectionName!, context.activity)
|
|
87
|
+
const oCard: Attachment = CardFactory.oauthCard(authConfig.connectionName!, 'Sign in', '', signingResource)
|
|
88
|
+
await context.sendActivity(MessageFactory.attachment(oCard))
|
|
89
|
+
this.state!.flowStarted = true
|
|
90
|
+
this.state.flowExpires = Date.now() + 30000
|
|
91
|
+
logger.info('OAuth flow started')
|
|
92
|
+
}
|
|
93
|
+
this.flowStateAccessor.set(context, this.state)
|
|
94
|
+
return retVal
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Signs the user out.
|
|
99
|
+
* @param context The turn context.
|
|
100
|
+
* @returns A promise that resolves when the sign-out operation is complete.
|
|
101
|
+
*/
|
|
102
|
+
async signOut (context: TurnContext) {
|
|
103
|
+
await this.userTokenClient!.signOut(context.activity.from?.id!, context.adapter.authConfig.connectionName!, context.activity.channelId!)
|
|
104
|
+
this.state!.flowStarted = false
|
|
105
|
+
this.state!.userToken = ''
|
|
106
|
+
this.state!.flowExpires = 0
|
|
107
|
+
this.flowStateAccessor.set(context, this.state)
|
|
108
|
+
logger.info('User signed out successfully')
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Gets the user state.
|
|
113
|
+
* @param context The turn context.
|
|
114
|
+
* @returns A promise that resolves to the user state.
|
|
115
|
+
*/
|
|
116
|
+
private async getUserState (context: TurnContext) {
|
|
117
|
+
let userProfile: FlowState | null = await this.flowStateAccessor.get(context, null)
|
|
118
|
+
if (userProfile === null) {
|
|
119
|
+
userProfile = new FlowState()
|
|
120
|
+
}
|
|
121
|
+
return userProfile
|
|
122
|
+
}
|
|
123
|
+
}
|