{"version":3,"sources":["src/common.speech/DialogConnectorFactory.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,WAAW,EAAqB,MAAM,sBAAsB,CAAC;AAEtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAA6B,MAAM,cAAc,CAAC;AAIrF,qBAAa,uBAAwB,SAAQ,qBAAqB;IAE9D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAiB;IAC/C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAA2B;IAEnD,MAAM,CACT,MAAM,EAAE,gBAAgB,EACxB,QAAQ,EAAE,QAAQ,EAClB,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;CAqDnD","file":"DialogConnectorFactory.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\n\n/* eslint-disable max-classes-per-file */\nimport {\n    ProxyInfo,\n    WebsocketConnection,\n} from \"../common.browser/Exports.js\";\nimport { OutputFormatPropertyName } from \"../common.speech/Exports.js\";\nimport { IConnection, IStringDictionary } from \"../common/Exports.js\";\nimport { DialogServiceConfig, OutputFormat, PropertyId } from \"../sdk/Exports.js\";\nimport { ConnectionFactoryBase } from \"./ConnectionFactoryBase.js\";\nimport { AuthInfo, RecognizerConfig, WebsocketMessageFormatter } from \"./Exports.js\";\nimport { HeaderNames } from \"./HeaderNames.js\";\nimport { QueryParameterNames } from \"./QueryParameterNames.js\";\n\nexport class DialogConnectionFactory extends ConnectionFactoryBase {\n\n    private static readonly ApiKey: string = \"api\";\n    private static readonly BaseUrl: string = \"convai.speech\";\n\n    public create(\n        config: RecognizerConfig,\n        authInfo: AuthInfo,\n        connectionId?: string): Promise<IConnection> {\n\n        const applicationId: string = config.parameters.getProperty(PropertyId.Conversation_ApplicationId, \"\");\n        const dialogType: string = config.parameters.getProperty(PropertyId.Conversation_DialogType);\n        const region: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Region);\n        const language: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_RecoLanguage, \"en-US\");\n        const requestTurnStatus: string = config.parameters.getProperty(PropertyId.Conversation_Request_Bot_Status_Messages, \"true\");\n\n        const queryParams: IStringDictionary<string> = {};\n        queryParams[HeaderNames.ConnectionId] = connectionId;\n        queryParams[QueryParameterNames.Format] = config.parameters.getProperty(OutputFormatPropertyName, OutputFormat[OutputFormat.Simple]).toLowerCase();\n        queryParams[QueryParameterNames.Language] = language;\n        queryParams[QueryParameterNames.RequestBotStatusMessages] = requestTurnStatus;\n        if (applicationId) {\n            queryParams[QueryParameterNames.BotId] = applicationId;\n            if (dialogType === DialogServiceConfig.DialogTypes.CustomCommands) {\n                queryParams[HeaderNames.CustomCommandsAppId] = applicationId;\n            }\n        }\n\n        const resourceInfix: string =\n            dialogType === DialogServiceConfig.DialogTypes.CustomCommands ? \"commands/\"\n            : \"\";\n        const version: string =\n            dialogType === DialogServiceConfig.DialogTypes.CustomCommands ? \"v1\"\n            : dialogType === DialogServiceConfig.DialogTypes.BotFramework ? \"v3\"\n            : \"v0\";\n\n        const headers: IStringDictionary<string> = {};\n\n        if (authInfo.token != null && authInfo.token !== \"\") {\n            headers[authInfo.headerName] = authInfo.token;\n        }\n\n        // The URL used for connection is chosen in a priority order of specification:\n        //  1. If a custom endpoint is provided, that URL is used verbatim.\n        //  2. If a custom host is provided (e.g. \"wss://my.custom.endpoint.com:1123\"), a URL is constructed from it.\n        //  3. If no custom connection details are provided, a URL is constructed from default values.\n        let endpoint: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Endpoint, \"\");\n        if (!endpoint) {\n            const hostSuffix: string = ConnectionFactoryBase.getHostSuffix(region);\n            const host: string = config.parameters.getProperty(\n                PropertyId.SpeechServiceConnection_Host,\n                `wss://${region}.${DialogConnectionFactory.BaseUrl}${hostSuffix}`);\n            const standardizedHost: string = host.endsWith(\"/\") ? host : host + \"/\";\n            endpoint = `${standardizedHost}${resourceInfix}${DialogConnectionFactory.ApiKey}/${version}`;\n        }\n\n        this.setCommonUrlParams(config, queryParams, endpoint);\n\n        const enableCompression: boolean = config.parameters.getProperty(\"SPEECH-EnableWebsocketCompression\", \"false\") === \"true\";\n        return Promise.resolve(new WebsocketConnection(endpoint, queryParams, headers, new WebsocketMessageFormatter(), ProxyInfo.fromRecognizerConfig(config), enableCompression, connectionId));\n    }\n}\n"]}