{"version":3,"sources":["src/common.speech/DialogConnectorFactory.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAqB,MAAM,mBAAmB,CAAC;AAEnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAA6B,MAAM,WAAW,CAAC;AAqClF,qBAAa,uBAAwB,SAAQ,qBAAqB;IAEvD,MAAM,uFA8BZ;CACJ","file":"DialogConnectorFactory.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\n\nimport {\n    ProxyInfo,\n    WebsocketConnection,\n} from \"../common.browser/Exports\";\nimport { IConnection, IStringDictionary } from \"../common/Exports\";\nimport { PropertyId } from \"../sdk/Exports\";\nimport { ConnectionFactoryBase } from \"./ConnectionFactoryBase\";\nimport { AuthInfo, RecognizerConfig, WebsocketMessageFormatter } from \"./Exports\";\nimport { QueryParameterNames } from \"./QueryParameterNames\";\n\nconst baseUrl: string = \"convai.speech.microsoft.com\";\n\ninterface IBackendValues {\n    authHeader: string;\n    resourcePath: string;\n    version: string;\n}\n\nconst botFramework: IBackendValues = {\n    authHeader: \"X-DLS-Secret\",\n    resourcePath: \"\",\n    version: \"v3\"\n};\n\nconst speechCommands: IBackendValues = {\n    authHeader: \"X-CommandsAppId\",\n    resourcePath: \"commands\",\n    version: \"v1\"\n};\n\nconst pathSuffix: string = \"api\";\n\nfunction getDialogSpecificValues(dialogType: string): IBackendValues {\n    switch (dialogType) {\n        case \"speech_commands\": {\n            return speechCommands;\n        }\n        case \"bot_framework\": {\n            return botFramework;\n        }\n    }\n    throw new Error(`Invalid dialog type '${dialogType}'`);\n}\n\nexport class DialogConnectionFactory extends ConnectionFactoryBase {\n\n    public create = (\n        config: RecognizerConfig,\n        authInfo: AuthInfo,\n        connectionId?: string): 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\n        const language: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_RecoLanguage, \"en-US\");\n\n        const queryParams: IStringDictionary<string> = {};\n        queryParams[QueryParameterNames.LanguageParamName] = language;\n\n        const {resourcePath, version, authHeader} = getDialogSpecificValues(dialogType);\n\n        const headers: IStringDictionary<string> = {};\n        headers[authInfo.headerName] = authInfo.token;\n        headers[QueryParameterNames.ConnectionIdHeader] = connectionId;\n\n        let endpoint: string;\n        // ApplicationId is only required for CustomCommands\n        if (applicationId === \"\") {\n            endpoint = `wss://${region}.${baseUrl}/${pathSuffix}/${version}`;\n        } else {\n            endpoint = `wss://${region}.${baseUrl}/${resourcePath}/${pathSuffix}/${version}`;\n            headers[authHeader] = applicationId;\n        }\n\n        return new WebsocketConnection(endpoint, queryParams, headers, new WebsocketMessageFormatter(), ProxyInfo.fromRecognizerConfig(config), connectionId);\n    }\n}\n"]}